aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/index.ts1
-rw-r--r--server/helpers/custom-validators/video-accounts.ts45
-rw-r--r--server/helpers/custom-validators/video-channels.ts4
-rw-r--r--server/helpers/custom-validators/videos.ts4
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'
3export * from './pods' 3export * from './pods'
4export * from './pods' 4export * from './pods'
5export * from './users' 5export * from './users'
6export * from './video-accounts'
6export * from './video-channels' 7export * from './video-channels'
7export * from './videos' 8export * 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 @@
1import * as Promise from 'bluebird'
2import * as validator from 'validator'
3import * as express from 'express'
4import 'express-validator'
5
6import { database as db } from '../../initializers'
7import { AccountInstance } from '../../models'
8import { logger } from '../logger'
9
10import { isUserUsernameValid } from './users'
11
12function isVideoAccountNameValid (value: string) {
13 return isUserUsernameValid(value)
14}
15
16function 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
42export {
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) {
26function checkVideoChannelExists (id: string, res: express.Response, callback: () => void) { 26function 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) {
166function checkVideoExists (id: string, res: express.Response, callback: () => void) { 166function 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 => {