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,
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'),
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,
})
}
+ if (body.videoChannelSyncId && !await doesVideoChannelSyncIdExist(body.videoChannelSyncId, res)) return
+
return next()
}
]