X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideo-blacklist.ts;h=3743f70233cb2507036efbc13adc50f1dbcbbaf4;hb=1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a;hp=b36b08d8bd275672481b1dee60349949f08e0044;hpb=26b7305a232e547709f433a6edf700bf495935d8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/video-blacklist.ts b/server/helpers/custom-validators/video-blacklist.ts index b36b08d8b..3743f7023 100644 --- a/server/helpers/custom-validators/video-blacklist.ts +++ b/server/helpers/custom-validators/video-blacklist.ts @@ -1,7 +1,9 @@ import { Response } from 'express' import * as validator from 'validator' -import { CONSTRAINTS_FIELDS } from '../../initializers' +import { exists } from './misc' +import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { VideoBlacklistModel } from '../../models/video/video-blacklist' +import { VideoBlacklistType } from '../../../shared/models/videos' const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST @@ -9,7 +11,7 @@ function isVideoBlacklistReasonValid (value: string) { return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) } -async function isVideoBlacklistExist (videoId: number, res: Response) { +async function doesVideoBlacklistExist (videoId: number, res: Response) { const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) if (videoBlacklist === null) { @@ -24,9 +26,14 @@ async function isVideoBlacklistExist (videoId: number, res: Response) { return true } +function isVideoBlacklistTypeValid (value: any) { + return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined +} + // --------------------------------------------------------------------------- export { isVideoBlacklistReasonValid, - isVideoBlacklistExist + isVideoBlacklistTypeValid, + doesVideoBlacklistExist }