From 7f16feaff64d2100d0fd0b5b2ee1355adbc3982d Mon Sep 17 00:00:00 2001 From: Fijxu Date: Tue, 24 Dec 2024 14:21:42 -0300 Subject: [PATCH] partial support for history details in history page --- src/invidious/database/users.cr | 6 +++--- src/invidious/routes/api/v1/authenticated.cr | 2 +- src/invidious/routes/watch.cr | 12 +++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/invidious/database/users.cr b/src/invidious/database/users.cr index 7ac14a52..a9512816 100644 --- a/src/invidious/database/users.cr +++ b/src/invidious/database/users.cr @@ -49,14 +49,14 @@ module Invidious::Database::Users PG_DB.exec(request, user.watched, user.email) end - def mark_watched(user : User, vid : String) + def mark_watched(user : User, history_details : JSON::Any) request = <<-SQL UPDATE users - SET watched = array_append(array_remove(watched, $1), $1) + SET watched = array_append(array_remove(watched, $1::jsonb), $1::jsonb) WHERE email = $2 SQL - PG_DB.exec(request, vid, user.email) + PG_DB.exec(request, history_details, user.email) end def mark_unwatched(user : User, vid : String) diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr index a35d2f2b..62c39cdf 100644 --- a/src/invidious/routes/api/v1/authenticated.cr +++ b/src/invidious/routes/api/v1/authenticated.cr @@ -86,7 +86,7 @@ module Invidious::Routes::API::V1::Authenticated return error_json(400, "Invalid video id.") end - Invidious::Database::Users.mark_watched(user, id) + # Invidious::Database::Users.mark_watched(user, id) env.response.status_code = 204 end diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index 42dfd1d4..fbdee104 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -76,8 +76,14 @@ module Invidious::Routes::Watch end env.params.query.delete_all("iv_load_policy") + history_details = JSON::Any.new({ + "id" => JSON::Any.new(id), + "title" => JSON::Any.new(video.title), + "author" => JSON::Any.new(video.author) + }) + if watched && preferences.watch_history - Invidious::Database::Users.mark_watched(user.as(User), id) + Invidious::Database::Users.mark_watched(user.as(User), history_details) end if CONFIG.enable_user_notifications && notifications && notifications.includes? id @@ -286,9 +292,9 @@ module Invidious::Routes::Watch case action when "action_mark_watched" - Invidious::Database::Users.mark_watched(user, id) + # Invidious::Database::Users.mark_watched(user, history_details) when "action_mark_unwatched" - Invidious::Database::Users.mark_unwatched(user, id) + # Invidious::Database::Users.mark_unwatched(user, id) else return error_json(400, "Unsupported action #{action}") end