aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos/video-view.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/videos/video-view.ts')
-rw-r--r--server/middlewares/validators/videos/video-view.ts61
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 @@
1import express from 'express'
2import { body, param } from 'express-validator'
3import { isVideoTimeValid } from '@server/helpers/custom-validators/video-view'
4import { getCachedVideoDuration } from '@server/lib/video'
5import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer'
6import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
7import { isIdValid, isIntOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
8import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
9
10const 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
31const 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
58export {
59 videoViewValidator,
60 getVideoLocalViewerValidator
61}