mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Add shares forward and collection on videos/video channels
This commit is contained in:
parent
74bb2cb834
commit
4e50b6a1c9
29 changed files with 546 additions and 133 deletions
|
@ -1,4 +1,4 @@
|
|||
import * as Promise from 'bluebird'
|
||||
import * as Bluebird from 'bluebird'
|
||||
import * as express from 'express'
|
||||
import 'express-validator'
|
||||
import * as validator from 'validator'
|
||||
|
@ -11,33 +11,45 @@ function isAccountNameValid (value: string) {
|
|||
return isUserUsernameValid(value)
|
||||
}
|
||||
|
||||
function checkVideoAccountExists (id: string, res: express.Response, callback: () => void) {
|
||||
let promise: Promise<AccountInstance>
|
||||
if (validator.isInt(id)) {
|
||||
function checkAccountIdExists (id: number | string, res: express.Response, callback: (err: Error, account: AccountInstance) => any) {
|
||||
let promise: Bluebird<AccountInstance>
|
||||
|
||||
if (validator.isInt('' + id)) {
|
||||
promise = db.Account.load(+id)
|
||||
} else { // UUID
|
||||
promise = db.Account.loadByUUID(id)
|
||||
promise = db.Account.loadByUUID('' + id)
|
||||
}
|
||||
|
||||
promise.then(account => {
|
||||
return checkAccountExists(promise, res, callback)
|
||||
}
|
||||
|
||||
function checkLocalAccountNameExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => any) {
|
||||
const p = db.Account.loadLocalByName(name)
|
||||
|
||||
return checkAccountExists(p, res, callback)
|
||||
}
|
||||
|
||||
function checkAccountExists (p: Bluebird<AccountInstance>, res: express.Response, callback: (err: Error, account: AccountInstance) => any) {
|
||||
p.then(account => {
|
||||
if (!account) {
|
||||
return res.status(404)
|
||||
.json({ error: 'Video account not found' })
|
||||
.send({ error: 'Account not found' })
|
||||
.end()
|
||||
}
|
||||
|
||||
res.locals.account = account
|
||||
callback()
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error in video account request validator.', err)
|
||||
return res.sendStatus(500)
|
||||
return callback(null, account)
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error in account request validator.', err)
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
checkVideoAccountExists,
|
||||
checkAccountIdExists,
|
||||
checkLocalAccountNameExists,
|
||||
isAccountNameValid
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue