From 571389d43b8fc8aaf27e77c06f19b320b08dbbc9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Nov 2017 17:27:49 +0100 Subject: Make it compile at least --- server/middlewares/validators/activitypub/index.ts | 3 +- server/middlewares/validators/activitypub/pods.ts | 38 ----------- server/middlewares/validators/index.ts | 1 - server/middlewares/validators/pods.ts | 73 ---------------------- 4 files changed, 1 insertion(+), 114 deletions(-) delete mode 100644 server/middlewares/validators/activitypub/pods.ts delete mode 100644 server/middlewares/validators/pods.ts (limited to 'server/middlewares') diff --git a/server/middlewares/validators/activitypub/index.ts b/server/middlewares/validators/activitypub/index.ts index f1f26043e..84d1107fc 100644 --- a/server/middlewares/validators/activitypub/index.ts +++ b/server/middlewares/validators/activitypub/index.ts @@ -1,3 +1,2 @@ -export * from './pods' +export * from './activity' export * from './signature' -export * from './videos' diff --git a/server/middlewares/validators/activitypub/pods.ts b/server/middlewares/validators/activitypub/pods.ts deleted file mode 100644 index f917b61ee..000000000 --- a/server/middlewares/validators/activitypub/pods.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { body } from 'express-validator/check' -import * as express from 'express' - -import { database as db } from '../../../initializers' -import { isHostValid, logger } from '../../../helpers' -import { checkErrors } from '../utils' - -const remotePodsAddValidator = [ - body('host').custom(isHostValid).withMessage('Should have a host'), - body('email').isEmail().withMessage('Should have an email'), - body('publicKey').not().isEmpty().withMessage('Should have a public key'), - - (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking podsAdd parameters', { parameters: req.body }) - - checkErrors(req, res, () => { - db.Pod.loadByHost(req.body.host) - .then(pod => { - // Pod with this host already exists - if (pod) { - return res.sendStatus(409) - } - - return next() - }) - .catch(err => { - logger.error('Cannot load pod by host.', err) - res.sendStatus(500) - }) - }) - } -] - -// --------------------------------------------------------------------------- - -export { - remotePodsAddValidator -} diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 46c00d679..0b7573d4f 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts @@ -2,7 +2,6 @@ export * from './account' export * from './oembed' export * from './activitypub' export * from './pagination' -export * from './pods' export * from './sort' export * from './users' export * from './videos' diff --git a/server/middlewares/validators/pods.ts b/server/middlewares/validators/pods.ts deleted file mode 100644 index 8465fea53..000000000 --- a/server/middlewares/validators/pods.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { body, param } from 'express-validator/check' -import * as express from 'express' - -import { database as db } from '../../initializers/database' -import { checkErrors } from './utils' -import { logger, isEachUniqueHostValid, isTestInstance } from '../../helpers' -import { CONFIG } from '../../initializers' -import { hasFriends } from '../../lib' - -const makeFriendsValidator = [ - body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), - - (req: express.Request, res: express.Response, next: express.NextFunction) => { - // Force https if the administrator wants to make friends - if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') { - return res.status(400) - .json({ - error: 'Cannot make friends with a non HTTPS web server.' - }) - .end() - } - - logger.debug('Checking makeFriends parameters', { parameters: req.body }) - - checkErrors(req, res, () => { - hasFriends() - .then(heHasFriends => { - if (heHasFriends === true) { - // We need to quit our friends before make new ones - return res.sendStatus(409) - } - - return next() - }) - .catch(err => { - logger.error('Cannot know if we have friends.', err) - res.sendStatus(500) - }) - }) - } -] - -const podRemoveValidator = [ - param('id').isNumeric().not().isEmpty().withMessage('Should have a valid id'), - - (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking podRemoveValidator parameters', { parameters: req.params }) - - checkErrors(req, res, () => { - db.Pod.load(req.params.id) - .then(pod => { - if (!pod) { - logger.error('Cannot find pod %d.', req.params.id) - return res.sendStatus(404) - } - - res.locals.pod = pod - return next() - }) - .catch(err => { - logger.error('Cannot load pod %d.', req.params.id, err) - res.sendStatus(500) - }) - }) - } -] - -// --------------------------------------------------------------------------- - -export { - makeFriendsValidator, - podRemoveValidator -} -- cgit v1.2.3