diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-24 13:36:47 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | b211106695bb82f6c32e53306081b5262c3d109d (patch) | |
tree | fa187de1c33b0956665f5362e29af6b0f6d8bb57 /server/controllers/api/videos/watching.ts | |
parent | 69d48ee30c9d47cddf0c3c047dc99a99dcb6e894 (diff) | |
download | PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.gz PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.zst PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.zip |
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
Diffstat (limited to 'server/controllers/api/videos/watching.ts')
-rw-r--r-- | server/controllers/api/videos/watching.ts | 44 |
1 files changed, 0 insertions, 44 deletions
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 @@ | |||
1 | import express from 'express' | ||
2 | import { HttpStatusCode, UserWatchingVideo } from '@shared/models' | ||
3 | import { | ||
4 | asyncMiddleware, | ||
5 | asyncRetryTransactionMiddleware, | ||
6 | authenticate, | ||
7 | openapiOperationDoc, | ||
8 | videoWatchingValidator | ||
9 | } from '../../../middlewares' | ||
10 | import { UserVideoHistoryModel } from '../../../models/user/user-video-history' | ||
11 | |||
12 | const watchingRouter = express.Router() | ||
13 | |||
14 | watchingRouter.put('/:videoId/watching', | ||
15 | openapiOperationDoc({ operationId: 'setProgress' }), | ||
16 | authenticate, | ||
17 | asyncMiddleware(videoWatchingValidator), | ||
18 | asyncRetryTransactionMiddleware(userWatchVideo) | ||
19 | ) | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | export { | ||
24 | watchingRouter | ||
25 | } | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | async function userWatchVideo (req: express.Request, res: express.Response) { | ||
30 | const user = res.locals.oauth.token.User | ||
31 | |||
32 | const body: UserWatchingVideo = req.body | ||
33 | const { id: videoId } = res.locals.videoId | ||
34 | |||
35 | await UserVideoHistoryModel.upsert({ | ||
36 | videoId, | ||
37 | userId: user.id, | ||
38 | currentTime: body.currentTime | ||
39 | }) | ||
40 | |||
41 | return res.type('json') | ||
42 | .status(HttpStatusCode.NO_CONTENT_204) | ||
43 | .end() | ||
44 | } | ||