]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
41fb13c3 1import express from 'express'
6e46de09 2import { UserWatchingVideo } from '../../../../shared'
4c7e60bc 3import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
c756bae0
RK
4import {
5 asyncMiddleware,
6 asyncRetryTransactionMiddleware,
7 authenticate,
8 openapiOperationDoc,
9 videoWatchingValidator
10} from '../../../middlewares'
7d9ba5c0 11import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
6e46de09
C
12
13const watchingRouter = express.Router()
14
15watchingRouter.put('/:videoId/watching',
c756bae0 16 openapiOperationDoc({ operationId: 'setProgress' }),
6e46de09
C
17 authenticate,
18 asyncMiddleware(videoWatchingValidator),
19 asyncRetryTransactionMiddleware(userWatchVideo)
20)
21
22// ---------------------------------------------------------------------------
23
24export {
25 watchingRouter
26}
27
28// ---------------------------------------------------------------------------
29
30async function userWatchVideo (req: express.Request, res: express.Response) {
dae86118 31 const user = res.locals.oauth.token.User
6e46de09
C
32
33 const body: UserWatchingVideo = req.body
453e83ea 34 const { id: videoId } = res.locals.videoId
6e46de09
C
35
36 await UserVideoHistoryModel.upsert({
37 videoId,
38 userId: user.id,
39 currentTime: body.currentTime
40 })
41
2d53be02
RK
42 return res.type('json')
43 .status(HttpStatusCode.NO_CONTENT_204)
44 .end()
6e46de09 45}