From ab016407be4d98c45f8cc70319efa056b85a4bd9 Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 11 Nov 2024 19:41:56 +0200 Subject: [PATCH] fix request referrer breaking --- files/assets/js/chat.js | 4 ++-- files/routes/chats.py | 5 +++-- files/templates/header.html | 2 +- files/templates/util/macros.html | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/files/assets/js/chat.js b/files/assets/js/chat.js index b1fd353a2..f85377d3c 100644 --- a/files/assets/js/chat.js +++ b/files/assets/js/chat.js @@ -108,7 +108,7 @@ socket.on('speak', function(json) { document.getElementsByClassName('time')[0].innerHTML = formatHourMinute(new Date(json.created_utc*1000)) - document.getElementsByClassName('link')[0].href = `/chat/${chat_id}/${json.id}#${json.id}` + document.getElementsByClassName('link')[0].href = `/chat/${chat_id}?m=${json.id}#${json.id}` document.getElementsByClassName('link')[0].innerHTML = `#${json.id}` } @@ -234,7 +234,7 @@ ta.addEventListener("keydown", function(e) { socket.on('online', function(data) { const online_li = data[0] - if (!location.pathname.startsWith('/chat/1')) { + if (chat_id != 1) { for (const marker of document.getElementsByClassName('online-marker')) { marker.classList.add('d-none') } diff --git a/files/routes/chats.py b/files/routes/chats.py index b5322be96..430bb73ad 100644 --- a/files/routes/chats.py +++ b/files/routes/chats.py @@ -63,11 +63,10 @@ def chat_user(v, username): @app.get("/chat/") -@app.get("/chat//") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required -def chat(v, chat_id, message_id=None): +def chat(v, chat_id): chat = g.db.get(Chat, chat_id) if not chat: stop(404, "Chat not found!") @@ -90,7 +89,9 @@ def chat(v, chat_id, message_id=None): if v.admin_level < PERMS['USER_SHADOWBAN']: displayed_messages = displayed_messages.join(ChatMessage.user).filter(or_(User.id == v.id, User.shadowbanned == None)) + message_id = request.values.get('m') if message_id: + message_id = int(message_id) start = message_id - 125 finish = message_id + 125 displayed_messages = displayed_messages.filter(ChatMessage.id > start, ChatMessage.id < finish) diff --git a/files/templates/header.html b/files/templates/header.html index ca8b86645..5c02f3153 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -508,7 +508,7 @@ {% endif %}
  • - {% if request.path.startswith('/chat/1') %} + {% if request.path == '/chat/1' %} {% if SITE_NAME == 'WPD' %}
    Chat Rules
      diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 360a804f2..821fced3d 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -303,7 +303,7 @@ {%- endif -%} - + {%- if m -%} #{{m.id}} {% endif %}