]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/video-blacklist.ts
preserve original variable names server-side
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / video-blacklist.ts
index b36b08d8bd275672481b1dee60349949f08e0044..17cb3b00b6b313f62474cb012ddeda3cd290cbea 100644 (file)
@@ -1,7 +1,7 @@
-import { Response } from 'express'
-import * as validator from 'validator'
-import { CONSTRAINTS_FIELDS } from '../../initializers'
-import { VideoBlacklistModel } from '../../models/video/video-blacklist'
+import validator from 'validator'
+import { exists } from './misc'
+import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
+import { VideoBlacklistType } from '../../../shared/models/videos'
 
 const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST
 
@@ -9,24 +9,13 @@ function isVideoBlacklistReasonValid (value: string) {
   return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON)
 }
 
-async function isVideoBlacklistExist (videoId: number, res: Response) {
-  const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
-
-  if (videoBlacklist === null) {
-    res.status(404)
-       .json({ error: 'Blacklisted video not found' })
-       .end()
-
-    return false
-  }
-
-  res.locals.videoBlacklist = videoBlacklist
-  return true
+function isVideoBlacklistTypeValid (value: any) {
+  return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined
 }
 
 // ---------------------------------------------------------------------------
 
 export {
   isVideoBlacklistReasonValid,
-  isVideoBlacklistExist
+  isVideoBlacklistTypeValid
 }