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'
6 const watchingRouter = express.Router()
8 watchingRouter.put('/:videoId/watching',
10 asyncMiddleware(videoWatchingValidator),
11 asyncRetryTransactionMiddleware(userWatchVideo)
14 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
22 async function userWatchVideo (req: express.Request, res: express.Response) {
23 const user = res.locals.oauth.token.User
25 const body: UserWatchingVideo = req.body
26 const { id: videoId } = res.locals.video as { id: number }
28 await UserVideoHistoryModel.upsert({
31 currentTime: body.currentTime
34 return res.type('json').status(204).end()