From ce548a10db3822c415b30ea0edb59e02a460734a Mon Sep 17 00:00:00 2001
From: Chocobozzz <florian.bigard@gmail.com>
Date: Mon, 13 Nov 2017 18:48:28 +0100
Subject: Send follow/accept

---
 server/middlewares/validators/index.ts |  1 +
 server/middlewares/validators/pods.ts  | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 server/middlewares/validators/pods.ts

(limited to 'server/middlewares')

diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts
index 0b7573d4f..46c00d679 100644
--- a/server/middlewares/validators/index.ts
+++ b/server/middlewares/validators/index.ts
@@ -2,6 +2,7 @@ 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
new file mode 100644
index 000000000..e17369a6f
--- /dev/null
+++ b/server/middlewares/validators/pods.ts
@@ -0,0 +1,32 @@
+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
+}
-- 
cgit v1.2.3