From 608624252466acf9f1d9ee1c1170bd4fe4d18d18 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Nov 2017 11:00:25 +0100 Subject: Rename Pod -> Server --- server/middlewares/activitypub.ts | 4 +- server/middlewares/index.ts | 2 +- server/middlewares/pods.ts | 58 ------------------------- server/middlewares/servers.ts | 58 +++++++++++++++++++++++++ server/middlewares/sort.ts | 7 --- server/middlewares/validators/index.ts | 2 +- server/middlewares/validators/pods.ts | 32 -------------- server/middlewares/validators/servers.ts | 32 ++++++++++++++ server/middlewares/validators/video-channels.ts | 4 +- server/middlewares/validators/videos.ts | 4 +- 10 files changed, 98 insertions(+), 105 deletions(-) delete mode 100644 server/middlewares/pods.ts create mode 100644 server/middlewares/servers.ts delete mode 100644 server/middlewares/validators/pods.ts create mode 100644 server/middlewares/validators/servers.ts (limited to 'server/middlewares') diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index bed2bfeab..0ea522e5c 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts @@ -1,7 +1,7 @@ import { NextFunction, Request, Response, RequestHandler } from 'express' import { ActivityPubSignature } from '../../shared' import { isSignatureVerified, logger } from '../helpers' -import { fetchRemoteAccountAndCreatePod } from '../helpers/activitypub' +import { fetchRemoteAccountAndCreateServer } from '../helpers/activitypub' import { database as db, ACTIVITY_PUB_ACCEPT_HEADER } from '../initializers' import { each, eachSeries, waterfall } from 'async' @@ -14,7 +14,7 @@ async function checkSignature (req: Request, res: Response, next: NextFunction) // We don't have this account in our database, fetch it on remote if (!account) { - const accountResult = await fetchRemoteAccountAndCreatePod(signatureObject.creator) + const accountResult = await fetchRemoteAccountAndCreateServer(signatureObject.creator) if (!accountResult) { return res.sendStatus(403) diff --git a/server/middlewares/index.ts b/server/middlewares/index.ts index 40480450b..aafcad2d9 100644 --- a/server/middlewares/index.ts +++ b/server/middlewares/index.ts @@ -3,7 +3,7 @@ export * from './activitypub' export * from './async' export * from './oauth' export * from './pagination' -export * from './pods' +export * from './servers' export * from './search' export * from './sort' export * from './user-right' diff --git a/server/middlewares/pods.ts b/server/middlewares/pods.ts deleted file mode 100644 index eaf9aa144..000000000 --- a/server/middlewares/pods.ts +++ /dev/null @@ -1,58 +0,0 @@ -import 'express-validator' -import * as express from 'express' - -import { REMOTE_SCHEME } from '../initializers' - -function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { - if (!req.body.hosts) return next() - - for (let i = 0; i < req.body.hosts.length; i++) { - const hostWithPort = getHostWithPort(req.body.hosts[i]) - - // Problem with the url parsing? - if (hostWithPort === null) { - return res.sendStatus(500) - } - - req.body.hosts[i] = hostWithPort - } - - return next() -} - -function setBodyHostPort (req: express.Request, res: express.Response, next: express.NextFunction) { - if (!req.body.host) return next() - - const hostWithPort = getHostWithPort(req.body.host) - - // Problem with the url parsing? - if (hostWithPort === null) { - return res.sendStatus(500) - } - - req.body.host = hostWithPort - - return next() -} - -// --------------------------------------------------------------------------- - -export { - setBodyHostsPort, - setBodyHostPort -} - -// --------------------------------------------------------------------------- - -function getHostWithPort (host: string) { - const splitted = host.split(':') - - // The port was not specified - if (splitted.length === 1) { - if (REMOTE_SCHEME.HTTP === 'https') return host + ':443' - - return host + ':80' - } - - return host -} diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts new file mode 100644 index 000000000..eaf9aa144 --- /dev/null +++ b/server/middlewares/servers.ts @@ -0,0 +1,58 @@ +import 'express-validator' +import * as express from 'express' + +import { REMOTE_SCHEME } from '../initializers' + +function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { + if (!req.body.hosts) return next() + + for (let i = 0; i < req.body.hosts.length; i++) { + const hostWithPort = getHostWithPort(req.body.hosts[i]) + + // Problem with the url parsing? + if (hostWithPort === null) { + return res.sendStatus(500) + } + + req.body.hosts[i] = hostWithPort + } + + return next() +} + +function setBodyHostPort (req: express.Request, res: express.Response, next: express.NextFunction) { + if (!req.body.host) return next() + + const hostWithPort = getHostWithPort(req.body.host) + + // Problem with the url parsing? + if (hostWithPort === null) { + return res.sendStatus(500) + } + + req.body.host = hostWithPort + + return next() +} + +// --------------------------------------------------------------------------- + +export { + setBodyHostsPort, + setBodyHostPort +} + +// --------------------------------------------------------------------------- + +function getHostWithPort (host: string) { + const splitted = host.split(':') + + // The port was not specified + if (splitted.length === 1) { + if (REMOTE_SCHEME.HTTP === 'https') return host + ':443' + + return host + ':80' + } + + return host +} diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index 20ae341f0..279b29e65 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts @@ -4,12 +4,6 @@ import * as express from 'express' import { SortType } from '../helpers' import { database } from '../initializers' -function setPodsSort (req: express.Request, res: express.Response, next: express.NextFunction) { - if (!req.query.sort) req.query.sort = '-createdAt' - - return next() -} - function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { if (!req.query.sort) req.query.sort = '-createdAt' @@ -70,7 +64,6 @@ function setBlacklistSort (req: express.Request, res: express.Response, next: ex // --------------------------------------------------------------------------- export { - setPodsSort, setUsersSort, setVideoAbusesSort, setVideoChannelsSort, diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 92a4bad28..3f5afe5b3 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts @@ -2,7 +2,7 @@ export * from './account' export * from './oembed' export * from './activitypub' export * from './pagination' -export * from './pods' +export * from './servers' 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 e17369a6f..000000000 --- a/server/middlewares/validators/pods.ts +++ /dev/null @@ -1,32 +0,0 @@ -import * as express from 'express' -import { body } from 'express-validator/check' -import { isEachUniqueHostValid } from '../../helpers/custom-validators/pods' -import { isTestInstance } from '../../helpers/core-utils' -import { CONFIG } from '../../initializers/constants' -import { logger } from '../../helpers/logger' -import { checkErrors } from './utils' - -const followValidator = [ - 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 follow non HTTPS web server.' - }) - .end() - } - - logger.debug('Checking follow parameters', { parameters: req.body }) - - checkErrors(req, res, next) - } -] - -// --------------------------------------------------------------------------- - -export { - followValidator -} diff --git a/server/middlewares/validators/servers.ts b/server/middlewares/validators/servers.ts new file mode 100644 index 000000000..95b69b789 --- /dev/null +++ b/server/middlewares/validators/servers.ts @@ -0,0 +1,32 @@ +import * as express from 'express' +import { body } from 'express-validator/check' +import { isEachUniqueHostValid } from '../../helpers/custom-validators/servers' +import { isTestInstance } from '../../helpers/core-utils' +import { CONFIG } from '../../initializers/constants' +import { logger } from '../../helpers/logger' +import { checkErrors } from './utils' + +const followValidator = [ + 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 follow non HTTPS web server.' + }) + .end() + } + + logger.debug('Checking follow parameters', { parameters: req.body }) + + checkErrors(req, res, next) + } +] + +// --------------------------------------------------------------------------- + +export { + followValidator +} diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 53416a857..f0ead24e3 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts @@ -50,7 +50,7 @@ const videoChannelsUpdateValidator = [ // We need to make additional checks if (res.locals.videoChannel.isOwned() === false) { return res.status(403) - .json({ error: 'Cannot update video channel of another pod' }) + .json({ error: 'Cannot update video channel of another server' }) .end() } @@ -113,7 +113,7 @@ function checkUserCanDeleteVideoChannel (res: express.Response, callback: () => // Retrieve the user who did the request if (res.locals.videoChannel.isOwned() === false) { return res.status(403) - .json({ error: 'Cannot remove video channel of another pod.' }) + .json({ error: 'Cannot remove video channel of another server.' }) .end() } diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index 10b426df3..158b475e3 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts @@ -127,7 +127,7 @@ const videosUpdateValidator = [ // We need to make additional checks if (video.isOwned() === false) { return res.status(403) - .json({ error: 'Cannot update video of another pod' }) + .json({ error: 'Cannot update video of another server' }) .end() } @@ -250,7 +250,7 @@ function checkUserCanDeleteVideo (userId: number, res: express.Response, callbac // Retrieve the user who did the request if (res.locals.video.isOwned() === false) { return res.status(403) - .json({ error: 'Cannot remove video of another pod, blacklist it' }) + .json({ error: 'Cannot remove video of another server, blacklist it' }) .end() } -- cgit v1.2.3