]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/videos/watching.ts
Merge branch 'feature/strong-model-types' into develop
[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'
6e46de09
C
5
6const watchingRouter = express.Router()
7
8watchingRouter.put('/:videoId/watching',
9 authenticate,
10 asyncMiddleware(videoWatchingValidator),
11 asyncRetryTransactionMiddleware(userWatchVideo)
12)
13
14// ---------------------------------------------------------------------------
15
16export {
17 watchingRouter
18}
19
20// ---------------------------------------------------------------------------
21
22async function userWatchVideo (req: express.Request, res: express.Response) {
dae86118 23 const user = res.locals.oauth.token.User
6e46de09
C
24
25 const body: UserWatchingVideo = req.body
453e83ea 26 const { id: videoId } = res.locals.videoId
6e46de09
C
27
28 await UserVideoHistoryModel.upsert({
29 videoId,
30 userId: user.id,
31 currentTime: body.currentTime
32 })
33
34 return res.type('json').status(204).end()
35}