From 31fa3dfd590b00e5c994103f0b2fb1f1969d9b9d Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 26 Mar 2021 18:36:40 -0700 Subject: [PATCH] Add route to redirect to another instance --- src/invidious.cr | 1 + src/invidious/routes/misc.cr | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/invidious.cr b/src/invidious.cr index 7037ecfe..b1ee1525 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -314,6 +314,7 @@ Invidious::Routing.get "/shorts/:id", Invidious::Routes::Watch, :redirect Invidious::Routing.get "/w/:id", Invidious::Routes::Watch, :redirect Invidious::Routing.get "/v/:id", Invidious::Routes::Watch, :redirect Invidious::Routing.get "/e/:id", Invidious::Routes::Watch, :redirect +Invidious::Routing.get "/redirect", Invidious::Routes::Misc, :cross_instance_redirect Invidious::Routing.get "/embed/", Invidious::Routes::Embed, :redirect Invidious::Routing.get "/embed/:id", Invidious::Routes::Embed, :show diff --git a/src/invidious/routes/misc.cr b/src/invidious/routes/misc.cr index d32ba892..857d0596 100644 --- a/src/invidious/routes/misc.cr +++ b/src/invidious/routes/misc.cr @@ -35,4 +35,10 @@ class Invidious::Routes::Misc < Invidious::Routes::BaseRoute locale = LOCALES[env.get("preferences").as(Preferences).locale]? rendered "licenses" end + + def cross_instance_redirect(env) + id = env.params.query["id"] + instance_url = fetch_random_instance + env.redirect "https://#{instance_url}/watch?v=#{id}" + end end