]>
Commit | Line | Data |
---|---|---|
38fa2065 | 1 | import * as Promise from 'bluebird' |
38fa2065 C |
2 | import * as express from 'express' |
3 | import 'express-validator' | |
d4f1e94c | 4 | import * as validator from 'validator' |
38fa2065 C |
5 | import { database as db } from '../../initializers' |
6 | import { AccountInstance } from '../../models' | |
7 | import { logger } from '../logger' | |
38fa2065 C |
8 | import { isUserUsernameValid } from './users' |
9 | ||
350e31d6 | 10 | function isAccountNameValid (value: string) { |
38fa2065 C |
11 | return isUserUsernameValid(value) |
12 | } | |
13 | ||
14 | function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) { | |
15 | let promise: Promise<AccountInstance> | |
16 | if (validator.isInt(id)) { | |
17 | promise = db.Account.load(+id) | |
18 | } else { // UUID | |
19 | promise = db.Account.loadByUUID(id) | |
20 | } | |
21 | ||
22 | promise.then(account => { | |
23 | if (!account) { | |
24 | return res.status(404) | |
25 | .json({ error: 'Video account not found' }) | |
26 | .end() | |
27 | } | |
28 | ||
29 | res.locals.account = account | |
30 | callback() | |
31 | }) | |
350e31d6 C |
32 | .catch(err => { |
33 | logger.error('Error in video account request validator.', err) | |
34 | return res.sendStatus(500) | |
35 | }) | |
38fa2065 C |
36 | } |
37 | ||
38 | // --------------------------------------------------------------------------- | |
39 | ||
40 | export { | |
41 | checkVideoAccountExists, | |
350e31d6 | 42 | isAccountNameValid |
38fa2065 | 43 | } |