diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-13 16:57:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-14 09:27:18 +0200 |
commit | 26b7305a232e547709f433a6edf700bf495935d8 (patch) | |
tree | b5676090c61df72f864735bcc881d5ee256cffbd /server/helpers/custom-validators | |
parent | efc9e8450a8bbeeef9cd18e3ad6037abc0f815c3 (diff) | |
download | PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.gz PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.zst PeerTube-26b7305a232e547709f433a6edf700bf495935d8.zip |
Add blacklist reason field
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/video-blacklist.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/video-blacklist.ts b/server/helpers/custom-validators/video-blacklist.ts new file mode 100644 index 000000000..b36b08d8b --- /dev/null +++ b/server/helpers/custom-validators/video-blacklist.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import { Response } from 'express' | ||
2 | import * as validator from 'validator' | ||
3 | import { CONSTRAINTS_FIELDS } from '../../initializers' | ||
4 | import { VideoBlacklistModel } from '../../models/video/video-blacklist' | ||
5 | |||
6 | const VIDEO_BLACKLIST_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_BLACKLIST | ||
7 | |||
8 | function isVideoBlacklistReasonValid (value: string) { | ||
9 | return value === null || validator.isLength(value, VIDEO_BLACKLIST_CONSTRAINTS_FIELDS.REASON) | ||
10 | } | ||
11 | |||
12 | async function isVideoBlacklistExist (videoId: number, res: Response) { | ||
13 | const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) | ||
14 | |||
15 | if (videoBlacklist === null) { | ||
16 | res.status(404) | ||
17 | .json({ error: 'Blacklisted video not found' }) | ||
18 | .end() | ||
19 | |||
20 | return false | ||
21 | } | ||
22 | |||
23 | res.locals.videoBlacklist = videoBlacklist | ||
24 | return true | ||
25 | } | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | export { | ||
30 | isVideoBlacklistReasonValid, | ||
31 | isVideoBlacklistExist | ||
32 | } | ||