aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/accounts.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-27 14:44:51 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commit4e50b6a1c9a3eb261e04ede73241648e6edf21d6 (patch)
treee1c6c121d561ffc1cf2996daec03a1e7f27f0a25 /server/helpers/custom-validators/accounts.ts
parent74bb2cb8348d6794ed3a0e2ec94c8c9abdde82cf (diff)
downloadPeerTube-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/accounts.ts')
-rw-r--r--server/helpers/custom-validators/accounts.ts38
1 files changed, 25 insertions, 13 deletions
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts
index fe0fc650a..a6d7f2b82 100644
--- a/server/helpers/custom-validators/accounts.ts
+++ b/server/helpers/custom-validators/accounts.ts
@@ -1,4 +1,4 @@
1import * as Promise from 'bluebird' 1import * as Bluebird from 'bluebird'
2import * as express from 'express' 2import * as express from 'express'
3import 'express-validator' 3import 'express-validator'
4import * as validator from 'validator' 4import * as validator from 'validator'
@@ -11,33 +11,45 @@ function isAccountNameValid (value: string) {
11 return isUserUsernameValid(value) 11 return isUserUsernameValid(value)
12} 12}
13 13
14function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) { 14function checkAccountIdExists (id: number | string, res: express.Response, callback: (err: Error, account: AccountInstance) => any) {
15 let promise: Promise<AccountInstance> 15 let promise: Bluebird<AccountInstance>
16 if (validator.isInt(id)) { 16
17 if (validator.isInt('' + id)) {
17 promise = db.Account.load(+id) 18 promise = db.Account.load(+id)
18 } else { // UUID 19 } else { // UUID
19 promise = db.Account.loadByUUID(id) 20 promise = db.Account.loadByUUID('' + id)
20 } 21 }
21 22
22 promise.then(account => { 23 return checkAccountExists(promise, res, callback)
24}
25
26function checkLocalAccountNameExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => any) {
27 const p = db.Account.loadLocalByName(name)
28
29 return checkAccountExists(p, res, callback)
30}
31
32function checkAccountExists (p: Bluebird<AccountInstance>, res: express.Response, callback: (err: Error, account: AccountInstance) => any) {
33 p.then(account => {
23 if (!account) { 34 if (!account) {
24 return res.status(404) 35 return res.status(404)
25 .json({ error: 'Video account not found' }) 36 .send({ error: 'Account not found' })
26 .end() 37 .end()
27 } 38 }
28 39
29 res.locals.account = account 40 res.locals.account = account
30 callback() 41 return callback(null, account)
31 })
32 .catch(err => {
33 logger.error('Error in video account request validator.', err)
34 return res.sendStatus(500)
35 }) 42 })
43 .catch(err => {
44 logger.error('Error in account request validator.', err)
45 return res.sendStatus(500)
46 })
36} 47}
37 48
38// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
39 50
40export { 51export {
41 checkVideoAccountExists, 52 checkAccountIdExists,
53 checkLocalAccountNameExists,
42 isAccountNameValid 54 isAccountNameValid
43} 55}