Invidious is an alternative front-end to YouTube
Adjust routes
saltycrys991a04dc2aeb
diff --git a/src/invidious.cr b/src/invidious.crindex 713d193e..a63d6aca 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -311,12 +311,12 @@ before_all do |env|env.set "current_page", URI.encode_www_form(current_page)end-Invidious::Routing.get "/", Invidious::Routes::Home-Invidious::Routing.get "/privacy", Invidious::Routes::Privacy-Invidious::Routing.get "/licenses", Invidious::Routes::Licenses+Invidious::Routing.get "/", Invidious::Routes::Misc, :home+Invidious::Routing.get "/privacy", Invidious::Routes::Misc, :privacy+Invidious::Routing.get "/licenses", Invidious::Routes::Misc, :licensesInvidious::Routing.get "/watch", Invidious::Routes::Watch-Invidious::Routing.get "/embed/", Invidious::Routes::Embed::Index-Invidious::Routing.get "/embed/:id", Invidious::Routes::Embed::Show+Invidious::Routing.get "/embed/", Invidious::Routes::Embed, :redirect+Invidious::Routing.get "/embed/:id", Invidious::Routes::Embed, :showInvidious::Routing.get "/view_all_playlists", Invidious::Routes::Playlists, :indexInvidious::Routing.get "/create_playlist", Invidious::Routes::Playlists, :newInvidious::Routing.post "/create_playlist", Invidious::Routes::Playlists, :create@@ -335,9 +335,9 @@ Invidious::Routing.get "/search", Invidious::Routes::Search, :searchInvidious::Routing.get "/login", Invidious::Routes::Login, :login_pageInvidious::Routing.post "/login", Invidious::Routes::Login, :loginInvidious::Routing.post "/signout", Invidious::Routes::Login, :signout-Invidious::Routing.get "/preferences", Invidious::Routes::UserPreferences, :show-Invidious::Routing.post "/preferences", Invidious::Routes::UserPreferences, :update-Invidious::Routing.get "/toggle_theme", Invidious::Routes::UserPreferences, :toggle_theme+Invidious::Routing.get "/preferences", Invidious::Routes::PreferencesRoute, :show+Invidious::Routing.post "/preferences", Invidious::Routes::PreferencesRoute, :update+Invidious::Routing.get "/toggle_theme", Invidious::Routes::PreferencesRoute, :toggle_theme# Usersdiff --git a/src/invidious/routes/embed/show.cr b/src/invidious/routes/embed.crsimilarity index 87%rename from src/invidious/routes/embed/show.crrename to src/invidious/routes/embed.crindex 8a655556..4fd265c9 100644--- a/src/invidious/routes/embed/show.cr+++ b/src/invidious/routes/embed.cr@@ -1,5 +1,29 @@-class Invidious::Routes::Embed::Show < Invidious::Routes::BaseRoute- def handle(env)+class Invidious::Routes::Embed < Invidious::Routes::BaseRoute+ def redirect(env)+ locale = LOCALES[env.get("preferences").as(Preferences).locale]?++ if plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")+ begin+ playlist = get_playlist(PG_DB, plid, locale: locale)+ offset = env.params.query["index"]?.try &.to_i? || 0+ videos = get_playlist_videos(PG_DB, playlist, offset: offset, locale: locale)+ rescue ex+ return error_template(500, ex)+ end++ url = "/embed/#{videos[0].id}?#{env.params.query}"++ if env.params.query.size > 0+ url += "?#{env.params.query}"+ end+ else+ url = "/"+ end++ env.redirect url+ end++ def show(env)locale = LOCALES[env.get("preferences").as(Preferences).locale]?id = env.params.url["id"]diff --git a/src/invidious/routes/embed/index.cr b/src/invidious/routes/embed/index.crdeleted file mode 100644index 32a4966b..00000000--- a/src/invidious/routes/embed/index.cr+++ /dev/null@@ -1,25 +0,0 @@-class Invidious::Routes::Embed::Index < Invidious::Routes::BaseRoute- def handle(env)- locale = LOCALES[env.get("preferences").as(Preferences).locale]?-- if plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")- begin- playlist = get_playlist(PG_DB, plid, locale: locale)- offset = env.params.query["index"]?.try &.to_i? || 0- videos = get_playlist_videos(PG_DB, playlist, offset: offset, locale: locale)- rescue ex- return error_template(500, ex)- end-- url = "/embed/#{videos[0].id}?#{env.params.query}"-- if env.params.query.size > 0- url += "?#{env.params.query}"- end- else- url = "/"- end-- env.redirect url- end-enddiff --git a/src/invidious/routes/licenses.cr b/src/invidious/routes/licenses.crdeleted file mode 100644index 38fde7bb..00000000--- a/src/invidious/routes/licenses.cr+++ /dev/null@@ -1,6 +0,0 @@-class Invidious::Routes::Licenses < Invidious::Routes::BaseRoute- def handle(env)- locale = LOCALES[env.get("preferences").as(Preferences).locale]?- rendered "licenses"- end-enddiff --git a/src/invidious/routes/home.cr b/src/invidious/routes/misc.crsimilarity index 65%rename from src/invidious/routes/home.crrename to src/invidious/routes/misc.crindex 486a7344..bc009633 100644--- a/src/invidious/routes/home.cr+++ b/src/invidious/routes/misc.cr@@ -1,5 +1,5 @@-class Invidious::Routes::Home < Invidious::Routes::BaseRoute- def handle(env)+class Invidious::Routes::Misc < Invidious::Routes::BaseRoute+ def home(env)preferences = env.get("preferences").as(Preferences)locale = LOCALES[preferences.locale]?user = env.get? "user"@@ -25,4 +25,14 @@ class Invidious::Routes::Home < Invidious::Routes::BaseRoutetemplated "empty"endend++ def privacy(env)+ locale = LOCALES[env.get("preferences").as(Preferences).locale]?+ templated "privacy"+ end++ def licenses(env)+ locale = LOCALES[env.get("preferences").as(Preferences).locale]?+ rendered "licenses"+ endenddiff --git a/src/invidious/routes/user_preferences.cr b/src/invidious/routes/preferences.crsimilarity index 99%rename from src/invidious/routes/user_preferences.crrename to src/invidious/routes/preferences.crindex a689a2a2..4901d22b 100644--- a/src/invidious/routes/user_preferences.cr+++ b/src/invidious/routes/preferences.cr@@ -1,4 +1,4 @@-class Invidious::Routes::UserPreferences < Invidious::Routes::BaseRoute+class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoutedef show(env)locale = LOCALES[env.get("preferences").as(Preferences).locale]?diff --git a/src/invidious/routes/privacy.cr b/src/invidious/routes/privacy.crdeleted file mode 100644index 4565c94c..00000000--- a/src/invidious/routes/privacy.cr+++ /dev/null@@ -1,6 +0,0 @@-class Invidious::Routes::Privacy < Invidious::Routes::BaseRoute- def handle(env)- locale = LOCALES[env.get("preferences").as(Preferences).locale]?- templated "privacy"- end-end