From af4a6ee726c8aa0626e233e98f8f168d5462f118 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 5 May 2025 19:54:48 -0400 Subject: [PATCH] placeholder --- .../Services/Innertube/InnertubeService.bs | 17 ++++++ .../PlayletInvidiousBackendRouter.bs | 55 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs index 0638e567..ccb0d4ed 100644 --- a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs +++ b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs @@ -315,6 +315,23 @@ namespace InnertubeService return Innertube.ParseResponseDataForFeeds(json) end function + function AuthMarkVideoWatched(videoId as string, options = invalid as object) as object + ' cancellation = invalid + ' accessToken = invalid + + ' if options <> invalid + ' if options.DoesExist("cancellation") + ' cancellation = options.cancellation + ' end if + ' if options.DoesExist("accessToken") + ' accessToken = options.accessToken + ' end if + ' end if + + LogInfo(`Marking video as watched: ${videoId} - not implemented`) + return true + end function + function GetChannel(channelId as string, options = invalid as object) as object continuation = "" params = "" diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs index 6d1ed234..f5f68095 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs @@ -197,6 +197,49 @@ namespace Http return true end function + function AuthMarkVideoWatched(context as object) as boolean + request = context.request + response = context.response + route = request.route + + accessToken = request.headers["authorization"] + if StringUtils.IsNullOrEmpty(accessToken) or not accessToken.StartsWith("Bearer ") + response.Json({ + "error": "Missing or invalid 'Authorization' header" + }) + response.http_code = 403 + return true + end if + + videoId = route.Mid("/playlet-invidious-backend/api/v1/auth/history/".Len()) + if videoId.InStr("?") > 0 + videoId = videoId.Left(videoId.InStr("?")) + end if + + if StringUtils.IsNullOrEmpty(videoId) + response.Json({ + "error": "Missing 'videoId' path parameter" + }) + response.http_code = 400 + return true + end if + + options = { + "accessToken": accessToken.Mid("Bearer ".Len()) + } + + if not InnertubeService.AuthMarkVideoWatched(videoId, options) + response.Json({ + "error": "Failed to mark video as watched" + }) + response.http_code = 500 + return true + end if + + response.Default(204, "OK") + return true + end function + @get("/playlet-invidious-backend/api/v1/stats") function GetStats(context as object) as boolean response = context.response @@ -444,6 +487,18 @@ namespace Http return false end function + @post("*") + function PostAll(context as object) as boolean + request = context.request + route = request.route + + if route.StartsWith("/playlet-invidious-backend/api/v1/auth/history/") + return m.AuthMarkVideoWatched(context) + end if + + return false + end function + function GetVideo(context as object) as boolean request = context.request response = context.response