diff options
| author | Alex Maras <dev@alexmaras.com> | 2025-05-03 07:28:18 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-03 01:28:18 +0200 |
| commit | 8fd0b82c387dfd10f427c8267526223ba4dc1fce (patch) | |
| tree | 1103710a0bef14c1bf9c8d04552b6e372c833e9a /src | |
| parent | 7579adc3a3f23958afc4f11c9c52302f9962f879 (diff) | |
| download | invidious-8fd0b82c387dfd10f427c8267526223ba4dc1fce.tar.gz invidious-8fd0b82c387dfd10f427c8267526223ba4dc1fce.tar.bz2 invidious-8fd0b82c387dfd10f427c8267526223ba4dc1fce.zip | |
feat: route to invidious companion on downloads (#5224)
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/frontend/watch_page.cr | 8 | ||||
| -rw-r--r-- | src/invidious/routes/watch.cr | 11 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/invidious/frontend/watch_page.cr b/src/invidious/frontend/watch_page.cr index 2e2f6ad0..15d925e3 100644 --- a/src/invidious/frontend/watch_page.cr +++ b/src/invidious/frontend/watch_page.cr @@ -23,10 +23,16 @@ module Invidious::Frontend::WatchPage return "<p id=\"download\">#{translate(locale, "Download is disabled")}</p>" end + url = "/download" + if (CONFIG.invidious_companion.present?) + invidious_companion = CONFIG.invidious_companion.sample + url = "#{invidious_companion.public_url}/download?check=#{invidious_companion_encrypt(video.id)}" + end + return String.build(4000) do |str| str << "<form" str << " class=\"pure-form pure-form-stacked\"" - str << " action='/download'" + str << " action='#{url}'" str << " method='post'" str << " rel='noopener'" str << " target='_blank'>" diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index ab588ad6..e777b3f1 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -293,6 +293,9 @@ module Invidious::Routes::Watch if CONFIG.disabled?("downloads") return error_template(403, "Administrator has disabled this endpoint.") end + if CONFIG.invidious_companion.present? + return error_template(403, "Downloads should be routed through Companion when present") + end title = env.params.body["title"]? || "" video_id = env.params.body["id"]? || "" @@ -328,13 +331,7 @@ module Invidious::Routes::Watch env.params.query["title"] = filename env.params.query["local"] = "true" - if (CONFIG.invidious_companion.present?) - video = get_video(video_id) - invidious_companion = CONFIG.invidious_companion.sample - return env.redirect "#{invidious_companion.public_url}/latest_version?#{env.params.query}" - else - return Invidious::Routes::VideoPlayback.latest_version(env) - end + return Invidious::Routes::VideoPlayback.latest_version(env) else return error_template(400, "Invalid label or itag") end |
