From a8c0023eb08676ab01141231fc04135a9052aa3a Mon Sep 17 00:00:00 2001 From: broquemonsieur Date: Sun, 23 Jul 2023 21:45:00 -0700 Subject: [PATCH] Debug SQL query for timestamp adjustment --- src/invidious/database/compilations.cr | 4 +-- src/invidious/routes/compilations.cr | 35 ++++++++++++++++--------- src/invidious/views/components/item.ecr | 2 +- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/invidious/database/compilations.cr b/src/invidious/database/compilations.cr index babe59bc..c8da9cfa 100644 --- a/src/invidious/database/compilations.cr +++ b/src/invidious/database/compilations.cr @@ -276,11 +276,11 @@ module Invidious::Database::CompilationVideos def update_start_timestamp(id : String, starting_timestamp_seconds : Int32) request = <<-SQL UPDATE compilation_videos - SET starting_timestamp_seconds = starting_timestamp_seconds + SET starting_timestamp_seconds = $2 WHERE id = $1 SQL - PG_DB.exec(request, id) + PG_DB.exec(request, id, starting_timestamp_seconds) end def update_end_timestamp(id : String, ending_timestamp_seconds : Int64) diff --git a/src/invidious/routes/compilations.cr b/src/invidious/routes/compilations.cr index 3171bebc..4e9e72bb 100644 --- a/src/invidious/routes/compilations.cr +++ b/src/invidious/routes/compilations.cr @@ -201,7 +201,7 @@ module Invidious::Routes::Compilations env.response.content_type = "application/json" user = env.get("user").as(User) - compid = env.params.url["compid"]? + compid = env.params.query["list"]? if !compid || compid.empty? return error_json(400, "A compilation ID is required") end @@ -215,31 +215,37 @@ module Invidious::Routes::Compilations return error_json(403, "Invalid user") end - 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 + #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 - if title != compilation.title || - privacy != compilation.privacy - updated = Time.utc - else - updated = compilation.updated - end + #if title != compilation.title || + # privacy != compilation.privacy + # updated = Time.utc + #else + # updated = compilation.updated + #end #{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 - (0..Invidious::Database::Compilations.count_owned_by(user.email)).each do |index| + (0..compilation_video_cardinality-1).each do |index| + LOGGER.info("for loop cycle #{index} of #{Invidious::Database::Compilations.count_owned_by(user.email)}") compilation_video_id = Invidious::Database::CompilationVideos.select_id_from_order_index(order_index: index) #compilation_video_index = Invidious::Database::CompilationVideos.select_index_from_order_index(order_index: index) compilation_video = Invidious::Database::CompilationVideos.select(compid, compilation.index, 0, 1) #numerical_string = index.to json_timestamp_query = index.to_s + "_start_timestamp" - start_timestamp = env.params.json[json_timestamp_query]?.try &.as(String).byte_slice(0, 8) + 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]} ") 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) if !start_timestamp_seconds.nil? - if start_timestamp_seconds >= 0 && start_timestamp_seconds <= compilation_video[0].starting_timestamp_seconds - Invidious::Database::CompilationVideos.update_start_timestamp(compilation_video_id, start_timestamp_seconds) + if start_timestamp_seconds >= 0 && start_timestamp_seconds <= compilation_video[0].length_seconds + LOGGER.info("adjusting timestamps to #{start_timestamp_seconds} which is #{start_timestamp_seconds.to_i}") + Invidious::Database::CompilationVideos.update_start_timestamp(compilation_video_id, start_timestamp_seconds.to_i) end end end @@ -256,6 +262,8 @@ module Invidious::Routes::Compilations end end + + env.redirect "/compilation?list=#{compid}" end @@ -369,6 +377,7 @@ module Invidious::Routes::Compilations when "action_edit_compilation" # TODO: Compilation stub LOGGER.info("Begin handling of Compilation edit") + when "action_add_video" if compilation.index.size >= CONFIG.compilation_length_limit if redirect diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index 4a9bacb3..163ebc11 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -58,7 +58,7 @@ if item.id.starts_with? "RD" link_url = "/mix?list=#{item.id}&continuation=#{URI.parse(item.thumbnail || "/vi/-----------").request_target.split("/")[2]}" else - link_url = "/playlist?list=#{item.id}" + link_url = "/compilation?list=#{item.id}" end -%>