1 import express from 'express'
2 import { UserWatchingVideo } from '../../../../shared'
3 import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
6 asyncRetryTransactionMiddleware,
10 } from '../../../middlewares'
11 import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
13 const watchingRouter = express.Router()
15 watchingRouter.put('/:videoId/watching',
16 openapiOperationDoc({ operationId: 'setProgress' }),
18 asyncMiddleware(videoWatchingValidator),
19 asyncRetryTransactionMiddleware(userWatchVideo)
22 // ---------------------------------------------------------------------------
28 // ---------------------------------------------------------------------------
30 async function userWatchVideo (req: express.Request, res: express.Response) {
31 const user = res.locals.oauth.token.User
33 const body: UserWatchingVideo = req.body
34 const { id: videoId } = res.locals.videoId
36 await UserVideoHistoryModel.upsert({
39 currentTime: body.currentTime
42 return res.type('json')
43 .status(HttpStatusCode.NO_CONTENT_204)