1 import * as express from 'express'
2 import { body, param } from 'express-validator/check'
3 import { getServerAccount, isTestInstance, logger } from '../../helpers'
4 import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
5 import { isEachUniqueHostValid } from '../../helpers/custom-validators/servers'
6 import { CONFIG } from '../../initializers'
7 import { AccountFollowModel } from '../../models/account/account-follow'
8 import { areValidationErrors } from './utils'
10 const followValidator = [
11 body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'),
13 (req: express.Request, res: express.Response, next: express.NextFunction) => {
14 // Force https if the administrator wants to make friends
15 if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') {
16 return res.status(400)
18 error: 'Cannot follow non HTTPS web server.'
23 logger.debug('Checking follow parameters', { parameters: req.body })
25 if (areValidationErrors(req, res)) return
31 const removeFollowingValidator = [
32 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),
34 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
35 logger.debug('Checking unfollow parameters', { parameters: req.params })
37 if (areValidationErrors(req, res)) return
39 const serverAccount = await getServerAccount()
40 const follow = await AccountFollowModel.loadByAccountAndTarget(serverAccount.id, req.params.accountId)
43 return res.status(404)
47 res.locals.follow = follow
52 // ---------------------------------------------------------------------------
56 removeFollowingValidator