mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-22 16:19:53 +05:30
Fix 404 handling for endpoints matching short URLs
This commit is contained in:
parent
27e032d10d
commit
f065a21542
@ -2374,42 +2374,42 @@ get "/feed/subscriptions" do |env|
|
|||||||
next env.redirect referer
|
next env.redirect referer
|
||||||
end
|
end
|
||||||
|
|
||||||
user = user.as(User)
|
user = user.as(User)
|
||||||
sid = sid.as(String)
|
sid = sid.as(String)
|
||||||
token = user.token
|
token = user.token
|
||||||
|
|
||||||
if user.preferences.unseen_only
|
if user.preferences.unseen_only
|
||||||
env.set "show_watched", true
|
env.set "show_watched", true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Refresh account
|
# Refresh account
|
||||||
headers = HTTP::Headers.new
|
headers = HTTP::Headers.new
|
||||||
headers["Cookie"] = env.request.headers["Cookie"]
|
headers["Cookie"] = env.request.headers["Cookie"]
|
||||||
|
|
||||||
if !user.password
|
if !user.password
|
||||||
user, sid = get_user(sid, headers, PG_DB)
|
user, sid = get_user(sid, headers, PG_DB)
|
||||||
end
|
end
|
||||||
|
|
||||||
max_results = user.preferences.max_results
|
max_results = user.preferences.max_results
|
||||||
max_results ||= env.params.query["max_results"]?.try &.to_i?
|
max_results ||= env.params.query["max_results"]?.try &.to_i?
|
||||||
max_results ||= 40
|
max_results ||= 40
|
||||||
|
|
||||||
page = env.params.query["page"]?.try &.to_i?
|
page = env.params.query["page"]?.try &.to_i?
|
||||||
page ||= 1
|
page ||= 1
|
||||||
|
|
||||||
videos, notifications = get_subscription_feed(PG_DB, user, max_results, page)
|
videos, notifications = get_subscription_feed(PG_DB, user, max_results, page)
|
||||||
|
|
||||||
# "updated" here is used for delivering new notifications, so if
|
# "updated" here is used for delivering new notifications, so if
|
||||||
# we know a user has looked at their feed e.g. in the past 10 minutes,
|
# we know a user has looked at their feed e.g. in the past 10 minutes,
|
||||||
# they've already seen a video posted 20 minutes ago, and don't need
|
# they've already seen a video posted 20 minutes ago, and don't need
|
||||||
# to be notified.
|
# to be notified.
|
||||||
PG_DB.exec("UPDATE users SET notifications = $1, updated = $2 WHERE email = $3", [] of String, Time.now,
|
PG_DB.exec("UPDATE users SET notifications = $1, updated = $2 WHERE email = $3", [] of String, Time.now,
|
||||||
user.email)
|
user.email)
|
||||||
user.notifications = [] of String
|
user.notifications = [] of String
|
||||||
env.set "user", user
|
env.set "user", user
|
||||||
|
|
||||||
templated "subscriptions"
|
templated "subscriptions"
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/feed/history" do |env|
|
get "/feed/history" do |env|
|
||||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||||
@ -2424,18 +2424,18 @@ get "/feed/history" do |env|
|
|||||||
next env.redirect referer
|
next env.redirect referer
|
||||||
end
|
end
|
||||||
|
|
||||||
user = user.as(User)
|
user = user.as(User)
|
||||||
|
|
||||||
limit = user.preferences.max_results.clamp(0, MAX_ITEMS_PER_PAGE)
|
limit = user.preferences.max_results.clamp(0, MAX_ITEMS_PER_PAGE)
|
||||||
if user.watched[(page - 1) * limit]?
|
if user.watched[(page - 1) * limit]?
|
||||||
watched = user.watched.reverse[(page - 1) * limit, limit]
|
watched = user.watched.reverse[(page - 1) * limit, limit]
|
||||||
else
|
else
|
||||||
watched = [] of String
|
watched = [] of String
|
||||||
end
|
|
||||||
|
|
||||||
templated "history"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
templated "history"
|
||||||
|
end
|
||||||
|
|
||||||
get "/feed/channel/:ucid" do |env|
|
get "/feed/channel/:ucid" do |env|
|
||||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||||
|
|
||||||
@ -2505,10 +2505,10 @@ get "/feed/channel/:ucid" do |env|
|
|||||||
|
|
||||||
videos.each do |video|
|
videos.each do |video|
|
||||||
video.to_xml(host_url, auto_generated, xml)
|
video.to_xml(host_url, auto_generated, xml)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/feed/private" do |env|
|
get "/feed/private" do |env|
|
||||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||||
@ -5058,6 +5058,11 @@ error 404 do |env|
|
|||||||
response = client.get(response.headers["Location"])
|
response = client.get(response.headers["Location"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if response.body.empty?
|
||||||
|
env.response.headers["Location"] = "/"
|
||||||
|
halt env, status_code: 302
|
||||||
|
end
|
||||||
|
|
||||||
html = XML.parse_html(response.body)
|
html = XML.parse_html(response.body)
|
||||||
ucid = html.xpath_node(%q(//meta[@itemprop="channelId"]))
|
ucid = html.xpath_node(%q(//meta[@itemprop="channelId"]))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user