diff options
Diffstat (limited to 'server/middlewares/validators/videos/videos.ts')
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index b3ffb7007..26597cf7b 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -3,7 +3,6 @@ import { body, header, param, query, ValidationChain } from 'express-validator' | |||
3 | import { isTestInstance } from '@server/helpers/core-utils' | 3 | import { isTestInstance } from '@server/helpers/core-utils' |
4 | import { getResumableUploadPath } from '@server/helpers/upload' | 4 | import { getResumableUploadPath } from '@server/helpers/upload' |
5 | import { Redis } from '@server/lib/redis' | 5 | import { Redis } from '@server/lib/redis' |
6 | import { isAbleToUploadVideo } from '@server/lib/user' | ||
7 | import { getServerActor } from '@server/models/application/application' | 6 | import { getServerActor } from '@server/models/application/application' |
8 | import { ExpressPromiseHandler } from '@server/types/express-handler' | 7 | import { ExpressPromiseHandler } from '@server/types/express-handler' |
9 | import { MUserAccountId, MVideoFullLight } from '@server/types/models' | 8 | import { MUserAccountId, MVideoFullLight } from '@server/types/models' |
@@ -13,7 +12,7 @@ import { | |||
13 | exists, | 12 | exists, |
14 | isBooleanValid, | 13 | isBooleanValid, |
15 | isDateValid, | 14 | isDateValid, |
16 | isFileFieldValid, | 15 | isFileValid, |
17 | isIdValid, | 16 | isIdValid, |
18 | isUUIDValid, | 17 | isUUIDValid, |
19 | toArray, | 18 | toArray, |
@@ -23,24 +22,24 @@ import { | |||
23 | } from '../../../helpers/custom-validators/misc' | 22 | } from '../../../helpers/custom-validators/misc' |
24 | import { isBooleanBothQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' | 23 | import { isBooleanBothQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' |
25 | import { | 24 | import { |
25 | areVideoTagsValid, | ||
26 | isScheduleVideoUpdatePrivacyValid, | 26 | isScheduleVideoUpdatePrivacyValid, |
27 | isVideoCategoryValid, | 27 | isVideoCategoryValid, |
28 | isVideoDescriptionValid, | 28 | isVideoDescriptionValid, |
29 | isVideoFileMimeTypeValid, | 29 | isVideoFileMimeTypeValid, |
30 | isVideoFileSizeValid, | 30 | isVideoFileSizeValid, |
31 | isVideoFilterValid, | 31 | isVideoFilterValid, |
32 | isVideoImage, | 32 | isVideoImageValid, |
33 | isVideoIncludeValid, | 33 | isVideoIncludeValid, |
34 | isVideoLanguageValid, | 34 | isVideoLanguageValid, |
35 | isVideoLicenceValid, | 35 | isVideoLicenceValid, |
36 | isVideoNameValid, | 36 | isVideoNameValid, |
37 | isVideoOriginallyPublishedAtValid, | 37 | isVideoOriginallyPublishedAtValid, |
38 | isVideoPrivacyValid, | 38 | isVideoPrivacyValid, |
39 | isVideoSupportValid, | 39 | isVideoSupportValid |
40 | isVideoTagsValid | ||
41 | } from '../../../helpers/custom-validators/videos' | 40 | } from '../../../helpers/custom-validators/videos' |
42 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 41 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
43 | import { getDurationFromVideoFile } from '../../../helpers/ffprobe-utils' | 42 | import { getVideoStreamDuration } from '../../../helpers/ffmpeg' |
44 | import { logger } from '../../../helpers/logger' | 43 | import { logger } from '../../../helpers/logger' |
45 | import { deleteFileAndCatch } from '../../../helpers/utils' | 44 | import { deleteFileAndCatch } from '../../../helpers/utils' |
46 | import { getVideoWithAttributes } from '../../../helpers/video' | 45 | import { getVideoWithAttributes } from '../../../helpers/video' |
@@ -53,6 +52,7 @@ import { | |||
53 | areValidationErrors, | 52 | areValidationErrors, |
54 | checkCanSeePrivateVideo, | 53 | checkCanSeePrivateVideo, |
55 | checkUserCanManageVideo, | 54 | checkUserCanManageVideo, |
55 | checkUserQuota, | ||
56 | doesVideoChannelOfAccountExist, | 56 | doesVideoChannelOfAccountExist, |
57 | doesVideoExist, | 57 | doesVideoExist, |
58 | doesVideoFileOfVideoExist, | 58 | doesVideoFileOfVideoExist, |
@@ -61,7 +61,7 @@ import { | |||
61 | 61 | ||
62 | const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([ | 62 | const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([ |
63 | body('videofile') | 63 | body('videofile') |
64 | .custom((value, { req }) => isFileFieldValid(req.files, 'videofile')) | 64 | .custom((_, { req }) => isFileValid({ files: req.files, field: 'videofile', mimeTypeRegex: null, maxSize: null })) |
65 | .withMessage('Should have a file'), | 65 | .withMessage('Should have a file'), |
66 | body('name') | 66 | body('name') |
67 | .trim() | 67 | .trim() |
@@ -299,12 +299,11 @@ const videosCustomGetValidator = ( | |||
299 | 299 | ||
300 | // Video private or blacklisted | 300 | // Video private or blacklisted |
301 | if (video.requiresAuth()) { | 301 | if (video.requiresAuth()) { |
302 | if (await checkCanSeePrivateVideo(req, res, video, authenticateInQuery)) return next() | 302 | if (await checkCanSeePrivateVideo(req, res, video, authenticateInQuery)) { |
303 | return next() | ||
304 | } | ||
303 | 305 | ||
304 | return res.fail({ | 306 | return |
305 | status: HttpStatusCode.FORBIDDEN_403, | ||
306 | message: 'Cannot get this private/internal or blocklisted video' | ||
307 | }) | ||
308 | } | 307 | } |
309 | 308 | ||
310 | // Video is public, anyone can access it | 309 | // Video is public, anyone can access it |
@@ -375,12 +374,12 @@ const videosOverviewValidator = [ | |||
375 | function getCommonVideoEditAttributes () { | 374 | function getCommonVideoEditAttributes () { |
376 | return [ | 375 | return [ |
377 | body('thumbnailfile') | 376 | body('thumbnailfile') |
378 | .custom((value, { req }) => isVideoImage(req.files, 'thumbnailfile')).withMessage( | 377 | .custom((value, { req }) => isVideoImageValid(req.files, 'thumbnailfile')).withMessage( |
379 | 'This thumbnail file is not supported or too large. Please, make sure it is of the following type: ' + | 378 | 'This thumbnail file is not supported or too large. Please, make sure it is of the following type: ' + |
380 | CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ') | 379 | CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ') |
381 | ), | 380 | ), |
382 | body('previewfile') | 381 | body('previewfile') |
383 | .custom((value, { req }) => isVideoImage(req.files, 'previewfile')).withMessage( | 382 | .custom((value, { req }) => isVideoImageValid(req.files, 'previewfile')).withMessage( |
384 | 'This preview file is not supported or too large. Please, make sure it is of the following type: ' + | 383 | 'This preview file is not supported or too large. Please, make sure it is of the following type: ' + |
385 | CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ') | 384 | CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ') |
386 | ), | 385 | ), |
@@ -420,7 +419,7 @@ function getCommonVideoEditAttributes () { | |||
420 | body('tags') | 419 | body('tags') |
421 | .optional() | 420 | .optional() |
422 | .customSanitizer(toValueOrNull) | 421 | .customSanitizer(toValueOrNull) |
423 | .custom(isVideoTagsValid) | 422 | .custom(areVideoTagsValid) |
424 | .withMessage( | 423 | .withMessage( |
425 | `Should have an array of up to ${CONSTRAINTS_FIELDS.VIDEOS.TAGS.max} tags between ` + | 424 | `Should have an array of up to ${CONSTRAINTS_FIELDS.VIDEOS.TAGS.max} tags between ` + |
426 | `${CONSTRAINTS_FIELDS.VIDEOS.TAG.min} and ${CONSTRAINTS_FIELDS.VIDEOS.TAG.max} characters each` | 425 | `${CONSTRAINTS_FIELDS.VIDEOS.TAG.min} and ${CONSTRAINTS_FIELDS.VIDEOS.TAG.max} characters each` |
@@ -612,14 +611,7 @@ async function commonVideoChecksPass (parameters: { | |||
612 | return false | 611 | return false |
613 | } | 612 | } |
614 | 613 | ||
615 | if (await isAbleToUploadVideo(user.id, videoFileSize) === false) { | 614 | if (await checkUserQuota(user, videoFileSize, res) === false) return false |
616 | res.fail({ | ||
617 | status: HttpStatusCode.PAYLOAD_TOO_LARGE_413, | ||
618 | message: 'The user video quota is exceeded with this video.', | ||
619 | type: ServerErrorCode.QUOTA_REACHED | ||
620 | }) | ||
621 | return false | ||
622 | } | ||
623 | 615 | ||
624 | return true | 616 | return true |
625 | } | 617 | } |
@@ -654,7 +646,7 @@ export async function isVideoAccepted ( | |||
654 | } | 646 | } |
655 | 647 | ||
656 | async function addDurationToVideo (videoFile: { path: string, duration?: number }) { | 648 | async function addDurationToVideo (videoFile: { path: string, duration?: number }) { |
657 | const duration: number = await getDurationFromVideoFile(videoFile.path) | 649 | const duration: number = await getVideoStreamDuration(videoFile.path) |
658 | 650 | ||
659 | if (isNaN(duration)) throw new Error(`Couldn't get video duration`) | 651 | if (isNaN(duration)) throw new Error(`Couldn't get video duration`) |
660 | 652 | ||