From 1e37d32f4bdc51045cd85d01ea1035fd53e0d32c Mon Sep 17 00:00:00 2001 From: Kimsible Date: Wed, 28 Apr 2021 17:33:55 +0200 Subject: Add server API actors route --- server/helpers/custom-validators/actor.ts | 10 ++++++++++ server/helpers/middlewares/video-channels.ts | 20 +++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 server/helpers/custom-validators/actor.ts (limited to 'server/helpers') diff --git a/server/helpers/custom-validators/actor.ts b/server/helpers/custom-validators/actor.ts new file mode 100644 index 000000000..ad129e080 --- /dev/null +++ b/server/helpers/custom-validators/actor.ts @@ -0,0 +1,10 @@ +import { isAccountNameValid } from './accounts' +import { isVideoChannelNameValid } from './video-channels' + +function isActorNameValid (value: string) { + return isAccountNameValid(value) || isVideoChannelNameValid(value) +} + +export { + isActorNameValid +} diff --git a/server/helpers/middlewares/video-channels.ts b/server/helpers/middlewares/video-channels.ts index e6eab65a2..e30ea90b3 100644 --- a/server/helpers/middlewares/video-channels.ts +++ b/server/helpers/middlewares/video-channels.ts @@ -3,22 +3,22 @@ import { MChannelBannerAccountDefault } from '@server/types/models' import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { VideoChannelModel } from '../../models/video/video-channel' -async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { +async function doesLocalVideoChannelNameExist (name: string, res: express.Response, sendNotFound = true) { const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) - return processVideoChannelExist(videoChannel, res) + return processVideoChannelExist(videoChannel, res, sendNotFound) } -async function doesVideoChannelIdExist (id: number, res: express.Response) { +async function doesVideoChannelIdExist (id: number, res: express.Response, sendNotFound = true) { const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) - return processVideoChannelExist(videoChannel, res) + return processVideoChannelExist(videoChannel, res, sendNotFound) } -async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { +async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response, sendNotFound = true) { const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) - return processVideoChannelExist(videoChannel, res) + return processVideoChannelExist(videoChannel, res, sendNotFound) } // --------------------------------------------------------------------------- @@ -29,10 +29,12 @@ export { doesVideoChannelNameWithHostExist } -function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) { +function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response, sendNotFound = true) { if (!videoChannel) { - res.status(HttpStatusCode.NOT_FOUND_404) - .json({ error: 'Video channel not found' }) + if (sendNotFound) { + res.status(HttpStatusCode.NOT_FOUND_404) + .json({ error: 'Video channel not found' }) + } return false } -- cgit v1.2.3