]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/videos/watching.ts
Guess if we need to generate the thumbnail for imports
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / watching.ts
CommitLineData
6e46de09
C
1import * as express from 'express'
2import { UserWatchingVideo } from '../../../../shared'
3import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares'
4import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
2d53be02 5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6e46de09
C
6
7const watchingRouter = express.Router()
8
9watchingRouter.put('/:videoId/watching',
10 authenticate,
11 asyncMiddleware(videoWatchingValidator),
12 asyncRetryTransactionMiddleware(userWatchVideo)
13)
14
15// ---------------------------------------------------------------------------
16
17export {
18 watchingRouter
19}
20
21// ---------------------------------------------------------------------------
22
23async function userWatchVideo (req: express.Request, res: express.Response) {
dae86118 24 const user = res.locals.oauth.token.User
6e46de09
C
25
26 const body: UserWatchingVideo = req.body
453e83ea 27 const { id: videoId } = res.locals.videoId
6e46de09
C
28
29 await UserVideoHistoryModel.upsert({
30 videoId,
31 userId: user.id,
32 currentTime: body.currentTime
33 })
34
2d53be02
RK
35 return res.type('json')
36 .status(HttpStatusCode.NO_CONTENT_204)
37 .end()
6e46de09 38}