aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-10-10 11:46:50 +0200
committerChocobozzz <me@florianbigard.com>2018-10-10 11:46:50 +0200
commit1cd3facc3de899ac864e979cd6d6a704b712cce3 (patch)
tree7a781918d6bf1426ec76cc18390922f65971a278 /server/middlewares/validators/videos
parentb014b6b9c7cb68d09c52b44046afe486c0736426 (diff)
downloadPeerTube-1cd3facc3de899ac864e979cd6d6a704b712cce3.tar.gz
PeerTube-1cd3facc3de899ac864e979cd6d6a704b712cce3.tar.zst
PeerTube-1cd3facc3de899ac864e979cd6d6a704b712cce3.zip
Add ability to list all local videos
Including private/unlisted for moderators/admins
Diffstat (limited to 'server/middlewares/validators/videos')
-rw-r--r--server/middlewares/validators/videos/videos.ts54
1 files changed, 52 insertions, 2 deletions
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index 1d0a64bb1..9dc52a134 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { body, param, ValidationChain } from 'express-validator/check' 3import { body, param, query, ValidationChain } from 'express-validator/check'
4import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' 4import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
5import { 5import {
6 isBooleanValid, 6 isBooleanValid,
@@ -8,6 +8,7 @@ import {
8 isIdOrUUIDValid, 8 isIdOrUUIDValid,
9 isIdValid, 9 isIdValid,
10 isUUIDValid, 10 isUUIDValid,
11 toArray,
11 toIntOrNull, 12 toIntOrNull,
12 toValueOrNull 13 toValueOrNull
13} from '../../../helpers/custom-validators/misc' 14} from '../../../helpers/custom-validators/misc'
@@ -19,6 +20,7 @@ import {
19 isVideoDescriptionValid, 20 isVideoDescriptionValid,
20 isVideoExist, 21 isVideoExist,
21 isVideoFile, 22 isVideoFile,
23 isVideoFilterValid,
22 isVideoImage, 24 isVideoImage,
23 isVideoLanguageValid, 25 isVideoLanguageValid,
24 isVideoLicenceValid, 26 isVideoLicenceValid,
@@ -42,6 +44,7 @@ import { VideoChangeOwnershipAccept } from '../../../../shared/models/videos/vid
42import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' 44import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership'
43import { AccountModel } from '../../../models/account/account' 45import { AccountModel } from '../../../models/account/account'
44import { VideoFetchType } from '../../../helpers/video' 46import { VideoFetchType } from '../../../helpers/video'
47import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
45 48
46const videosAddValidator = getCommonVideoAttributes().concat([ 49const videosAddValidator = getCommonVideoAttributes().concat([
47 body('videofile') 50 body('videofile')
@@ -359,6 +362,51 @@ function getCommonVideoAttributes () {
359 ] as (ValidationChain | express.Handler)[] 362 ] as (ValidationChain | express.Handler)[]
360} 363}
361 364
365const commonVideosFiltersValidator = [
366 query('categoryOneOf')
367 .optional()
368 .customSanitizer(toArray)
369 .custom(isNumberArray).withMessage('Should have a valid one of category array'),
370 query('licenceOneOf')
371 .optional()
372 .customSanitizer(toArray)
373 .custom(isNumberArray).withMessage('Should have a valid one of licence array'),
374 query('languageOneOf')
375 .optional()
376 .customSanitizer(toArray)
377 .custom(isStringArray).withMessage('Should have a valid one of language array'),
378 query('tagsOneOf')
379 .optional()
380 .customSanitizer(toArray)
381 .custom(isStringArray).withMessage('Should have a valid one of tags array'),
382 query('tagsAllOf')
383 .optional()
384 .customSanitizer(toArray)
385 .custom(isStringArray).withMessage('Should have a valid all of tags array'),
386 query('nsfw')
387 .optional()
388 .custom(isNSFWQueryValid).withMessage('Should have a valid NSFW attribute'),
389 query('filter')
390 .optional()
391 .custom(isVideoFilterValid).withMessage('Should have a valid filter attribute'),
392
393 (req: express.Request, res: express.Response, next: express.NextFunction) => {
394 logger.debug('Checking commons video filters query', { parameters: req.query })
395
396 if (areValidationErrors(req, res)) return
397
398 const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined
399 if (req.query.filter === 'all-local' && (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false)) {
400 res.status(401)
401 .json({ error: 'You are not allowed to see all local videos.' })
402
403 return
404 }
405
406 return next()
407 }
408]
409
362// --------------------------------------------------------------------------- 410// ---------------------------------------------------------------------------
363 411
364export { 412export {
@@ -375,7 +423,9 @@ export {
375 videosTerminateChangeOwnershipValidator, 423 videosTerminateChangeOwnershipValidator,
376 videosAcceptChangeOwnershipValidator, 424 videosAcceptChangeOwnershipValidator,
377 425
378 getCommonVideoAttributes 426 getCommonVideoAttributes,
427
428 commonVideosFiltersValidator
379} 429}
380 430
381// --------------------------------------------------------------------------- 431// ---------------------------------------------------------------------------