From a2431b7dcbc72c05101dcdbe631ff84a823aeb51 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Nov 2017 17:30:46 +0100 Subject: Refractor validators --- server/helpers/custom-validators/video-channels.ts | 38 ++-------------------- 1 file changed, 2 insertions(+), 36 deletions(-) (limited to 'server/helpers/custom-validators/video-channels.ts') diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index 267d987fc..3de9f041b 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts @@ -1,21 +1,13 @@ -import * as Bluebird from 'bluebird' import * as express from 'express' import 'express-validator' import 'multer' import * as validator from 'validator' - import { CONSTRAINTS_FIELDS, database as db } from '../../initializers' import { VideoChannelInstance } from '../../models' -import { logger } from '../logger' -import { isActivityPubUrlValid } from './index' import { exists } from './misc' const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS -function isVideoChannelUrlValid (value: string) { - return isActivityPubUrlValid(value) -} - function isVideoChannelDescriptionValid (value: string) { return value === null || validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.DESCRIPTION) } @@ -24,31 +16,7 @@ function isVideoChannelNameValid (value: string) { return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME) } -function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) { - let promise: Bluebird - if (validator.isInt(id)) { - promise = db.VideoChannel.loadAndPopulateAccount(+id) - } else { // UUID - promise = db.VideoChannel.loadByUUIDAndPopulateAccount(id) - } - - promise.then(videoChannel => { - if (!videoChannel) { - return res.status(404) - .json({ error: 'Video channel not found' }) - .end() - } - - res.locals.videoChannel = videoChannel - callback() - }) - .catch(err => { - logger.error('Error in video channel request validator.', err) - return res.sendStatus(500) - }) -} - -async function isVideoChannelExistsPromise (id: string, res: express.Response) { +async function isVideoChannelExist (id: string, res: express.Response) { let videoChannel: VideoChannelInstance if (validator.isInt(id)) { videoChannel = await db.VideoChannel.loadAndPopulateAccount(+id) @@ -72,8 +40,6 @@ async function isVideoChannelExistsPromise (id: string, res: express.Response) { export { isVideoChannelDescriptionValid, - checkVideoChannelExists, isVideoChannelNameValid, - isVideoChannelExistsPromise, - isVideoChannelUrlValid + isVideoChannelExist } -- cgit v1.2.3