summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Filo <jakub@filo.dev>2022-08-27 22:36:07 +0200
committerJakub Filo <jakub@filo.dev>2022-08-27 22:36:07 +0200
commit4818b89ab164713b1e52b7b03e48d47b6e7bce26 (patch)
tree6408df03ce1f6d5ce844bcac4b31dd81815d7fe4
parenta7d9df551675169014a3a9481f9a3871f055d9db (diff)
downloadinvidious-4818b89ab164713b1e52b7b03e48d47b6e7bce26.tar.gz
invidious-4818b89ab164713b1e52b7b03e48d47b6e7bce26.tar.bz2
invidious-4818b89ab164713b1e52b7b03e48d47b6e7bce26.zip
Allow to set maximum custom playlist length via a config variable.
-rw-r--r--config/config.example.yml8
-rw-r--r--src/invidious/config.cr3
-rw-r--r--src/invidious/database/playlists.cr2
-rw-r--r--src/invidious/routes/api/v1/authenticated.cr4
-rw-r--r--src/invidious/routes/playlists.cr6
-rw-r--r--src/invidious/routes/subscriptions.cr2
-rw-r--r--src/invidious/user/imports.cr2
7 files changed, 19 insertions, 8 deletions
diff --git a/config/config.example.yml b/config/config.example.yml
index 10734c3a..424e2a38 100644
--- a/config/config.example.yml
+++ b/config/config.example.yml
@@ -869,3 +869,11 @@ default_user_preferences:
## Default: false
##
#extend_desc: false
+
+ ##
+ ## Maximum custom playlist length limit.
+ ##
+ ## Accepted values: Integer
+ ## Default: 500
+ ##
+ #playlist_length_limit: 500
diff --git a/src/invidious/config.cr b/src/invidious/config.cr
index 786b65df..f0873df4 100644
--- a/src/invidious/config.cr
+++ b/src/invidious/config.cr
@@ -131,6 +131,9 @@ class Config
# API URL for Anti-Captcha
property captcha_api_url : String = "https://api.anti-captcha.com"
+ # Playlist length limit
+ property playlist_length_limit : Int32 = 500
+
def disabled?(option)
case disabled = CONFIG.disable_proxy
when Bool
diff --git a/src/invidious/database/playlists.cr b/src/invidious/database/playlists.cr
index c6754a1e..5f47ff95 100644
--- a/src/invidious/database/playlists.cr
+++ b/src/invidious/database/playlists.cr
@@ -248,7 +248,7 @@ module Invidious::Database::PlaylistVideos
return PG_DB.query_one?(request, plid, index, as: String)
end
- def select_ids(plid : String, index : VideoIndex, limit = 500) : Array(String)
+ def select_ids(plid : String, index : VideoIndex, limit = CONFIG.playlist_length_limit) : Array(String)
request = <<-SQL
SELECT id FROM playlist_videos
WHERE plid = $1
diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr
index 1f5ad8ef..421355bb 100644
--- a/src/invidious/routes/api/v1/authenticated.cr
+++ b/src/invidious/routes/api/v1/authenticated.cr
@@ -226,8 +226,8 @@ module Invidious::Routes::API::V1::Authenticated
return error_json(403, "Invalid user")
end
- if playlist.index.size >= 500
- return error_json(400, "Playlist cannot have more than 500 videos")
+ if playlist.index.size >= CONFIG.playlist_length_limit
+ return error_json(400, "Playlist cannot have more than #{CONFIG.playlist_length_limit} videos")
end
video_id = env.params.json["videoId"].try &.as(String)
diff --git a/src/invidious/routes/playlists.cr b/src/invidious/routes/playlists.cr
index fe7e4e1c..0d242ee6 100644
--- a/src/invidious/routes/playlists.cr
+++ b/src/invidious/routes/playlists.cr
@@ -330,11 +330,11 @@ module Invidious::Routes::Playlists
when "action_edit_playlist"
# TODO: Playlist stub
when "action_add_video"
- if playlist.index.size >= 500
+ if playlist.index.size >= CONFIG.playlist_length_limit
if redirect
- return error_template(400, "Playlist cannot have more than 500 videos")
+ return error_template(400, "Playlist cannot have more than #{CONFIG.playlist_length_limit} videos")
else
- return error_json(400, "Playlist cannot have more than 500 videos")
+ return error_json(400, "Playlist cannot have more than #{CONFIG.playlist_length_limit} videos")
end
end
diff --git a/src/invidious/routes/subscriptions.cr b/src/invidious/routes/subscriptions.cr
index 7b1fa876..ed595d9a 100644
--- a/src/invidious/routes/subscriptions.cr
+++ b/src/invidious/routes/subscriptions.cr
@@ -120,7 +120,7 @@ module Invidious::Routes::Subscriptions
json.field "privacy", playlist.privacy.to_s
json.field "videos" do
json.array do
- Invidious::Database::PlaylistVideos.select_ids(playlist.id, playlist.index, limit: 500).each do |video_id|
+ Invidious::Database::PlaylistVideos.select_ids(playlist.id, playlist.index, limit: CONFIG.playlist_length_limit).each do |video_id|
json.string video_id
end
end
diff --git a/src/invidious/user/imports.cr b/src/invidious/user/imports.cr
index f8b9e4e4..bd929e4d 100644
--- a/src/invidious/user/imports.cr
+++ b/src/invidious/user/imports.cr
@@ -71,7 +71,7 @@ struct Invidious::User
Invidious::Database::Playlists.update_description(playlist.id, description)
videos = item["videos"]?.try &.as_a?.try &.each_with_index do |video_id, idx|
- raise InfoException.new("Playlist cannot have more than 500 videos") if idx > 500
+ raise InfoException.new("Playlist cannot have more than #{CONFIG.playlist_length_limit} videos") if idx > 500
video_id = video_id.try &.as_s?
next if !video_id