From 601527d7953a83d6ad08dbb2ed8ac02851beaf1e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 1 Oct 2018 15:18:07 +0200 Subject: Check video channel name is unique on our instance --- server/middlewares/activitypub.ts | 2 +- server/middlewares/validators/video-channels.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 12d5c22c5..d7f59be8c 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts @@ -18,7 +18,7 @@ async function checkSignature (req: Request, res: Response, next: NextFunction) try { actor = await getOrCreateActorAndServerAndModel(creator) } catch (err) { - logger.error('Cannot create remote actor and check signature.', { err }) + logger.warn('Cannot create remote actor %s and check signature.', creator, { err }) return res.sendStatus(403) } diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 79587b028..56a347b39 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts @@ -14,6 +14,7 @@ import { UserModel } from '../../models/account/user' import { VideoChannelModel } from '../../models/video/video-channel' import { areValidationErrors } from './utils' import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' +import { ActorModel } from '../../models/activitypub/actor' const listVideoAccountChannelsValidator = [ param('accountName').exists().withMessage('Should have a valid account name'), @@ -34,11 +35,19 @@ const videoChannelsAddValidator = [ body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), - (req: express.Request, res: express.Response, next: express.NextFunction) => { + async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return + const actor = await ActorModel.loadLocalByName(req.body.name) + if (actor) { + res.status(409) + .send({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' }) + .end() + return false + } + return next() } ] -- cgit v1.2.3