diff --git a/assets/js/compilation_widget.js b/assets/js/compilation_widget.js index 7e8e6356..16ace89e 100644 --- a/assets/js/compilation_widget.js +++ b/assets/js/compilation_widget.js @@ -46,3 +46,18 @@ function remove_compilation_item(target) { } }); } + +function move_compilation_video_before(target) { + var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode; + tile.style.display = 'none'; + + var url = '/compilation_ajax?action_move_video_before=1&redirect=false' + + '&set_video_id=' + target.getAttribute('data-index') + + '&compilation_id=' + target.getAttribute('data-compid'); + + helpers.xhr('POST', url, {payload: payload}, { + onNon200: function (xhr) { + tile.style.display = ''; + } + }); +} diff --git a/locales/en-US.json b/locales/en-US.json index 3905de6e..73fbd177 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -179,7 +179,10 @@ "Playlist privacy": "Playlist privacy", "Compilation privacy": "Compilation privacy", "Editing playlist `x`": "Editing playlist `x`", + "Editing compilation `x`": "Editing compilation `x`", "playlist_button_add_items": "Add videos", + "compilation_button_add_items": "Add videos", + "compilation_button_play": "Play", "Show more": "Show more", "Show less": "Show less", "Watch on YouTube": "Watch on YouTube", diff --git a/src/invidious/compilations.cr b/src/invidious/compilations.cr index e87a1a7a..bf532ac9 100644 --- a/src/invidious/compilations.cr +++ b/src/invidious/compilations.cr @@ -244,7 +244,7 @@ end def create_compilation(title, privacy, user) LOGGER.info("2. create_compilation") - compid = "IVPL#{Random::Secure.urlsafe_base64(24)[0, 31]}" + compid = "IVCMP#{Random::Secure.urlsafe_base64(24)[0, 31]}" LOGGER.info("generated compilation id") compilation = InvidiousCompilation.new({ @@ -320,7 +320,7 @@ def produce_compilation_continuation(id, index) end def get_compilation(compid : String) - #if compid.starts_with? "IV" + #if compid.starts_with? "IVCMP" if compilation = Invidious::Database::Compilations.select(id: compid) return compilation else diff --git a/src/invidious/routes/compilations.cr b/src/invidious/routes/compilations.cr index 4e9e72bb..90ccb2e1 100644 --- a/src/invidious/routes/compilations.cr +++ b/src/invidious/routes/compilations.cr @@ -197,11 +197,31 @@ module Invidious::Routes::Compilations end def self.adjust_timestamps(env) + locale = env.get("preferences").as(Preferences).locale LOGGER.info("Handle POST request for edit compilation") env.response.content_type = "application/json" - user = env.get("user").as(User) + user = env.get("user") + sid = env.get? "sid" + + referer = get_referer(env) + + return env.redirect "/" if user.nil? compid = env.params.query["list"]? + return env.redirect referer if compid.nil? + + user = user.as(User) + + sid = sid.as(String) + token = env.params.body["csrf_token"]? + + begin + validate_request(token, sid, env.request, HMAC_KEY, locale) + rescue ex + return error_template(400, ex) + end + + if !compid || compid.empty? return error_json(400, "A compilation ID is required") end @@ -215,6 +235,9 @@ module Invidious::Routes::Compilations return error_json(403, "Invalid user") end + title = env.params.body["title"]?.try &.delete("<>") || "" + privacy = CompilationPrivacy.parse(env.params.body["privacy"]? || "Private") + #title = env.params.json["title"].try &.as(String).delete("<>").byte_slice(0, 150) || compilation.title #privacy = env.params.json["privacy"]?.try { |p| CompilationPrivacy.parse(p.as(String).downcase) } || compilation.privacy @@ -225,6 +248,8 @@ module Invidious::Routes::Compilations # updated = compilation.updated #end + Invidious::Database::Compilations.update(compid, title, privacy, "", compilation.updated) + #{1...Invidious::Database::Compilations.count_owned_by(user.email)}.each do |index| # start_timestamp = env.params.json["_start_timestamp"]?.try &.as(String).byte_slice(0, 150) || compilation.title compilation_video_cardinality = Invidious::Database::CompilationVideos.select_ids(compid, compilation.index).size @@ -238,7 +263,7 @@ module Invidious::Routes::Compilations json_timestamp_query = index.to_s + "_start_timestamp" LOGGER.info("adjust #{json_timestamp_query} ") start_timestamp = env.params.body[json_timestamp_query]?.try &.as(String).byte_slice(0, 8) - LOGGER.info("render #{env.params.body[json_timestamp_query]} ") + LOGGER.info("render #{env.params.body[json_timestamp_query]?} ") if !start_timestamp.nil? && !compilation_video_id.nil? LOGGER.info("adjust #{json_timestamp_query} which renders as #{start_timestamp}") start_timestamp_seconds = decode_length_seconds(start_timestamp) @@ -353,6 +378,8 @@ module Invidious::Routes::Compilations action = "action_remove_video" elsif env.params.query["action_move_video_before"]? action = "action_move_video_before" + elsif env.params.query["action_move_video_after"]? + action = "action_move_video_after" else return env.redirect referer end diff --git a/src/invidious/views/compilation.ecr b/src/invidious/views/compilation.ecr index 6bcd7d0f..2520dc0c 100644 --- a/src/invidious/views/compilation.ecr +++ b/src/invidious/views/compilation.ecr @@ -6,9 +6,43 @@ <% end %> +
+

<%= title %>

+ +
+ <%- if compilation.is_a?(InvidiousCompilation) && compilation.author == user.try &.email -%> + + + + + <%- end -%> + + +
+
+
-
-

<%= title %>

+
<% if compilation.is_a? InvidiousCompilation %> <% if compilation.author == user.try &.email %> @@ -33,35 +67,12 @@ <% end %>
-
-

-
- <% if compilation.is_a?(InvidiousCompilation) && compilation.author == user.try &.email %> -
-
- <% else %> - <% if !Invidious::Database::Compilations.exists?(compilation.id) %> -
- <% end %> - <% end %> -
-
-

-
<%= compilation.description_html %>
-<% if compilation.is_a?(InvidiousCompilation) && compilation.author == user.try &.email %> -
-

- -

-
-<% end %> -

@@ -82,23 +93,3 @@ <%= rendered "components/compilation_video" %> <% end %>
- - - -
-
- <% if page > 1 %> - - <%= translate(locale, "Previous page") %> - - <% end %> -
-
-
- <% if page_count != 1 && page < page_count %> - - <%= translate(locale, "Next page") %> - - <% end %> -
-
\ No newline at end of file diff --git a/src/invidious/views/components/compilation_video.ecr b/src/invidious/views/components/compilation_video.ecr index 84dafc2a..b30d6a2e 100644 --- a/src/invidious/views/components/compilation_video.ecr +++ b/src/invidious/views/components/compilation_video.ecr @@ -2,12 +2,25 @@
- - - - - - + <%- form_parameters = "action_move_video_before=1&set_video_id=#{compilation_video.index}&compilation_id=#{compilation_video.compid}&referer=#{env.get("current_page")}" -%> +
+ "> + +
+ <%- form_parameters = "action_move_video_after=1&set_video_id=#{compilation_video.index}&compilation_id=#{compilation_video.compid}&referer=#{env.get("current_page")}" -%> +
+ "> + +
- <% if compilation.is_a?(InvidiousCompilation) && compilation.author == user.try &.email %> -
-

- -

-
- <% end %> -

@@ -65,3 +64,5 @@ + +