diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 14:44:51 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | 4e50b6a1c9a3eb261e04ede73241648e6edf21d6 (patch) | |
tree | e1c6c121d561ffc1cf2996daec03a1e7f27f0a25 /server/helpers/custom-validators/video-channels.ts | |
parent | 74bb2cb8348d6794ed3a0e2ec94c8c9abdde82cf (diff) | |
download | PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.gz PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.zst PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.zip |
Add shares forward and collection on videos/video channels
Diffstat (limited to 'server/helpers/custom-validators/video-channels.ts')
-rw-r--r-- | server/helpers/custom-validators/video-channels.ts | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index 5de01f74b..267d987fc 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts | |||
@@ -1,14 +1,14 @@ | |||
1 | import * as Promise from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import * as validator from 'validator' | ||
3 | import * as express from 'express' | 2 | import * as express from 'express' |
4 | import 'express-validator' | 3 | import 'express-validator' |
5 | import 'multer' | 4 | import 'multer' |
5 | import * as validator from 'validator' | ||
6 | 6 | ||
7 | import { database as db, CONSTRAINTS_FIELDS } from '../../initializers' | 7 | import { CONSTRAINTS_FIELDS, database as db } from '../../initializers' |
8 | import { VideoChannelInstance } from '../../models' | 8 | import { VideoChannelInstance } from '../../models' |
9 | import { logger } from '../logger' | 9 | import { logger } from '../logger' |
10 | import { exists } from './misc' | ||
11 | import { isActivityPubUrlValid } from './index' | 10 | import { isActivityPubUrlValid } from './index' |
11 | import { exists } from './misc' | ||
12 | 12 | ||
13 | const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS | 13 | const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS |
14 | 14 | ||
@@ -25,7 +25,7 @@ function isVideoChannelNameValid (value: string) { | |||
25 | } | 25 | } |
26 | 26 | ||
27 | function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) { | 27 | function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) { |
28 | let promise: Promise<VideoChannelInstance> | 28 | let promise: Bluebird<VideoChannelInstance> |
29 | if (validator.isInt(id)) { | 29 | if (validator.isInt(id)) { |
30 | promise = db.VideoChannel.loadAndPopulateAccount(+id) | 30 | promise = db.VideoChannel.loadAndPopulateAccount(+id) |
31 | } else { // UUID | 31 | } else { // UUID |
@@ -48,11 +48,32 @@ function checkVideoChannelExists (id: string, res: express.Response, callback: ( | |||
48 | }) | 48 | }) |
49 | } | 49 | } |
50 | 50 | ||
51 | async function isVideoChannelExistsPromise (id: string, res: express.Response) { | ||
52 | let videoChannel: VideoChannelInstance | ||
53 | if (validator.isInt(id)) { | ||
54 | videoChannel = await db.VideoChannel.loadAndPopulateAccount(+id) | ||
55 | } else { // UUID | ||
56 | videoChannel = await db.VideoChannel.loadByUUIDAndPopulateAccount(id) | ||
57 | } | ||
58 | |||
59 | if (!videoChannel) { | ||
60 | res.status(404) | ||
61 | .json({ error: 'Video channel not found' }) | ||
62 | .end() | ||
63 | |||
64 | return false | ||
65 | } | ||
66 | |||
67 | res.locals.videoChannel = videoChannel | ||
68 | return true | ||
69 | } | ||
70 | |||
51 | // --------------------------------------------------------------------------- | 71 | // --------------------------------------------------------------------------- |
52 | 72 | ||
53 | export { | 73 | export { |
54 | isVideoChannelDescriptionValid, | 74 | isVideoChannelDescriptionValid, |
55 | isVideoChannelNameValid, | ||
56 | checkVideoChannelExists, | 75 | checkVideoChannelExists, |
76 | isVideoChannelNameValid, | ||
77 | isVideoChannelExistsPromise, | ||
57 | isVideoChannelUrlValid | 78 | isVideoChannelUrlValid |
58 | } | 79 | } |