mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 18:29:27 +02:00
Follow works
This commit is contained in:
parent
e34c85e527
commit
350e31d6b6
39 changed files with 431 additions and 169 deletions
|
@ -1,53 +0,0 @@
|
|||
import * as Promise from 'bluebird'
|
||||
import * as validator from 'validator'
|
||||
import * as express from 'express'
|
||||
import 'express-validator'
|
||||
|
||||
import { database as db } from '../../initializers'
|
||||
import { AccountInstance } from '../../models'
|
||||
import { logger } from '../logger'
|
||||
|
||||
import { isUserUsernameValid } from './users'
|
||||
import { isHostValid } from './pods'
|
||||
|
||||
function isVideoAccountNameValid (value: string) {
|
||||
return isUserUsernameValid(value)
|
||||
}
|
||||
|
||||
function isAccountNameWithHostValid (value: string) {
|
||||
const [ name, host ] = value.split('@')
|
||||
|
||||
return isVideoAccountNameValid(name) && isHostValid(host)
|
||||
}
|
||||
|
||||
function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) {
|
||||
let promise: Promise<AccountInstance>
|
||||
if (validator.isInt(id)) {
|
||||
promise = db.Account.load(+id)
|
||||
} else { // UUID
|
||||
promise = db.Account.loadByUUID(id)
|
||||
}
|
||||
|
||||
promise.then(account => {
|
||||
if (!account) {
|
||||
return res.status(404)
|
||||
.json({ error: 'Video account not found' })
|
||||
.end()
|
||||
}
|
||||
|
||||
res.locals.account = account
|
||||
callback()
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error in video account request validator.', err)
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
checkVideoAccountExists,
|
||||
isAccountNameWithHostValid,
|
||||
isVideoAccountNameValid
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue