From 7ca2bbd7685f2695f168fb525b14337457a7b4dc Mon Sep 17 00:00:00 2001 From: NorkzYT Date: Mon, 23 Mar 2026 01:59:38 +0000 Subject: [PATCH] fix(before_all): halt response after rendering disabled page error The return from before_all did not stop the route handler from executing. The trending/popular/hashtag routes still ran and overwrote the 403 response. Now set a halted flag and use Kemal halt in the before_all block to prevent route handler execution. Error page now renders with the full Invidious theme (dark mode, navbar, CSS) matching the rest of the UI. --- src/invidious.cr | 6 ++++ src/invidious/routes/before_all.cr | 47 +++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index ac15ec1f..9ce002dd 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -200,6 +200,12 @@ end before_all do |env| Invidious::Routes::BeforeAll.handle(env) + + # If before_all flagged a halt (e.g. disabled page), stop the route handler. + # Use halt with the already-set status code to prevent the route handler from running. + if env.get?("halted") + halt env, status_code: env.response.status_code + end end Invidious::Routing.register_all diff --git a/src/invidious/routes/before_all.cr b/src/invidious/routes/before_all.cr index 4cd2f470..3ed881cf 100644 --- a/src/invidious/routes/before_all.cr +++ b/src/invidious/routes/before_all.cr @@ -164,13 +164,52 @@ module Invidious::Routes::BeforeAll end if page_key && !CONFIG.page_enabled?(page_key) + env.response.status_code = 403 + env.set "halted", true + if path.starts_with?("/api/") - error_message = {error: "Administrator has disabled this endpoint."}.to_json - haltf env, 403, error_message + env.response.content_type = "application/json" + env.response.print({error: "Administrator has disabled this endpoint."}.to_json) else - message = "#{page_key}_page_disabled" - return error_template(403, message) + preferences = env.get("preferences").as(Preferences) + locale = preferences.locale + dark_mode = preferences.dark_mode + theme_class = dark_mode.blank? ? "no" : dark_mode + error_message = translate(locale, "#{page_key}_page_disabled") + + env.response.content_type = "text/html" + env.response.print <<-HTML + + + + + + Error - Invidious + + + + + + +
+
+ +
+

#{error_message}

+

← #{translate(locale, "Back")}

+
+
+
+ + + HTML end + + return end end end