]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/controllers/api/videos/watching.ts
Merge branch 'release/4.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / watching.ts
... / ...
CommitLineData
1import express from 'express'
2import { HttpStatusCode, UserWatchingVideo } from '@shared/models'
3import {
4 asyncMiddleware,
5 asyncRetryTransactionMiddleware,
6 authenticate,
7 openapiOperationDoc,
8 videoWatchingValidator
9} from '../../../middlewares'
10import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
11
12const watchingRouter = express.Router()
13
14watchingRouter.put('/:videoId/watching',
15 openapiOperationDoc({ operationId: 'setProgress' }),
16 authenticate,
17 asyncMiddleware(videoWatchingValidator),
18 asyncRetryTransactionMiddleware(userWatchVideo)
19)
20
21// ---------------------------------------------------------------------------
22
23export {
24 watchingRouter
25}
26
27// ---------------------------------------------------------------------------
28
29async 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}