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'
12 function isVideoAccountNameValid (value: string) {
13 return isUserUsernameValid(value)
16 function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) {
17 let promise: Promise<AccountInstance>
18 if (validator.isInt(id)) {
19 promise = db.Account.load(+id)
21 promise = db.Account.loadByUUID(id)
24 promise.then(account => {
26 return res.status(404)
27 .json({ error: 'Video account not found' })
31 res.locals.account = account
35 logger.error('Error in video account request validator.', err)
36 return res.sendStatus(500)
40 // ---------------------------------------------------------------------------
43 checkVideoAccountExists,
44 isVideoAccountNameValid