diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/index.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-accounts.ts | 45 | ||||
-rw-r--r-- | server/helpers/custom-validators/video-channels.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 4 |
4 files changed, 50 insertions, 4 deletions
diff --git a/server/helpers/custom-validators/index.ts b/server/helpers/custom-validators/index.ts index 58a40249b..33922b8fe 100644 --- a/server/helpers/custom-validators/index.ts +++ b/server/helpers/custom-validators/index.ts | |||
@@ -3,5 +3,6 @@ export * from './misc' | |||
3 | export * from './pods' | 3 | export * from './pods' |
4 | export * from './pods' | 4 | export * from './pods' |
5 | export * from './users' | 5 | export * from './users' |
6 | export * from './video-accounts' | ||
6 | export * from './video-channels' | 7 | export * from './video-channels' |
7 | export * from './videos' | 8 | export * from './videos' |
diff --git a/server/helpers/custom-validators/video-accounts.ts b/server/helpers/custom-validators/video-accounts.ts new file mode 100644 index 000000000..3f3e9edd1 --- /dev/null +++ b/server/helpers/custom-validators/video-accounts.ts | |||
@@ -0,0 +1,45 @@ | |||
1 | import * as Promise from 'bluebird' | ||
2 | import * as validator from 'validator' | ||
3 | import * as express from 'express' | ||
4 | import 'express-validator' | ||
5 | |||
6 | import { database as db } from '../../initializers' | ||
7 | import { AccountInstance } from '../../models' | ||
8 | import { logger } from '../logger' | ||
9 | |||
10 | import { isUserUsernameValid } from './users' | ||
11 | |||
12 | function isVideoAccountNameValid (value: string) { | ||
13 | return isUserUsernameValid(value) | ||
14 | } | ||
15 | |||
16 | function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) { | ||
17 | let promise: Promise<AccountInstance> | ||
18 | if (validator.isInt(id)) { | ||
19 | promise = db.Account.load(+id) | ||
20 | } else { // UUID | ||
21 | promise = db.Account.loadByUUID(id) | ||
22 | } | ||
23 | |||
24 | promise.then(account => { | ||
25 | if (!account) { | ||
26 | return res.status(404) | ||
27 | .json({ error: 'Video account not found' }) | ||
28 | .end() | ||
29 | } | ||
30 | |||
31 | res.locals.account = account | ||
32 | callback() | ||
33 | }) | ||
34 | .catch(err => { | ||
35 | logger.error('Error in video account request validator.', err) | ||
36 | return res.sendStatus(500) | ||
37 | }) | ||
38 | } | ||
39 | |||
40 | // --------------------------------------------------------------------------- | ||
41 | |||
42 | export { | ||
43 | checkVideoAccountExists, | ||
44 | isVideoAccountNameValid | ||
45 | } | ||
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index b6be557e6..acc42f4a4 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts | |||
@@ -26,9 +26,9 @@ function isVideoChannelUUIDValid (value: string) { | |||
26 | function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) { | 26 | function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) { |
27 | let promise: Promise<VideoChannelInstance> | 27 | let promise: Promise<VideoChannelInstance> |
28 | if (validator.isInt(id)) { | 28 | if (validator.isInt(id)) { |
29 | promise = db.VideoChannel.loadAndPopulateAuthor(+id) | 29 | promise = db.VideoChannel.loadAndPopulateAccount(+id) |
30 | } else { // UUID | 30 | } else { // UUID |
31 | promise = db.VideoChannel.loadByUUIDAndPopulateAuthor(id) | 31 | promise = db.VideoChannel.loadByUUIDAndPopulateAccount(id) |
32 | } | 32 | } |
33 | 33 | ||
34 | promise.then(videoChannel => { | 34 | promise.then(videoChannel => { |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 83407f17b..487b3d646 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -166,9 +166,9 @@ function isVideoFileInfoHashValid (value: string) { | |||
166 | function checkVideoExists (id: string, res: express.Response, callback: () => void) { | 166 | function checkVideoExists (id: string, res: express.Response, callback: () => void) { |
167 | let promise: Promise<VideoInstance> | 167 | let promise: Promise<VideoInstance> |
168 | if (validator.isInt(id)) { | 168 | if (validator.isInt(id)) { |
169 | promise = db.Video.loadAndPopulateAuthorAndPodAndTags(+id) | 169 | promise = db.Video.loadAndPopulateAccountAndPodAndTags(+id) |
170 | } else { // UUID | 170 | } else { // UUID |
171 | promise = db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(id) | 171 | promise = db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(id) |
172 | } | 172 | } |
173 | 173 | ||
174 | promise.then(video => { | 174 | promise.then(video => { |