From 4da3936b5a3daea0e7638f49ab658fa1a1c0c54d Mon Sep 17 00:00:00 2001 From: Fijxu Date: Thu, 7 Nov 2024 21:06:45 -0300 Subject: [PATCH] Remove old code that is done on the Openresty side --- src/invidious/config.cr | 2 ++ src/invidious/routes/switch_backend.cr | 18 ------------------ src/invidious/routing.cr | 1 - src/invidious/user/cookies.cr | 13 ------------- src/invidious/views/template.ecr | 4 ++-- 5 files changed, 4 insertions(+), 34 deletions(-) delete mode 100644 src/invidious/routes/switch_backend.cr diff --git a/src/invidious/config.cr b/src/invidious/config.cr index b4930590..74a378c6 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -204,6 +204,8 @@ class Config property ignore_user_tokens : Bool = false + property server_id_cookie_name : String = "INVIDIOUS_SERVER_ID" + {% if flag?(:linux) %} property reload_config_automatically : Bool = true {% end %} diff --git a/src/invidious/routes/switch_backend.cr b/src/invidious/routes/switch_backend.cr deleted file mode 100644 index 993f3fec..00000000 --- a/src/invidious/routes/switch_backend.cr +++ /dev/null @@ -1,18 +0,0 @@ -{% skip_file if flag?(:api_only) %} - -module Invidious::Routes::BackendSwitcher - def self.switch(env) - referer = get_referer(env) - backend_id = env.params.query["backend_id"] - - # Checks if there is any alternative domain, like a second domain name, - # TOR or I2P address - if alt = CONFIG.alternative_domains.index(env.request.headers["Host"]) - env.response.cookies["SERVER_ID"] = Invidious::User::Cookies.server_id(CONFIG.alternative_domains[alt], backend_id) - else - env.response.cookies["SERVER_ID"] = Invidious::User::Cookies.server_id(CONFIG.domain, backend_id) - end - - env.redirect referer - end -end diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr index e56c670b..fa1c5b97 100644 --- a/src/invidious/routing.cr +++ b/src/invidious/routing.cr @@ -21,7 +21,6 @@ module Invidious::Routing get "/privacy", Routes::Misc, :privacy get "/licenses", Routes::Misc, :licenses get "/redirect", Routes::Misc, :cross_instance_redirect - get "/switchbackend", Routes::BackendSwitcher, :switch self.register_channel_routes self.register_watch_routes diff --git a/src/invidious/user/cookies.cr b/src/invidious/user/cookies.cr index 5036f4fb..a9928d0a 100644 --- a/src/invidious/user/cookies.cr +++ b/src/invidious/user/cookies.cr @@ -45,18 +45,5 @@ struct Invidious::User samesite: HTTP::Cookie::SameSite::Lax ) end - - # Server ID (SERVER_ID) cookie used for Sticky Sessions - # Parameter "domain" comes from the global config - def server_id(domain : String?, server_id) : HTTP::Cookie - return HTTP::Cookie.new( - name: "SERVER_ID", - domain: domain, - value: server_id, - secure: false, - http_only: true, - samesite: HTTP::Cookie::SameSite::Lax - ) - end end end diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index 2767be7f..0079ed61 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -1,7 +1,7 @@ <% locale = env.get("preferences").as(Preferences).locale dark_mode = env.get("preferences").as(Preferences).dark_mode - current_backend = env.request.cookies["SERVER_ID"]?.try &.value + current_backend = env.request.cookies[CONFIG.server_id_cookie_name]?.try &.value %> @@ -310,7 +310,7 @@