mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Minor refactor
This commit is contained in:
parent
7d3ecd2297
commit
26107bd6c3
3 changed files with 86 additions and 131 deletions
|
@ -159,10 +159,9 @@ class APIHandler < Kemal::Handler
|
|||
call_next env
|
||||
|
||||
env.response.output.rewind
|
||||
response = env.response.output.gets_to_end
|
||||
|
||||
if env.response.headers["Content-Type"]?.try &.== "application/json"
|
||||
response = JSON.parse(response)
|
||||
if env.response.headers.includes_word?("Content-Type", "application/json")
|
||||
response = JSON.parse(env.response.output)
|
||||
|
||||
if fields_text = env.params.query["fields"]?
|
||||
begin
|
||||
|
@ -178,6 +177,8 @@ class APIHandler < Kemal::Handler
|
|||
else
|
||||
response = response.to_json
|
||||
end
|
||||
else
|
||||
response = env.response.output.gets_to_end
|
||||
end
|
||||
rescue ex
|
||||
ensure
|
||||
|
|
|
@ -295,8 +295,7 @@ def get_subscription_feed(db, user, max_results = 40, page = 1)
|
|||
|
||||
args = arg_array(notifications)
|
||||
|
||||
notifications = db.query_all("SELECT * FROM channel_videos WHERE id IN (#{args})
|
||||
ORDER BY published DESC", notifications, as: ChannelVideo)
|
||||
notifications = db.query_all("SELECT * FROM channel_videos WHERE id IN (#{args}) ORDER BY published DESC", notifications, as: ChannelVideo)
|
||||
videos = [] of ChannelVideo
|
||||
|
||||
notifications.sort_by! { |video| video.published }.reverse!
|
||||
|
@ -322,14 +321,11 @@ def get_subscription_feed(db, user, max_results = 40, page = 1)
|
|||
else
|
||||
values = "VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}"
|
||||
end
|
||||
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE \
|
||||
NOT id = ANY (#{values}) \
|
||||
ORDER BY ucid, published DESC", as: ChannelVideo)
|
||||
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE NOT id = ANY (#{values}) ORDER BY ucid, published DESC", as: ChannelVideo)
|
||||
else
|
||||
# Show latest video from each channel
|
||||
|
||||
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} \
|
||||
ORDER BY ucid, published DESC", as: ChannelVideo)
|
||||
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} ORDER BY ucid, published DESC", as: ChannelVideo)
|
||||
end
|
||||
|
||||
videos.sort_by! { |video| video.published }.reverse!
|
||||
|
@ -342,14 +338,11 @@ def get_subscription_feed(db, user, max_results = 40, page = 1)
|
|||
else
|
||||
values = "VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}"
|
||||
end
|
||||
videos = PG_DB.query_all("SELECT * FROM #{view_name} WHERE \
|
||||
NOT id = ANY (#{values}) \
|
||||
ORDER BY published DESC LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
||||
videos = PG_DB.query_all("SELECT * FROM #{view_name} WHERE NOT id = ANY (#{values}) ORDER BY published DESC LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
||||
else
|
||||
# Sort subscriptions as normal
|
||||
|
||||
videos = PG_DB.query_all("SELECT * FROM #{view_name} \
|
||||
ORDER BY published DESC LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
||||
videos = PG_DB.query_all("SELECT * FROM #{view_name} ORDER BY published DESC LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -366,16 +359,11 @@ def get_subscription_feed(db, user, max_results = 40, page = 1)
|
|||
videos.sort_by! { |video| video.author }.reverse!
|
||||
end
|
||||
|
||||
notifications = PG_DB.query_one("SELECT notifications FROM users WHERE email = $1", user.email,
|
||||
as: Array(String))
|
||||
notifications = PG_DB.query_one("SELECT notifications FROM users WHERE email = $1", user.email, as: Array(String))
|
||||
|
||||
notifications = videos.select { |v| notifications.includes? v.id }
|
||||
videos = videos - notifications
|
||||
end
|
||||
|
||||
if !limit
|
||||
videos = videos[0..max_results]
|
||||
end
|
||||
|
||||
return videos, notifications
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue