X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fvideos%2Fvideo-channels.ts;h=d53c777fac8ac7a20f59f602de31c943d57025c8;hb=a3b472a12ec6e57dbe2f650419f8064864686eab;hp=88f8b814d8479f548da5ae8a50cf45753a61b68e;hpb=0567049a9819d67070aa6d548a75a7e632a4aaa4;p=github%2FChocobozzz%2FPeerTube.git 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' import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' import { CONFIG } from '@server/initializers/config' import { MChannelAccountDefault } from '@server/types/models' +import { VideosImportInChannelCreate } from '@shared/models' import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' -import { isBooleanValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' +import { isBooleanValid, isIdValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc' import { isVideoChannelDescriptionValid, isVideoChannelDisplayNameValid, @@ -15,6 +16,7 @@ import { logger } from '../../../helpers/logger' import { ActorModel } from '../../../models/actor/actor' import { VideoChannelModel } from '../../../models/video/video-channel' import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist } from '../shared' +import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs' export const videoChannelsAddValidator = [ body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), @@ -145,11 +147,17 @@ export const videoChannelsListValidator = [ export const videoChannelImportVideosValidator = [ body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), - (req: express.Request, res: express.Response, next: express.NextFunction) => { + body('videoChannelSyncId') + .optional() + .custom(isIdValid).withMessage('Should have a valid channel sync id'), + + async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoChannelImport parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return + const body: VideosImportInChannelCreate = req.body + if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) { return res.fail({ status: HttpStatusCode.FORBIDDEN_403, @@ -157,6 +165,8 @@ export const videoChannelImportVideosValidator = [ }) } + if (body.videoChannelSyncId && !await doesVideoChannelSyncIdExist(body.videoChannelSyncId, res)) return + return next() } ]