mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-19 19:48:00 -04:00
Update watch.cr
JSON::ParseException
This commit is contained in:
parent
ac0c0609bb
commit
fb7f4ced04
1 changed files with 53 additions and 39 deletions
|
@ -294,15 +294,28 @@ module Invidious::Routes::Watch
|
||||||
return error_template(403, "Administrator has disabled this endpoint.")
|
return error_template(403, "Administrator has disabled this endpoint.")
|
||||||
end
|
end
|
||||||
|
|
||||||
title = env.params.body["title"]? || ""
|
title = env.params.body["title"] || ""
|
||||||
video_id = env.params.body["id"]? || ""
|
video_id = env.params.body["id"] || ""
|
||||||
selection = env.params.body["download_widget"]?
|
selection = env.params.body["download_widget"]
|
||||||
|
|
||||||
if title.empty? || video_id.empty? || selection.nil?
|
if title.empty? || video_id.empty? || selection.nil?
|
||||||
return error_template(400, "Missing form data")
|
return error_template(400, "Missing form data")
|
||||||
end
|
end
|
||||||
|
|
||||||
download_widget = JSON.parse(selection)
|
begin
|
||||||
|
# Check if the JSON data starts with '{' (indicating an object) or '[' (indicating an array).
|
||||||
|
json_data = selection.strip
|
||||||
|
if json_data.start_with?('{', '[')
|
||||||
|
download_widget = JSON.parse(json_data)
|
||||||
|
# Your existing code for processing the JSON data goes here
|
||||||
|
else
|
||||||
|
# Handle the case where the JSON data is not correctly formatted.
|
||||||
|
return error_template(400, "Invalid JSON format")
|
||||||
|
end
|
||||||
|
rescue JSON::ParserError => e
|
||||||
|
# Handle any JSON parsing errors
|
||||||
|
return error_template(400, "Invalid JSON: #{e.message}")
|
||||||
|
end
|
||||||
|
|
||||||
extension = download_widget["ext"].as_s
|
extension = download_widget["ext"].as_s
|
||||||
filename = "#{title}-#{video_id}.#{extension}"
|
filename = "#{title}-#{video_id}.#{extension}"
|
||||||
|
@ -313,7 +326,7 @@ module Invidious::Routes::Watch
|
||||||
env.params.body.delete("download_widget")
|
env.params.body.delete("download_widget")
|
||||||
|
|
||||||
# Pass form parameters as URL parameters for the handlers of both
|
# Pass form parameters as URL parameters for the handlers of both
|
||||||
# /latest_version and /api/v1/captions. This avoids an un-necessary
|
# /latest_version and /api/v1/captions. This avoids an unnecessary
|
||||||
# redirect and duplicated (and hazardous) sanity checks.
|
# redirect and duplicated (and hazardous) sanity checks.
|
||||||
if label = download_widget["label"]?
|
if label = download_widget["label"]?
|
||||||
# URL params specific to /api/v1/captions/:id
|
# URL params specific to /api/v1/captions/:id
|
||||||
|
@ -334,4 +347,5 @@ module Invidious::Routes::Watch
|
||||||
return error_template(400, "Invalid label or itag")
|
return error_template(400, "Invalid label or itag")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue