]>
Commit | Line | Data |
---|---|---|
6e46de09 C |
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' | |
6e46de09 C |
5 | |
6 | const watchingRouter = express.Router() | |
7 | ||
8 | watchingRouter.put('/:videoId/watching', | |
9 | authenticate, | |
10 | asyncMiddleware(videoWatchingValidator), | |
11 | asyncRetryTransactionMiddleware(userWatchVideo) | |
12 | ) | |
13 | ||
14 | // --------------------------------------------------------------------------- | |
15 | ||
16 | export { | |
17 | watchingRouter | |
18 | } | |
19 | ||
20 | // --------------------------------------------------------------------------- | |
21 | ||
22 | async 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 | |
26 | const { id: videoId } = res.locals.video as { id: number } | |
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 | } |