From f9312f3b4bf53c514779e1e9b7e1a98fab11a66f Mon Sep 17 00:00:00 2001 From: magmaus3 Date: Fri, 9 Jun 2023 15:51:25 +0200 Subject: [PATCH] Add level embed --- iwm_browser/main.py | 25 ++++++++++++++++++++ iwm_browser/templates/levelCard_embed.html | 27 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 iwm_browser/templates/levelCard_embed.html diff --git a/iwm_browser/main.py b/iwm_browser/main.py index 40659f9..e27485d 100644 --- a/iwm_browser/main.py +++ b/iwm_browser/main.py @@ -279,6 +279,31 @@ async def showUser(user_id: int): THUMB_URL=THUMB_URL, ) +@app.get("/embed/level/{level_id}", response_class=HTMLResponse) +async def embed_level(level_id: int): + template = template_env.get_template("levelCard_embed.html") + + try: + rq = httpx.get(BASE_URL + "/api/v1/map/" + str(level_id), timeout=10, proxies=PROXIES) + if rq.status_code == 503: + return error_template.render(reason="Server is unavailable right now") + searchResults = rq.json() + print(rq.url) + except httpx.ReadTimeout: + return error_template.render(reason="Server timed out") + except json.decoder.JSONDecodeError: + return error_template.render( + reason="Failed to parse server response.", details=rq.text + ) + except Exception as exc: + print(exc) + return error_template.render(reason="Uncaught exception", details=exc) + + return template.render( + map=searchResults, + THUMB_URL=THUMB_URL, + ) + def start(): """Launched with `poetry run start` at root level""" diff --git a/iwm_browser/templates/levelCard_embed.html b/iwm_browser/templates/levelCard_embed.html new file mode 100644 index 0000000..99ed4f3 --- /dev/null +++ b/iwm_browser/templates/levelCard_embed.html @@ -0,0 +1,27 @@ + + + + IWM Browser + + + + + + + + + {% include "levelCard.html" %} + +