Skip to content

Commit

Permalink
Merge pull request #465 from dh4340/patch-1
Browse files Browse the repository at this point in the history
Remove css and js from html_routes
  • Loading branch information
sei-dupdyke authored Nov 21, 2024
2 parents df48615 + 27840d8 commit d618439
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions src/ghosts.pandora/app/routes/html_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def return_chm(file_name: str = None) -> StreamingResponse:

return response


@router.get("/", tags=["Information"])
@router.get("/html", tags=["Web"])
@router.post("/html", tags=["Web"])
Expand All @@ -106,9 +107,14 @@ def return_html(file_name: str = None) -> HTMLResponse:
for _ in range(random.randint(1, 20)):
if random.randint(2, 100) > 55:
body = body + f"<h3>{fake.sentence().replace('.','')}</h3>"
body = body + f"<p>{fake.paragraph(nb_sentences=random.randint(1, 100))}</p>"
body = (
body + f"<p>{fake.paragraph(nb_sentences=random.randint(1, 100))}</p>"
)
if random.randint(1, 100) > 85:
body = body + f"<img src='images/{fake.word()}.png?h={random.randint(80, 200)}&w={random.randint(200, 400)}'/>"
body = (
body
+ f"<img src='images/{fake.word()}.png?h={random.randint(80, 200)}&w={random.randint(200, 400)}'/>"
)

header = f'<script type="text/javascript" src="/scripts/{fake.uuid4()}.js"></script><link rel="stylesheet" href="/css/{fake.uuid4()}/{fake.word()}.css" type="text/css" />'
html_content = f"""
Expand All @@ -132,27 +138,3 @@ def return_html(file_name: str = None) -> HTMLResponse:
logger.info("HTML file generated successfully.")

return response

@router.get("/{file_path:path}.css", tags=["Web"])
def return_css(file_name: str = None) -> HTMLResponse:

fonts=["sans-serif","serif","geneva","georgia","Arial","Verdana","Helvetica","Tahoma","Trebuchet MS","Times New Roman","Garamond","Courier New"]

content = "* {font-family:" + random.choice(fonts) + "} h1 {font-family:" + random.choice(fonts) + "} body {width:" + str(random.randint(65, 100)) + "%;}"

response = HTMLResponse(content=content, media_type="text/css")

logger.info("css file generated successfully.")

return response

@router.get("/{file_path:path}.js", tags=["Web"])
def return_css(file_name: str = None) -> HTMLResponse:

content = f"console.log('{fake.word()}, /{fake.date()}');"

response = HTMLResponse(content=content, media_type="text/javascript")

logger.info("js file generated successfully.")

return response

0 comments on commit d618439

Please sign in to comment.