forked from Fijxu/invidious
Feat: backend supports with cookies
This commit is contained in:
parent
8f46bd5751
commit
33ffafb9e3
5 changed files with 46 additions and 0 deletions
|
@ -167,6 +167,9 @@ class Config
|
||||||
# The max resolution the Instance can offer
|
# The max resolution the Instance can offer
|
||||||
property max_dash_resolution : Int32?
|
property max_dash_resolution : Int32?
|
||||||
|
|
||||||
|
# List of names of the backends
|
||||||
|
property backends : Array(String) = [] of String
|
||||||
|
|
||||||
# Materialious redirects
|
# Materialious redirects
|
||||||
property materialious_domain : String?
|
property materialious_domain : String?
|
||||||
|
|
||||||
|
|
18
src/invidious/routes/switch_backend.cr
Normal file
18
src/invidious/routes/switch_backend.cr
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{% 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
|
|
@ -21,6 +21,7 @@ module Invidious::Routing
|
||||||
get "/privacy", Routes::Misc, :privacy
|
get "/privacy", Routes::Misc, :privacy
|
||||||
get "/licenses", Routes::Misc, :licenses
|
get "/licenses", Routes::Misc, :licenses
|
||||||
get "/redirect", Routes::Misc, :cross_instance_redirect
|
get "/redirect", Routes::Misc, :cross_instance_redirect
|
||||||
|
get "/switchbackend", Routes::BackendSwitcher, :switch
|
||||||
|
|
||||||
self.register_channel_routes
|
self.register_channel_routes
|
||||||
self.register_watch_routes
|
self.register_watch_routes
|
||||||
|
|
|
@ -45,5 +45,18 @@ struct Invidious::User
|
||||||
samesite: HTTP::Cookie::SameSite::Lax
|
samesite: HTTP::Cookie::SameSite::Lax
|
||||||
)
|
)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -104,6 +104,17 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if CONFIG.backends %>
|
||||||
|
<div class="h-box">
|
||||||
|
<b>Switch Backend:</b>
|
||||||
|
<% CONFIG.backends.each do | backend | %>
|
||||||
|
<a href="/switchbackend?backend_id=<%= backend %>">
|
||||||
|
Backend<%= HTML.escape(backend) %>
|
||||||
|
</a> |
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if CONFIG.banner %>
|
<% if CONFIG.banner %>
|
||||||
<div class="h-box">
|
<div class="h-box">
|
||||||
<h3><%= CONFIG.banner %></h3>
|
<h3><%= CONFIG.banner %></h3>
|
||||||
|
|
Loading…
Reference in a new issue