aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-accounts.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-10 14:48:08 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit38fa2065831b5f55be0d7f30f19a62c967397208 (patch)
tree4a986465e3a88c85bc6a8b5fc992e0f2edd63ef0 /server/helpers/custom-validators/video-accounts.ts
parent0d0e8dd0904b380b70e19ebcb4763d65601c4632 (diff)
downloadPeerTube-38fa2065831b5f55be0d7f30f19a62c967397208.tar.gz
PeerTube-38fa2065831b5f55be0d7f30f19a62c967397208.tar.zst
PeerTube-38fa2065831b5f55be0d7f30f19a62c967397208.zip
Remove references to author
Diffstat (limited to 'server/helpers/custom-validators/video-accounts.ts')
-rw-r--r--server/helpers/custom-validators/video-accounts.ts45
1 files changed, 45 insertions, 0 deletions
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}