1 import * as express from 'express'
2 import { UserWatchingVideo } from '../../../../shared'
3 import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares'
4 import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
5 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7 const watchingRouter = express.Router()
9 watchingRouter.put('/:videoId/watching',
11 asyncMiddleware(videoWatchingValidator),
12 asyncRetryTransactionMiddleware(userWatchVideo)
15 // ---------------------------------------------------------------------------
21 // ---------------------------------------------------------------------------
23 async function userWatchVideo (req: express.Request, res: express.Response) {
24 const user = res.locals.oauth.token.User
26 const body: UserWatchingVideo = req.body
27 const { id: videoId } = res.locals.videoId
29 await UserVideoHistoryModel.upsert({
32 currentTime: body.currentTime
35 return res.type('json')
36 .status(HttpStatusCode.NO_CONTENT_204)