]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
d17c7b4e | 2 | import { HttpStatusCode, UserWatchingVideo } from '@shared/models' |
c756bae0 RK |
3 | import { |
4 | asyncMiddleware, | |
5 | asyncRetryTransactionMiddleware, | |
6 | authenticate, | |
7 | openapiOperationDoc, | |
8 | videoWatchingValidator | |
9 | } from '../../../middlewares' | |
7d9ba5c0 | 10 | import { UserVideoHistoryModel } from '../../../models/user/user-video-history' |
6e46de09 C |
11 | |
12 | const watchingRouter = express.Router() | |
13 | ||
14 | watchingRouter.put('/:videoId/watching', | |
c756bae0 | 15 | openapiOperationDoc({ operationId: 'setProgress' }), |
6e46de09 C |
16 | authenticate, |
17 | asyncMiddleware(videoWatchingValidator), | |
18 | asyncRetryTransactionMiddleware(userWatchVideo) | |
19 | ) | |
20 | ||
21 | // --------------------------------------------------------------------------- | |
22 | ||
23 | export { | |
24 | watchingRouter | |
25 | } | |
26 | ||
27 | // --------------------------------------------------------------------------- | |
28 | ||
29 | async function userWatchVideo (req: express.Request, res: express.Response) { | |
dae86118 | 30 | const user = res.locals.oauth.token.User |
6e46de09 C |
31 | |
32 | const body: UserWatchingVideo = req.body | |
453e83ea | 33 | const { id: videoId } = res.locals.videoId |
6e46de09 C |
34 | |
35 | await UserVideoHistoryModel.upsert({ | |
36 | videoId, | |
37 | userId: user.id, | |
38 | currentTime: body.currentTime | |
39 | }) | |
40 | ||
2d53be02 RK |
41 | return res.type('json') |
42 | .status(HttpStatusCode.NO_CONTENT_204) | |
43 | .end() | |
6e46de09 | 44 | } |