]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/videos/watching.ts
Process video torrents in order
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / watching.ts
CommitLineData
41fb13c3 1import express from 'express'
d17c7b4e 2import { HttpStatusCode, UserWatchingVideo } from '@shared/models'
c756bae0
RK
3import {
4 asyncMiddleware,
5 asyncRetryTransactionMiddleware,
6 authenticate,
7 openapiOperationDoc,
8 videoWatchingValidator
9} from '../../../middlewares'
7d9ba5c0 10import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
6e46de09
C
11
12const watchingRouter = express.Router()
13
14watchingRouter.put('/:videoId/watching',
c756bae0 15 openapiOperationDoc({ operationId: 'setProgress' }),
6e46de09
C
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) {
dae86118 30 const user = res.locals.oauth.token.User
6e46de09
C
31
32 const body: UserWatchingVideo = req.body
453e83ea 33 const { id: videoId } = res.locals.videoId
6e46de09
C
34
35 await UserVideoHistoryModel.upsert({
36 videoId,
37 userId: user.id,
38 currentTime: body.currentTime
39 })
40
2d53be02
RK
41 return res.type('json')
42 .status(HttpStatusCode.NO_CONTENT_204)
43 .end()
6e46de09 44}