} from '../../../helpers/custom-validators/videos'
import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils'
import { logger } from '../../../helpers/logger'
-import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
+import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants'
import { authenticatePromiseIfNeeded } from '../../oauth'
import { areValidationErrors } from '../utils'
import { cleanUpReqFiles } from '../../../helpers/express-utils'
import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/video-change-ownership-accept.model'
import { AccountModel } from '../../../models/account/account'
import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
-import { getServerActor } from '../../../helpers/utils'
import { CONFIG } from '../../../initializers/config'
import { isLocalVideoAccepted } from '../../../lib/moderation'
import { Hooks } from '../../../lib/plugins/hooks'
-import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '../../../helpers/middlewares'
-import { MVideoFullLight } from '@server/typings/models'
+import {
+ checkUserCanManageVideo,
+ doesVideoChannelOfAccountExist,
+ doesVideoExist,
+ doesVideoFileOfVideoExist
+} from '../../../helpers/middlewares'
+import { MVideoFullLight } from '@server/types/models'
import { getVideoWithAttributes } from '../../../helpers/video'
+import { getServerActor } from '@server/models/application/application'
const videosAddValidator = getCommonVideoEditAttributes().concat([
body('videofile')
})
}
-const videosCustomGetValidator = (fetchType: 'all' | 'only-video' | 'only-video-with-rights', authenticateInQuery = false) => {
+const videosCustomGetValidator = (
+ fetchType: 'all' | 'only-video' | 'only-video-with-rights' | 'only-immutable-attributes',
+ authenticateInQuery = false
+) => {
return [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.id, res, fetchType)) return
+ // Controllers does not need to check video rights
+ if (fetchType === 'only-immutable-attributes') return next()
+
const video = getVideoWithAttributes(res)
const videoAll = video as MVideoFullLight
const videosGetValidator = videosCustomGetValidator('all')
const videosDownloadValidator = videosCustomGetValidator('all', true)
+const videoFileMetadataGetValidator = getCommonVideoEditAttributes().concat([
+ param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
+ param('videoFileId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid videoFileId'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking videoFileMetadataGet parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+ if (!await doesVideoFileOfVideoExist(+req.params.videoFileId, req.params.id, res)) return
+
+ return next()
+ }
+])
+
const videosRemoveValidator = [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
}
]
+const videosOverviewValidator = [
+ query('page')
+ .optional()
+ .isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT })
+ .withMessage('Should have a valid pagination'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ if (areValidationErrors(req, res)) return
+
+ return next()
+ }
+]
+
function getCommonVideoEditAttributes () {
return [
body('thumbnailfile')
videosAddValidator,
videosUpdateValidator,
videosGetValidator,
+ videoFileMetadataGetValidator,
videosDownloadValidator,
checkVideoFollowConstraints,
videosCustomGetValidator,
getCommonVideoEditAttributes,
- commonVideosFiltersValidator
+ commonVideosFiltersValidator,
+
+ videosOverviewValidator
}
// ---------------------------------------------------------------------------