mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-14 16:48:29 +00:00
Change status_code + return blocks to use haltf
This commit is contained in:
parent
a9fa46b60e
commit
b37c8b0153
@ -213,14 +213,12 @@ module Invidious::Routes::Feeds
|
|||||||
token = env.params.query["token"]?
|
token = env.params.query["token"]?
|
||||||
|
|
||||||
if !token
|
if !token
|
||||||
env.response.status_code = 403
|
haltf env, status_code: 403
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
user = PG_DB.query_one?("SELECT * FROM users WHERE token = $1", token.strip, as: User)
|
user = PG_DB.query_one?("SELECT * FROM users WHERE token = $1", token.strip, as: User)
|
||||||
if !user
|
if !user
|
||||||
env.response.status_code = 403
|
haltf env, status_code: 403
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
max_results = env.params.query["max_results"]?.try &.to_i?.try &.clamp(0, MAX_ITEMS_PER_PAGE)
|
max_results = env.params.query["max_results"]?.try &.to_i?.try &.clamp(0, MAX_ITEMS_PER_PAGE)
|
||||||
@ -284,8 +282,7 @@ module Invidious::Routes::Feeds
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
env.response.status_code = 404
|
haltf env, status_code: 404
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -333,8 +330,7 @@ module Invidious::Routes::Feeds
|
|||||||
challenge = env.params.query["hub.challenge"]?
|
challenge = env.params.query["hub.challenge"]?
|
||||||
|
|
||||||
if !mode || !topic || !challenge
|
if !mode || !topic || !challenge
|
||||||
env.response.status_code = 400
|
haltf env, status_code: 400
|
||||||
return
|
|
||||||
else
|
else
|
||||||
mode = mode.not_nil!
|
mode = mode.not_nil!
|
||||||
topic = topic.not_nil!
|
topic = topic.not_nil!
|
||||||
@ -349,20 +345,17 @@ module Invidious::Routes::Feeds
|
|||||||
time, signature = verify_token.split(":")
|
time, signature = verify_token.split(":")
|
||||||
data = "#{time}"
|
data = "#{time}"
|
||||||
else
|
else
|
||||||
env.response.status_code = 400
|
haltf env, status_code: 400
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# The hub will sometimes check if we're still subscribed after delivery errors,
|
# The hub will sometimes check if we're still subscribed after delivery errors,
|
||||||
# so we reply with a 200 as long as the request hasn't expired
|
# so we reply with a 200 as long as the request hasn't expired
|
||||||
if Time.utc.to_unix - time.to_i > 432000
|
if Time.utc.to_unix - time.to_i > 432000
|
||||||
env.response.status_code = 400
|
haltf env, status_code: 400
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, data) != signature
|
if OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, data) != signature
|
||||||
env.response.status_code = 400
|
haltf env, status_code: 400
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ucid = HTTP::Params.parse(URI.parse(topic).query.not_nil!)["channel_id"]?
|
if ucid = HTTP::Params.parse(URI.parse(topic).query.not_nil!)["channel_id"]?
|
||||||
@ -370,8 +363,7 @@ module Invidious::Routes::Feeds
|
|||||||
elsif plid = HTTP::Params.parse(URI.parse(topic).query.not_nil!)["playlist_id"]?
|
elsif plid = HTTP::Params.parse(URI.parse(topic).query.not_nil!)["playlist_id"]?
|
||||||
PG_DB.exec("UPDATE playlists SET subscribed = $1 WHERE id = $2", Time.utc, ucid)
|
PG_DB.exec("UPDATE playlists SET subscribed = $1 WHERE id = $2", Time.utc, ucid)
|
||||||
else
|
else
|
||||||
env.response.status_code = 400
|
haltf env, status_code: 400
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
env.response.status_code = 200
|
env.response.status_code = 200
|
||||||
@ -387,8 +379,7 @@ module Invidious::Routes::Feeds
|
|||||||
|
|
||||||
if signature != OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, body)
|
if signature != OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, body)
|
||||||
LOGGER.error("/feed/webhook/#{token} : Invalid signature")
|
LOGGER.error("/feed/webhook/#{token} : Invalid signature")
|
||||||
env.response.status_code = 200
|
haltf env, status_code: 200
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
spawn do
|
spawn do
|
||||||
@ -433,6 +424,5 @@ module Invidious::Routes::Feeds
|
|||||||
end
|
end
|
||||||
|
|
||||||
env.response.status_code = 200
|
env.response.status_code = 200
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user