diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-23 10:40:39 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 3e753302d8c911b59971c16a8018df0e1ab78465 (patch) | |
tree | efce7ece3273589228c5c948ea6757b2bdf65429 /server/helpers/custom-validators/accounts.ts | |
parent | a8b666e9f1ed002230869606308749614390c82f (diff) | |
download | PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.tar.gz PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.tar.zst PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.zip |
Refactor middleware helpers
Diffstat (limited to 'server/helpers/custom-validators/accounts.ts')
-rw-r--r-- | server/helpers/custom-validators/accounts.ts | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts index 31a2de5ca..be196d2a4 100644 --- a/server/helpers/custom-validators/accounts.ts +++ b/server/helpers/custom-validators/accounts.ts | |||
@@ -1,7 +1,4 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { Response } from 'express' | ||
3 | import 'express-validator' | 1 | import 'express-validator' |
4 | import { AccountModel } from '../../models/account/account' | ||
5 | import { isUserDescriptionValid, isUserUsernameValid } from './users' | 2 | import { isUserDescriptionValid, isUserUsernameValid } from './users' |
6 | import { exists } from './misc' | 3 | import { exists } from './misc' |
7 | 4 | ||
@@ -17,47 +14,10 @@ function isAccountDescriptionValid (value: string) { | |||
17 | return isUserDescriptionValid(value) | 14 | return isUserDescriptionValid(value) |
18 | } | 15 | } |
19 | 16 | ||
20 | function doesAccountIdExist (id: number, res: Response, sendNotFound = true) { | ||
21 | const promise = AccountModel.load(id) | ||
22 | |||
23 | return doesAccountExist(promise, res, sendNotFound) | ||
24 | } | ||
25 | |||
26 | function doesLocalAccountNameExist (name: string, res: Response, sendNotFound = true) { | ||
27 | const promise = AccountModel.loadLocalByName(name) | ||
28 | |||
29 | return doesAccountExist(promise, res, sendNotFound) | ||
30 | } | ||
31 | |||
32 | function doesAccountNameWithHostExist (nameWithDomain: string, res: Response, sendNotFound = true) { | ||
33 | return doesAccountExist(AccountModel.loadByNameWithHost(nameWithDomain), res, sendNotFound) | ||
34 | } | ||
35 | |||
36 | async function doesAccountExist (p: Bluebird<AccountModel>, res: Response, sendNotFound: boolean) { | ||
37 | const account = await p | ||
38 | |||
39 | if (!account) { | ||
40 | if (sendNotFound === true) { | ||
41 | res.status(404) | ||
42 | .send({ error: 'Account not found' }) | ||
43 | .end() | ||
44 | } | ||
45 | |||
46 | return false | ||
47 | } | ||
48 | |||
49 | res.locals.account = account | ||
50 | |||
51 | return true | ||
52 | } | ||
53 | |||
54 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
55 | 18 | ||
56 | export { | 19 | export { |
57 | isAccountIdValid, | 20 | isAccountIdValid, |
58 | doesAccountIdExist, | ||
59 | doesLocalAccountNameExist, | ||
60 | isAccountDescriptionValid, | 21 | isAccountDescriptionValid, |
61 | doesAccountNameWithHostExist, | ||
62 | isAccountNameValid | 22 | isAccountNameValid |
63 | } | 23 | } |