1 import * as express from 'express'
2 import { body, param } from 'express-validator/check'
3 import { getServerActor, isTestInstance, logger } from '../../helpers'
4 import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers'
5 import { CONFIG } from '../../initializers'
6 import { ActorFollowModel } from '../../models/activitypub/actor-follow'
7 import { areValidationErrors } from './utils'
9 const followValidator = [
10 body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'),
12 (req: express.Request, res: express.Response, next: express.NextFunction) => {
13 // Force https if the administrator wants to make friends
14 if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') {
15 return res.status(400)
17 error: 'Cannot follow non HTTPS web server.'
22 logger.debug('Checking follow parameters', { parameters: req.body })
24 if (areValidationErrors(req, res)) return
30 const removeFollowingValidator = [
31 param('host').custom(isHostValid).withMessage('Should have a valid host'),
33 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
34 logger.debug('Checking unfollow parameters', { parameters: req.params })
36 if (areValidationErrors(req, res)) return
38 const serverActor = await getServerActor()
39 const follow = await ActorFollowModel.loadByActorAndTargetHost(serverActor.id, req.params.host)
42 return res.status(404)
46 res.locals.follow = follow
51 // ---------------------------------------------------------------------------
55 removeFollowingValidator