mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-14 14:20:34 +05:30
Clean useless database arguments (3/5)
This commit is contained in:
parent
c25d664edc
commit
40ed4a0506
@ -783,7 +783,7 @@ post "/data_control" do |env|
|
|||||||
next if !description
|
next if !description
|
||||||
next if !privacy
|
next if !privacy
|
||||||
|
|
||||||
playlist = create_playlist(PG_DB, title, privacy, user)
|
playlist = create_playlist(title, privacy, user)
|
||||||
Invidious::Database::Playlists.update_description(playlist.id, description)
|
Invidious::Database::Playlists.update_description(playlist.id, description)
|
||||||
|
|
||||||
videos = item["videos"]?.try &.as_a?.try &.each_with_index do |video_id, idx|
|
videos = item["videos"]?.try &.as_a?.try &.each_with_index do |video_id, idx|
|
||||||
|
@ -125,7 +125,7 @@ struct Playlist
|
|||||||
|
|
||||||
json.field "videos" do
|
json.field "videos" do
|
||||||
json.array do
|
json.array do
|
||||||
videos = get_playlist_videos(PG_DB, self, offset: offset, locale: locale, video_id: video_id)
|
videos = get_playlist_videos(self, offset: offset, locale: locale, video_id: video_id)
|
||||||
videos.each do |video|
|
videos.each do |video|
|
||||||
video.to_json(json)
|
video.to_json(json)
|
||||||
end
|
end
|
||||||
@ -205,7 +205,7 @@ struct InvidiousPlaylist
|
|||||||
offset = self.index.index(index) || 0
|
offset = self.index.index(index) || 0
|
||||||
end
|
end
|
||||||
|
|
||||||
videos = get_playlist_videos(PG_DB, self, offset: offset, locale: locale, video_id: video_id)
|
videos = get_playlist_videos(self, offset: offset, locale: locale, video_id: video_id)
|
||||||
videos.each_with_index do |video, index|
|
videos.each_with_index do |video, index|
|
||||||
video.to_json(json, offset + index)
|
video.to_json(json, offset + index)
|
||||||
end
|
end
|
||||||
@ -247,7 +247,7 @@ struct InvidiousPlaylist
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_playlist(db, title, privacy, user)
|
def create_playlist(title, privacy, user)
|
||||||
plid = "IVPL#{Random::Secure.urlsafe_base64(24)[0, 31]}"
|
plid = "IVPL#{Random::Secure.urlsafe_base64(24)[0, 31]}"
|
||||||
|
|
||||||
playlist = InvidiousPlaylist.new({
|
playlist = InvidiousPlaylist.new({
|
||||||
@ -267,7 +267,7 @@ def create_playlist(db, title, privacy, user)
|
|||||||
return playlist
|
return playlist
|
||||||
end
|
end
|
||||||
|
|
||||||
def subscribe_playlist(db, user, playlist)
|
def subscribe_playlist(user, playlist)
|
||||||
playlist = InvidiousPlaylist.new({
|
playlist = InvidiousPlaylist.new({
|
||||||
title: playlist.title.byte_slice(0, 150),
|
title: playlist.title.byte_slice(0, 150),
|
||||||
id: playlist.id,
|
id: playlist.id,
|
||||||
@ -322,7 +322,7 @@ def produce_playlist_continuation(id, index)
|
|||||||
return continuation
|
return continuation
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_playlist(db, plid, locale, refresh = true, force_refresh = false)
|
def get_playlist(plid, locale, refresh = true, force_refresh = false)
|
||||||
if plid.starts_with? "IV"
|
if plid.starts_with? "IV"
|
||||||
if playlist = Invidious::Database::Playlists.select(id: plid)
|
if playlist = Invidious::Database::Playlists.select(id: plid)
|
||||||
return playlist
|
return playlist
|
||||||
@ -404,7 +404,7 @@ def fetch_playlist(plid, locale)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_playlist_videos(db, playlist, offset, locale = nil, video_id = nil)
|
def get_playlist_videos(playlist, offset, locale = nil, video_id = nil)
|
||||||
# Show empy playlist if requested page is out of range
|
# Show empy playlist if requested page is out of range
|
||||||
# (e.g, when a new playlist has been created, offset will be negative)
|
# (e.g, when a new playlist has been created, offset will be negative)
|
||||||
if offset >= playlist.video_count || offset < 0
|
if offset >= playlist.video_count || offset < 0
|
||||||
|
@ -150,7 +150,7 @@ module Invidious::Routes::API::V1::Authenticated
|
|||||||
return error_json(400, "User cannot have more than 100 playlists.")
|
return error_json(400, "User cannot have more than 100 playlists.")
|
||||||
end
|
end
|
||||||
|
|
||||||
playlist = create_playlist(PG_DB, title, privacy, user)
|
playlist = create_playlist(title, privacy, user)
|
||||||
env.response.headers["Location"] = "#{HOST_URL}/api/v1/auth/playlists/#{playlist.id}"
|
env.response.headers["Location"] = "#{HOST_URL}/api/v1/auth/playlists/#{playlist.id}"
|
||||||
env.response.status_code = 201
|
env.response.status_code = 201
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@ module Invidious::Routes::API::V1::Misc
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
playlist = get_playlist(PG_DB, plid, locale)
|
playlist = get_playlist(plid, locale)
|
||||||
rescue ex : InfoException
|
rescue ex : InfoException
|
||||||
return error_json(404, ex)
|
return error_json(404, ex)
|
||||||
rescue ex
|
rescue ex
|
||||||
|
@ -6,9 +6,9 @@ module Invidious::Routes::Embed
|
|||||||
|
|
||||||
if plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")
|
if plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")
|
||||||
begin
|
begin
|
||||||
playlist = get_playlist(PG_DB, plid, locale: locale)
|
playlist = get_playlist(plid, locale: locale)
|
||||||
offset = env.params.query["index"]?.try &.to_i? || 0
|
offset = env.params.query["index"]?.try &.to_i? || 0
|
||||||
videos = get_playlist_videos(PG_DB, playlist, offset: offset, locale: locale)
|
videos = get_playlist_videos(playlist, offset: offset, locale: locale)
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_template(500, ex)
|
return error_template(500, ex)
|
||||||
end
|
end
|
||||||
@ -60,9 +60,9 @@ module Invidious::Routes::Embed
|
|||||||
|
|
||||||
if plid
|
if plid
|
||||||
begin
|
begin
|
||||||
playlist = get_playlist(PG_DB, plid, locale: locale)
|
playlist = get_playlist(plid, locale: locale)
|
||||||
offset = env.params.query["index"]?.try &.to_i? || 0
|
offset = env.params.query["index"]?.try &.to_i? || 0
|
||||||
videos = get_playlist_videos(PG_DB, playlist, offset: offset, locale: locale)
|
videos = get_playlist_videos(playlist, offset: offset, locale: locale)
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_template(500, ex)
|
return error_template(500, ex)
|
||||||
end
|
end
|
||||||
|
@ -265,7 +265,7 @@ module Invidious::Routes::Feeds
|
|||||||
|
|
||||||
if plid.starts_with? "IV"
|
if plid.starts_with? "IV"
|
||||||
if playlist = Invidious::Database::Playlists.select(id: plid)
|
if playlist = Invidious::Database::Playlists.select(id: plid)
|
||||||
videos = get_playlist_videos(PG_DB, playlist, offset: 0, locale: locale)
|
videos = get_playlist_videos(playlist, offset: 0, locale: locale)
|
||||||
|
|
||||||
return XML.build(indent: " ", encoding: "UTF-8") do |xml|
|
return XML.build(indent: " ", encoding: "UTF-8") do |xml|
|
||||||
xml.element("feed", "xmlns:yt": "http://www.youtube.com/xml/schemas/2015",
|
xml.element("feed", "xmlns:yt": "http://www.youtube.com/xml/schemas/2015",
|
||||||
|
@ -50,7 +50,7 @@ module Invidious::Routes::Playlists
|
|||||||
return error_template(400, "User cannot have more than 100 playlists.")
|
return error_template(400, "User cannot have more than 100 playlists.")
|
||||||
end
|
end
|
||||||
|
|
||||||
playlist = create_playlist(PG_DB, title, privacy, user)
|
playlist = create_playlist(title, privacy, user)
|
||||||
|
|
||||||
env.redirect "/playlist?list=#{playlist.id}"
|
env.redirect "/playlist?list=#{playlist.id}"
|
||||||
end
|
end
|
||||||
@ -66,8 +66,8 @@ module Invidious::Routes::Playlists
|
|||||||
user = user.as(User)
|
user = user.as(User)
|
||||||
|
|
||||||
playlist_id = env.params.query["list"]
|
playlist_id = env.params.query["list"]
|
||||||
playlist = get_playlist(PG_DB, playlist_id, locale)
|
playlist = get_playlist(playlist_id, locale)
|
||||||
subscribe_playlist(PG_DB, user, playlist)
|
subscribe_playlist(user, playlist)
|
||||||
|
|
||||||
env.redirect "/playlist?list=#{playlist.id}"
|
env.redirect "/playlist?list=#{playlist.id}"
|
||||||
end
|
end
|
||||||
@ -161,7 +161,7 @@ module Invidious::Routes::Playlists
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
videos = get_playlist_videos(PG_DB, playlist, offset: (page - 1) * 100, locale: locale)
|
videos = get_playlist_videos(playlist, offset: (page - 1) * 100, locale: locale)
|
||||||
rescue ex
|
rescue ex
|
||||||
videos = [] of PlaylistVideo
|
videos = [] of PlaylistVideo
|
||||||
end
|
end
|
||||||
@ -314,7 +314,7 @@ module Invidious::Routes::Playlists
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
playlist_id = env.params.query["playlist_id"]
|
playlist_id = env.params.query["playlist_id"]
|
||||||
playlist = get_playlist(PG_DB, playlist_id, locale).as(InvidiousPlaylist)
|
playlist = get_playlist(playlist_id, locale).as(InvidiousPlaylist)
|
||||||
raise "Invalid user" if playlist.author != user.email
|
raise "Invalid user" if playlist.author != user.email
|
||||||
rescue ex
|
rescue ex
|
||||||
if redirect
|
if redirect
|
||||||
@ -405,7 +405,7 @@ module Invidious::Routes::Playlists
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
playlist = get_playlist(PG_DB, plid, locale)
|
playlist = get_playlist(plid, locale)
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_template(500, ex)
|
return error_template(500, ex)
|
||||||
end
|
end
|
||||||
@ -422,7 +422,7 @@ module Invidious::Routes::Playlists
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
videos = get_playlist_videos(PG_DB, playlist, offset: (page - 1) * 100, locale: locale)
|
videos = get_playlist_videos(playlist, offset: (page - 1) * 100, locale: locale)
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_template(500, "Error encountered while retrieving playlist videos.<br>#{ex.message}")
|
return error_template(500, "Error encountered while retrieving playlist videos.<br>#{ex.message}")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user