From b6181b9d97d270356d5dae3dabe1f03d8dd34803 Mon Sep 17 00:00:00 2001 From: broquemonsieur Date: Thu, 15 Jun 2023 21:29:37 -0700 Subject: [PATCH] Add authenticated API for compilation creation --- assets/css/default.css | 7 ++++++ src/invidious/routes/api/v1/authenticated.cr | 26 ++++++++++++++++++++ src/invidious/routing.cr | 2 ++ src/invidious/views/components/item.ecr | 3 +++ src/invidious/views/feeds/compilations.ecr | 2 +- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/assets/css/default.css b/assets/css/default.css index c31b24e5..9828513a 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -759,3 +759,10 @@ h1, h2, h3, h4, h5, p, .channel-emoji { margin: 0 2px; } + +div.compilation-video-panel { + display: block; + margin-left: auto; + margin-right: auto; + color: #d9d9d9; +} diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr index a35d2f2b..0f96965c 100644 --- a/src/invidious/routes/api/v1/authenticated.cr +++ b/src/invidious/routes/api/v1/authenticated.cr @@ -207,6 +207,32 @@ module Invidious::Routes::API::V1::Authenticated end end + def self.create_compilation(env) + env.response.content_type = "application/json" + user = env.get("user").as(User) + + title = env.params.json["title"]?.try &.as(String).delete("<>").byte_slice(0, 150) + if !title + return error_json(400, "Invalid title.") + end + + privacy = env.params.json["privacy"]?.try { |p| CompilationPrivacy.parse(p.as(String).downcase) } + if !privacy + return error_json(400, "Invalid privacy setting.") + end + + if Invidious::Database::Compilations.count_owned_by(user.email) >= 100 + return error_json(400, "User cannot have more than 100 compilations.") + end + + compilation = create_compilation(title, privacy, user) + env.response.headers["Location"] = "#{HOST_URL}/api/v1/auth/compilations/#{playlist.id}" + env.response.status_code = 201 + { + "title" => title, + "compilationId" => compilation.id, + }.to_json + def self.create_playlist(env) env.response.content_type = "application/json" user = env.get("user").as(User) diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr index a653c1a5..a40bef73 100644 --- a/src/invidious/routing.cr +++ b/src/invidious/routing.cr @@ -274,6 +274,8 @@ module Invidious::Routing post "/api/v1/auth/subscriptions/:ucid", {{namespace}}::Authenticated, :subscribe_channel delete "/api/v1/auth/subscriptions/:ucid", {{namespace}}::Authenticated, :unsubscribe_channel + get "/api/v1/auth/compilations", {{namespace}}::Authenticated, :create_compilation + get "/api/v1/auth/playlists", {{namespace}}::Authenticated, :list_playlists post "/api/v1/auth/playlists", {{namespace}}::Authenticated, :create_playlist patch "/api/v1/auth/playlists/:plid",{{namespace}}:: Authenticated, :update_playlist_attribute diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index 867e2e8f..8f8ba40f 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -90,6 +90,9 @@ <% when CompilationVideo %> <% if !env.get("preferences").as(Preferences).thin_mode %> +
+ +
<% end %>
<% when Category %> diff --git a/src/invidious/views/feeds/compilations.ecr b/src/invidious/views/feeds/compilations.ecr index a7280e30..31d073c4 100644 --- a/src/invidious/views/feeds/compilations.ecr +++ b/src/invidious/views/feeds/compilations.ecr @@ -10,7 +10,7 @@

- "><%= translate(locale, "Create compilation") %> + "><%= translate(locale, "Create compilation") %>