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/api/videos/watching.ts | 44 ------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 server/controllers/api/videos/watching.ts (limited to 'server/controllers/api/videos/watching.ts') diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts deleted file mode 100644 index 3fd22caac..000000000 --- a/server/controllers/api/videos/watching.ts +++ /dev/null @@ -1,44 +0,0 @@ -import express from 'express' -import { HttpStatusCode, UserWatchingVideo } from '@shared/models' -import { - asyncMiddleware, - asyncRetryTransactionMiddleware, - authenticate, - openapiOperationDoc, - videoWatchingValidator -} from '../../../middlewares' -import { UserVideoHistoryModel } from '../../../models/user/user-video-history' - -const watchingRouter = express.Router() - -watchingRouter.put('/:videoId/watching', - openapiOperationDoc({ operationId: 'setProgress' }), - authenticate, - asyncMiddleware(videoWatchingValidator), - asyncRetryTransactionMiddleware(userWatchVideo) -) - -// --------------------------------------------------------------------------- - -export { - watchingRouter -} - -// --------------------------------------------------------------------------- - -async function userWatchVideo (req: express.Request, res: express.Response) { - const user = res.locals.oauth.token.User - - const body: UserWatchingVideo = req.body - const { id: videoId } = res.locals.videoId - - await UserVideoHistoryModel.upsert({ - videoId, - userId: user.id, - currentTime: body.currentTime - }) - - return res.type('json') - .status(HttpStatusCode.NO_CONTENT_204) - .end() -} -- cgit v1.2.3