diff options
Diffstat (limited to 'server/middlewares/validators/videos/video-view.ts')
-rw-r--r-- | server/middlewares/validators/videos/video-view.ts | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/server/middlewares/validators/videos/video-view.ts b/server/middlewares/validators/videos/video-view.ts deleted file mode 100644 index a2f61f4ba..000000000 --- a/server/middlewares/validators/videos/video-view.ts +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { body, param } from 'express-validator' | ||
3 | import { isVideoTimeValid } from '@server/helpers/custom-validators/video-view' | ||
4 | import { getCachedVideoDuration } from '@server/lib/video' | ||
5 | import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' | ||
6 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | ||
7 | import { isIdValid, isIntOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' | ||
8 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' | ||
9 | |||
10 | const getVideoLocalViewerValidator = [ | ||
11 | param('localViewerId') | ||
12 | .custom(isIdValid), | ||
13 | |||
14 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
15 | if (areValidationErrors(req, res)) return | ||
16 | |||
17 | const localViewer = await LocalVideoViewerModel.loadFullById(+req.params.localViewerId) | ||
18 | if (!localViewer) { | ||
19 | return res.fail({ | ||
20 | status: HttpStatusCode.NOT_FOUND_404, | ||
21 | message: 'Local viewer not found' | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | res.locals.localViewerFull = localViewer | ||
26 | |||
27 | return next() | ||
28 | } | ||
29 | ] | ||
30 | |||
31 | const videoViewValidator = [ | ||
32 | isValidVideoIdParam('videoId'), | ||
33 | |||
34 | body('currentTime') | ||
35 | .customSanitizer(toIntOrNull) | ||
36 | .custom(isIntOrNull), | ||
37 | |||
38 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
39 | if (areValidationErrors(req, res)) return | ||
40 | if (!await doesVideoExist(req.params.videoId, res, 'only-immutable-attributes')) return | ||
41 | |||
42 | const video = res.locals.onlyImmutableVideo | ||
43 | const { duration } = await getCachedVideoDuration(video.id) | ||
44 | |||
45 | if (!isVideoTimeValid(req.body.currentTime, duration)) { | ||
46 | return res.fail({ | ||
47 | status: HttpStatusCode.BAD_REQUEST_400, | ||
48 | message: 'Current time is invalid' | ||
49 | }) | ||
50 | } | ||
51 | |||
52 | return next() | ||
53 | } | ||
54 | ] | ||
55 | |||
56 | // --------------------------------------------------------------------------- | ||
57 | |||
58 | export { | ||
59 | videoViewValidator, | ||
60 | getVideoLocalViewerValidator | ||
61 | } | ||