From b211106695bb82f6c32e53306081b5262c3d109d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 24 Mar 2022 13:36:47 +0100 Subject: Support video views/viewers stats in server * Add "currentTime" and "event" body params to view endpoint * Merge watching and view endpoints * Introduce WatchAction AP activity * Add tables to store viewer information of local videos * Add endpoints to fetch video views/viewers stats of local videos * Refactor views/viewers handlers * Support "views" and "viewers" counters for both VOD and live videos --- server/controllers/activitypub/client.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'server/controllers/activitypub/client.ts') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index d0f761009..8e064fb5b 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -27,7 +27,7 @@ import { videosShareValidator } from '../../middlewares' import { cacheRoute } from '../../middlewares/cache/cache' -import { getAccountVideoRateValidatorFactory, videoCommentGetValidator } from '../../middlewares/validators' +import { getAccountVideoRateValidatorFactory, getVideoLocalViewerValidator, videoCommentGetValidator } from '../../middlewares/validators' import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy' import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' import { AccountModel } from '../../models/account/account' @@ -175,6 +175,12 @@ activityPubClientRouter.get('/video-playlists/:playlistId/videos/:playlistElemen videoPlaylistElementController ) +activityPubClientRouter.get('/videos/local-viewer/:localViewerId', + executeIfActivityPub, + asyncMiddleware(getVideoLocalViewerValidator), + getVideoLocalViewerController +) + // --------------------------------------------------------------------------- export { @@ -399,6 +405,12 @@ function videoPlaylistElementController (req: express.Request, res: express.Resp return activityPubResponse(activityPubContextify(json, 'Playlist'), res) } +function getVideoLocalViewerController (req: express.Request, res: express.Response) { + const localViewer = res.locals.localViewerFull + + return activityPubResponse(activityPubContextify(localViewer.toActivityPubObject(), 'WatchAction'), res) +} + // --------------------------------------------------------------------------- function actorFollowing (req: express.Request, actor: MActorId) { -- cgit v1.2.3