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