1 import * as Promise from 'bluebird'
2 import * as validator from 'validator'
3 import * as express from 'express'
4 import 'express-validator'
6 import { database as db } from '../../initializers'
7 import { AccountInstance } from '../../models'
8 import { logger } from '../logger'
10 import { isUserUsernameValid } from './users'
11 import { isHostValid } from './servers'
13 function isAccountNameValid (value: string) {
14 return isUserUsernameValid(value)
17 function isAccountNameWithHostValid (value: string) {
18 const [ name, host ] = value.split('@')
20 return isAccountNameValid(name) && isHostValid(host)
23 function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) {
24 let promise: Promise<AccountInstance>
25 if (validator.isInt(id)) {
26 promise = db.Account.load(+id)
28 promise = db.Account.loadByUUID(id)
31 promise.then(account => {
33 return res.status(404)
34 .json({ error: 'Video account not found' })
38 res.locals.account = account
42 logger.error('Error in video account request validator.', err)
43 return res.sendStatus(500)
47 // ---------------------------------------------------------------------------
50 checkVideoAccountExists,
51 isAccountNameWithHostValid,