aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-blacklist.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-23 10:40:39 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit3e753302d8c911b59971c16a8018df0e1ab78465 (patch)
treeefce7ece3273589228c5c948ea6757b2bdf65429 /server/helpers/custom-validators/video-blacklist.ts
parenta8b666e9f1ed002230869606308749614390c82f (diff)
downloadPeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.tar.gz
PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.tar.zst
PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.zip
Refactor middleware helpers
Diffstat (limited to 'server/helpers/custom-validators/video-blacklist.ts')
-rw-r--r--server/helpers/custom-validators/video-blacklist.ts20
1 files changed, 1 insertions, 19 deletions
diff --git a/server/helpers/custom-validators/video-blacklist.ts b/server/helpers/custom-validators/video-blacklist.ts
index 3743f7023..9a44332ef 100644
--- a/server/helpers/custom-validators/video-blacklist.ts
+++ b/server/helpers/custom-validators/video-blacklist.ts
@@ -1,8 +1,6 @@
1import { Response } from 'express'
2import * as validator from 'validator' 1import * as validator from 'validator'
3import { exists } from './misc' 2import { exists } from './misc'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 3import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { VideoBlacklistModel } from '../../models/video/video-blacklist'
6import { VideoBlacklistType } from '../../../shared/models/videos' 4import { VideoBlacklistType } from '../../../shared/models/videos'
7 5
8const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST 6const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST
@@ -11,21 +9,6 @@ function isVideoBlacklistReasonValid (value: string) {
11 return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) 9 return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON)
12} 10}
13 11
14async function doesVideoBlacklistExist (videoId: number, res: Response) {
15 const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
16
17 if (videoBlacklist === null) {
18 res.status(404)
19 .json({ error: 'Blacklisted video not found' })
20 .end()
21
22 return false
23 }
24
25 res.locals.videoBlacklist = videoBlacklist
26 return true
27}
28
29function isVideoBlacklistTypeValid (value: any) { 12function isVideoBlacklistTypeValid (value: any) {
30 return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined 13 return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined
31} 14}
@@ -34,6 +17,5 @@ function isVideoBlacklistTypeValid (value: any) {
34 17
35export { 18export {
36 isVideoBlacklistReasonValid, 19 isVideoBlacklistReasonValid,
37 isVideoBlacklistTypeValid, 20 isVideoBlacklistTypeValid
38 doesVideoBlacklistExist
39} 21}