diff options
Diffstat (limited to 'server/middlewares/validators/videos/video-channels.ts')
-rw-r--r-- | server/middlewares/validators/videos/video-channels.ts | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts index 88f8b814d..d53c777fa 100644 --- a/server/middlewares/validators/videos/video-channels.ts +++ b/server/middlewares/validators/videos/video-channels.ts | |||
@@ -3,8 +3,9 @@ import { body, param, query } from 'express-validator' | |||
3 | import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' | 3 | import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' |
4 | import { CONFIG } from '@server/initializers/config' | 4 | import { CONFIG } from '@server/initializers/config' |
5 | import { MChannelAccountDefault } from '@server/types/models' | 5 | import { MChannelAccountDefault } from '@server/types/models' |
6 | import { VideosImportInChannelCreate } from '@shared/models' | ||
6 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | 7 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
7 | import { isBooleanValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' | 8 | import { isBooleanValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' |
8 | import { | 9 | import { |
9 | isVideoChannelDescriptionValid, | 10 | isVideoChannelDescriptionValid, |
10 | isVideoChannelDisplayNameValid, | 11 | isVideoChannelDisplayNameValid, |
@@ -15,6 +16,7 @@ import { logger } from '../../../helpers/logger' | |||
15 | import { ActorModel } from '../../../models/actor/actor' | 16 | import { ActorModel } from '../../../models/actor/actor' |
16 | import { VideoChannelModel } from '../../../models/video/video-channel' | 17 | import { VideoChannelModel } from '../../../models/video/video-channel' |
17 | import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared' | 18 | import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared' |
19 | import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs' | ||
18 | 20 | ||
19 | export const videoChannelsAddValidator = [ | 21 | export const videoChannelsAddValidator = [ |
20 | body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), | 22 | body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), |
@@ -145,11 +147,17 @@ export const videoChannelsListValidator = [ | |||
145 | export const videoChannelImportVideosValidator = [ | 147 | export const videoChannelImportVideosValidator = [ |
146 | body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), | 148 | body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), |
147 | 149 | ||
148 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 150 | body('videoChannelSyncId') |
151 | .optional() | ||
152 | .custom(isIdValid).withMessage('Should have a valid channel sync id'), | ||
153 | |||
154 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
149 | logger.debug('Checking videoChannelImport parameters', { parameters: req.body }) | 155 | logger.debug('Checking videoChannelImport parameters', { parameters: req.body }) |
150 | 156 | ||
151 | if (areValidationErrors(req, res)) return | 157 | if (areValidationErrors(req, res)) return |
152 | 158 | ||
159 | const body: VideosImportInChannelCreate = req.body | ||
160 | |||
153 | if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) { | 161 | if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) { |
154 | return res.fail({ | 162 | return res.fail({ |
155 | status: HttpStatusCode.FORBIDDEN_403, | 163 | status: HttpStatusCode.FORBIDDEN_403, |
@@ -157,6 +165,8 @@ export const videoChannelImportVideosValidator = [ | |||
157 | }) | 165 | }) |
158 | } | 166 | } |
159 | 167 | ||
168 | if (body.videoChannelSyncId && !await doesVideoChannelSyncIdExist(body.videoChannelSyncId, res)) return | ||
169 | |||
160 | return next() | 170 | return next() |
161 | } | 171 | } |
162 | ] | 172 | ] |