aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/videos/video-channels.ts')
-rw-r--r--server/middlewares/validators/videos/video-channels.ts14
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'
3import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' 3import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
4import { CONFIG } from '@server/initializers/config' 4import { CONFIG } from '@server/initializers/config'
5import { MChannelAccountDefault } from '@server/types/models' 5import { MChannelAccountDefault } from '@server/types/models'
6import { VideosImportInChannelCreate } from '@shared/models'
6import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' 7import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
7import { isBooleanValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' 8import { isBooleanValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'
8import { 9import {
9 isVideoChannelDescriptionValid, 10 isVideoChannelDescriptionValid,
10 isVideoChannelDisplayNameValid, 11 isVideoChannelDisplayNameValid,
@@ -15,6 +16,7 @@ import { logger } from '../../../helpers/logger'
15import { ActorModel } from '../../../models/actor/actor' 16import { ActorModel } from '../../../models/actor/actor'
16import { VideoChannelModel } from '../../../models/video/video-channel' 17import { VideoChannelModel } from '../../../models/video/video-channel'
17import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared' 18import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared'
19import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs'
18 20
19export const videoChannelsAddValidator = [ 21export 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 = [
145export const videoChannelImportVideosValidator = [ 147export 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]