From 1c076049cf38d77cfeb028e07665899a4b618648 Mon Sep 17 00:00:00 2001 From: Kevin Wallace Date: Fri, 4 Nov 2022 00:34:05 -0700 Subject: [PATCH] Fix URL generation when not at domain root --- app/config.py | 2 +- app/media.py | 2 +- app/templates.py | 6 +++--- app/templates/admin_new.html | 2 +- app/templates/header.html | 2 +- app/templates/layout.html | 8 ++++---- app/templates/utils.html | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/config.py b/app/config.py index cc20ed5..241a0d1 100644 --- a/app/config.py +++ b/app/config.py @@ -179,7 +179,7 @@ if CONFIG.emoji: EMOJIS = CONFIG.emoji # Emoji template for the FE -EMOJI_TPL = '{raw}' +EMOJI_TPL = '{raw}' _load_emojis(ROOT_DIR, BASE_URL) diff --git a/app/media.py b/app/media.py index 04339b1..6c1f51c 100644 --- a/app/media.py +++ b/app/media.py @@ -9,7 +9,7 @@ def proxied_media_url(url: str) -> str: if url.startswith(BASE_URL): return url - return "/proxy/media/" + base64.urlsafe_b64encode(url.encode()).decode() + return BASE_URL + "/proxy/media/" + base64.urlsafe_b64encode(url.encode()).decode() def resized_media_url(url: str, size: int) -> str: diff --git a/app/templates.py b/app/templates.py index d75e506..bdb6dc5 100644 --- a/app/templates.py +++ b/app/templates.py @@ -59,13 +59,13 @@ def _filter_domain(text: str) -> str: def _media_proxy_url(url: str | None) -> str: if not url: - return "/static/nopic.png" + return BASE_URL + "/static/nopic.png" if url.startswith(BASE_URL): return url encoded_url = base64.urlsafe_b64encode(url.encode()).decode() - return f"/proxy/media/{encoded_url}" + return BASE_URL + f"/proxy/media/{encoded_url}" def is_current_user_admin(request: Request) -> bool: @@ -388,7 +388,7 @@ def _html2text(content: str) -> str: def _replace_emoji(u: str, _) -> str: filename = "-".join(hex(ord(c))[2:] for c in u) - return config.EMOJI_TPL.format(filename=filename, raw=u) + return config.EMOJI_TPL.format(base_url=BASE_URL, filename=filename, raw=u) def _emojify(text: str, is_local: bool) -> str: diff --git a/app/templates/admin_new.html b/app/templates/admin_new.html index 57c3052..ac3b3db 100644 --- a/app/templates/admin_new.html +++ b/app/templates/admin_new.html @@ -90,5 +90,5 @@

- + {% endblock %} diff --git a/app/templates/header.html b/app/templates/header.html index 99151a1..7b48452 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -25,7 +25,7 @@ {%- macro header_link(url, text) -%} -{% set url_for = request.app.router.url_path_for(url) %} +{% set url_for = BASE_URL + request.app.router.url_path_for(url) %} {{ text }} {% endmacro %} diff --git a/app/templates/layout.html b/app/templates/layout.html index 3c30d2a..d592cc4 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -4,11 +4,11 @@ - + - + {% block head %}{% endblock %} @@ -18,7 +18,7 @@ {% if is_admin %}
{% macro admin_link(url, text) %} -{% set url_for = request.app.router.url_path_for(url) %} +{% set url_for = BASE_URL + request.app.router.url_path_for(url) %} {{ text }} {% endmacro %}
@@ -53,7 +53,7 @@
{% if is_admin %} - + {% endif %} diff --git a/app/templates/utils.html b/app/templates/utils.html index 57aec8b..f2f1920 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -124,14 +124,14 @@ {% endmacro %} {% macro admin_reply_button(ap_object_id) %} -
+
{% endmacro %} {% macro admin_dm_button(actor_handle) %} -
+ @@ -139,7 +139,7 @@ {% endmacro %} {% macro admin_mention_button(actor_handle) %} - +