From 3e753302d8c911b59971c16a8018df0e1ab78465 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jul 2019 10:40:39 +0200 Subject: Refactor middleware helpers --- server/middlewares/validators/videos/video-abuses.ts | 3 +-- server/middlewares/validators/videos/video-blacklist.ts | 8 ++------ server/middlewares/validators/videos/video-captions.ts | 4 ++-- server/middlewares/validators/videos/video-channels.ts | 3 +-- server/middlewares/validators/videos/video-comments.ts | 2 +- server/middlewares/validators/videos/video-imports.ts | 3 ++- server/middlewares/validators/videos/video-playlists.ts | 5 ++--- server/middlewares/validators/videos/video-rates.ts | 3 ++- server/middlewares/validators/videos/video-shares.ts | 2 +- server/middlewares/validators/videos/video-watch.ts | 2 +- server/middlewares/validators/videos/videos.ts | 6 ++---- 11 files changed, 17 insertions(+), 24 deletions(-) (limited to 'server/middlewares/validators/videos') diff --git a/server/middlewares/validators/videos/video-abuses.ts b/server/middlewares/validators/videos/video-abuses.ts index d1910a992..e176e01af 100644 --- a/server/middlewares/validators/videos/video-abuses.ts +++ b/server/middlewares/validators/videos/video-abuses.ts @@ -2,15 +2,14 @@ import * as express from 'express' import 'express-validator' import { body, param } from 'express-validator/check' import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' -import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { areValidationErrors } from '../utils' import { - doesVideoAbuseExist, isVideoAbuseModerationCommentValid, isVideoAbuseReasonValid, isVideoAbuseStateValid } from '../../../helpers/custom-validators/video-abuses' +import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares' const videoAbuseReportValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts index 1d7ddb2e3..db59427c7 100644 --- a/server/middlewares/validators/videos/video-blacklist.ts +++ b/server/middlewares/validators/videos/video-blacklist.ts @@ -1,14 +1,10 @@ import * as express from 'express' import { body, param, query } from 'express-validator/check' import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' -import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { areValidationErrors } from '../utils' -import { - doesVideoBlacklistExist, - isVideoBlacklistReasonValid, - isVideoBlacklistTypeValid -} from '../../../helpers/custom-validators/video-blacklist' +import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' +import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares' const videosBlacklistRemoveValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), diff --git a/server/middlewares/validators/videos/video-captions.ts b/server/middlewares/validators/videos/video-captions.ts index d857ac3ec..f8739e27f 100644 --- a/server/middlewares/validators/videos/video-captions.ts +++ b/server/middlewares/validators/videos/video-captions.ts @@ -1,13 +1,13 @@ import * as express from 'express' import { areValidationErrors } from '../utils' -import { checkUserCanManageVideo, doesVideoExist } from '../../../helpers/custom-validators/videos' import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' import { body, param } from 'express-validator/check' import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' import { UserRight } from '../../../../shared' import { logger } from '../../../helpers/logger' -import { doesVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' +import { isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../../helpers/custom-validators/video-captions' import { cleanUpReqFiles } from '../../../helpers/express-utils' +import { checkUserCanManageVideo, doesVideoCaptionExist, doesVideoExist } from '../../../helpers/middlewares' const addVideoCaptionValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index f5a59cacb..c1065b898 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts @@ -2,8 +2,6 @@ import * as express from 'express' import { body, param } from 'express-validator/check' import { UserRight } from '../../../../shared' import { - doesLocalVideoChannelNameExist, - doesVideoChannelNameWithHostExist, isVideoChannelDescriptionValid, isVideoChannelNameValid, isVideoChannelSupportValid @@ -15,6 +13,7 @@ import { areValidationErrors } from '../utils' import { isActorPreferredUsernameValid } from '../../../helpers/custom-validators/activitypub/actor' import { ActorModel } from '../../../models/activitypub/actor' import { isBooleanValid } from '../../../helpers/custom-validators/misc' +import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../../../helpers/middlewares' const videoChannelsAddValidator = [ body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts index 6b8e2f318..1e3e42833 100644 --- a/server/middlewares/validators/videos/video-comments.ts +++ b/server/middlewares/validators/videos/video-comments.ts @@ -3,7 +3,6 @@ import { body, param } from 'express-validator/check' import { UserRight } from '../../../../shared' import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' -import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { UserModel } from '../../../models/account/user' import { VideoModel } from '../../../models/video/video' @@ -11,6 +10,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment' import { areValidationErrors } from '../utils' import { Hooks } from '../../../lib/plugins/hooks' import { isLocalVideoThreadAccepted, isLocalVideoCommentReplyAccepted, AcceptResult } from '../../../lib/moderation' +import { doesVideoExist } from '../../../helpers/middlewares' const listVideoCommentThreadsValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts index 452084a7c..8b0dd8960 100644 --- a/server/middlewares/validators/videos/video-imports.ts +++ b/server/middlewares/validators/videos/video-imports.ts @@ -6,9 +6,10 @@ import { areValidationErrors } from '../utils' import { getCommonVideoEditAttributes } from './videos' import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' import { cleanUpReqFiles } from '../../../helpers/express-utils' -import { doesVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' +import { isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' import { CONFIG } from '../../../initializers/config' import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' +import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares' const videoImportAddValidator = getCommonVideoEditAttributes().concat([ body('channelId') diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index 9c88dd291..638122a2e 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts @@ -4,11 +4,10 @@ import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../.. import { logger } from '../../../helpers/logger' import { UserModel } from '../../../models/account/user' import { areValidationErrors } from '../utils' -import { doesVideoExist, isVideoImage } from '../../../helpers/custom-validators/videos' +import { isVideoImage } from '../../../helpers/custom-validators/videos' import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' import { - doesVideoPlaylistExist, isVideoPlaylistDescriptionValid, isVideoPlaylistNameValid, isVideoPlaylistPrivacyValid, @@ -17,11 +16,11 @@ import { } from '../../../helpers/custom-validators/video-playlists' import { VideoPlaylistModel } from '../../../models/video/video-playlist' import { cleanUpReqFiles } from '../../../helpers/express-utils' -import { doesVideoChannelIdExist } from '../../../helpers/custom-validators/video-channels' import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-element' import { authenticatePromiseIfNeeded } from '../../oauth' import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' +import { doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist } from '../../../helpers/middlewares' const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ body('displayName') diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 204b4a78d..5bb3f4a51 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts @@ -3,12 +3,13 @@ import 'express-validator' import { body, param, query } from 'express-validator/check' import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' import { isRatingValid } from '../../../helpers/custom-validators/video-rates' -import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' +import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { areValidationErrors } from '../utils' import { AccountVideoRateModel } from '../../../models/account/account-video-rate' import { VideoRateType } from '../../../../shared/models/videos' import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' +import { doesVideoExist } from '../../../helpers/middlewares' const videoUpdateRateValidator = [ param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts index d5cbdb03e..6f4a1f3e0 100644 --- a/server/middlewares/validators/videos/video-shares.ts +++ b/server/middlewares/validators/videos/video-shares.ts @@ -2,10 +2,10 @@ import * as express from 'express' import 'express-validator' import { param } from 'express-validator/check' import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' -import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { logger } from '../../../helpers/logger' import { VideoShareModel } from '../../../models/video/video-share' import { areValidationErrors } from '../utils' +import { doesVideoExist } from '../../../helpers/middlewares' const videosShareValidator = [ param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts index a3a800d14..a0b530c75 100644 --- a/server/middlewares/validators/videos/video-watch.ts +++ b/server/middlewares/validators/videos/video-watch.ts @@ -1,9 +1,9 @@ import { body, param } from 'express-validator/check' import * as express from 'express' import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' -import { doesVideoExist } from '../../../helpers/custom-validators/videos' import { areValidationErrors } from '../utils' import { logger } from '../../../helpers/logger' +import { doesVideoExist } from '../../../helpers/middlewares' const videoWatchingValidator = [ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 5593ede64..8f5e5c95c 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -13,9 +13,6 @@ import { toValueOrNull } from '../../../helpers/custom-validators/misc' import { - checkUserCanManageVideo, - doesVideoChannelOfAccountExist, - doesVideoExist, isScheduleVideoUpdatePrivacyValid, isVideoCategoryValid, isVideoDescriptionValid, @@ -33,7 +30,7 @@ import { import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' import { logger } from '../../../helpers/logger' import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' -import { authenticate, authenticatePromiseIfNeeded } from '../../oauth' +import { authenticatePromiseIfNeeded } from '../../oauth' import { areValidationErrors } from '../utils' import { cleanUpReqFiles } from '../../../helpers/express-utils' import { VideoModel } from '../../../models/video/video' @@ -46,6 +43,7 @@ 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' const videosAddValidator = getCommonVideoEditAttributes().concat([ body('videofile') -- cgit v1.2.3