aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-14 17:31:26 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad (patch)
treef4191f3c04a5230fcf8ca3d6ca3248643fc4151d /server/middlewares/validators
parente34c85e527100c0b5c44567bd951e95be41b8d7e (diff)
downloadPeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.gz
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.zst
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.zip
Follow works
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/account.ts10
-rw-r--r--server/middlewares/validators/activitypub/activity.ts7
-rw-r--r--server/middlewares/validators/index.ts1
-rw-r--r--server/middlewares/validators/webfinger.ts42
4 files changed, 50 insertions, 10 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
index 3ccf2ea21..58eeed3cc 100644
--- a/server/middlewares/validators/account.ts
+++ b/server/middlewares/validators/account.ts
@@ -8,13 +8,13 @@ import {
8 isUserVideoQuotaValid, 8 isUserVideoQuotaValid,
9 logger 9 logger
10} from '../../helpers' 10} from '../../helpers'
11import { isAccountNameWithHostValid } from '../../helpers/custom-validators/video-accounts' 11import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
12import { database as db } from '../../initializers/database' 12import { database as db } from '../../initializers/database'
13import { AccountInstance } from '../../models' 13import { AccountInstance } from '../../models'
14import { checkErrors } from './utils' 14import { checkErrors } from './utils'
15 15
16const localAccountValidator = [ 16const localAccountValidator = [
17 param('nameWithHost').custom(isAccountNameWithHostValid).withMessage('Should have a valid account with domain name (myuser@domain.tld)'), 17 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
18 18
19 (req: express.Request, res: express.Response, next: express.NextFunction) => { 19 (req: express.Request, res: express.Response, next: express.NextFunction) => {
20 logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) 20 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
@@ -33,10 +33,8 @@ export {
33 33
34// --------------------------------------------------------------------------- 34// ---------------------------------------------------------------------------
35 35
36function checkLocalAccountExists (nameWithHost: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) { 36function checkLocalAccountExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) {
37 const [ name, host ] = nameWithHost.split('@') 37 db.Account.loadLocalByName(name)
38
39 db.Account.loadLocalAccountByNameAndPod(name, host)
40 .then(account => { 38 .then(account => {
41 if (!account) { 39 if (!account) {
42 return res.status(404) 40 return res.status(404)
diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts
index 78a6d1444..0de8b2d85 100644
--- a/server/middlewares/validators/activitypub/activity.ts
+++ b/server/middlewares/validators/activitypub/activity.ts
@@ -1,11 +1,10 @@
1import { body } from 'express-validator/check'
2import * as express from 'express' 1import * as express from 'express'
3 2import { body } from 'express-validator/check'
4import { logger, isRootActivityValid } from '../../../helpers' 3import { isRootActivityValid, logger } from '../../../helpers'
5import { checkErrors } from '../utils' 4import { checkErrors } from '../utils'
6 5
7const activityPubValidator = [ 6const activityPubValidator = [
8 body('data').custom(isRootActivityValid), 7 body('').custom((value, { req }) => isRootActivityValid(req.body)),
9 8
10 (req: express.Request, res: express.Response, next: express.NextFunction) => { 9 (req: express.Request, res: express.Response, next: express.NextFunction) => {
11 logger.debug('Checking activity pub parameters', { parameters: req.body }) 10 logger.debug('Checking activity pub parameters', { parameters: req.body })
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts
index 46c00d679..92a4bad28 100644
--- a/server/middlewares/validators/index.ts
+++ b/server/middlewares/validators/index.ts
@@ -8,3 +8,4 @@ export * from './users'
8export * from './videos' 8export * from './videos'
9export * from './video-blacklist' 9export * from './video-blacklist'
10export * from './video-channels' 10export * from './video-channels'
11export * from './webfinger'
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts
new file mode 100644
index 000000000..068e03ad7
--- /dev/null
+++ b/server/middlewares/validators/webfinger.ts
@@ -0,0 +1,42 @@
1import { query } from 'express-validator/check'
2import * as express from 'express'
3
4import { checkErrors } from './utils'
5import { logger, isWebfingerResourceValid } from '../../helpers'
6import { database as db } from '../../initializers'
7
8const webfingerValidator = [
9 query('resource').custom(isWebfingerResourceValid).withMessage('Should have a valid webfinger resource'),
10
11 (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 logger.debug('Checking webfinger parameters', { parameters: req.query })
13
14 checkErrors(req, res, () => {
15 // Remove 'acct:' from the beginning of the string
16 const nameWithHost = req.query.resource.substr(5)
17 const [ name, ] = nameWithHost.split('@')
18
19 db.Account.loadLocalByName(name)
20 .then(account => {
21 if (!account) {
22 return res.status(404)
23 .send({ error: 'Account not found' })
24 .end()
25 }
26
27 res.locals.account = account
28 return next()
29 })
30 .catch(err => {
31 logger.error('Error in webfinger validator.', err)
32 return res.sendStatus(500)
33 })
34 })
35 }
36]
37
38// ---------------------------------------------------------------------------
39
40export {
41 webfingerValidator
42}