1 import * as express from 'express'
2 import { body } from 'express-validator/check'
3 import { isTestInstance } from '../../helpers/core-utils'
4 import { isAccountIdValid } from '../../helpers/custom-validators/activitypub/account'
5 import { isEachUniqueHostValid } from '../../helpers/custom-validators/servers'
6 import { logger } from '../../helpers/logger'
7 import { CONFIG, database as db } from '../../initializers'
8 import { checkErrors } from './utils'
9 import { getServerAccount } from '../../helpers/utils'
11 const followValidator = [
12 body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'),
14 (req: express.Request, res: express.Response, next: express.NextFunction) => {
15 // Force https if the administrator wants to make friends
16 if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') {
17 return res.status(400)
19 error: 'Cannot follow non HTTPS web server.'
24 logger.debug('Checking follow parameters', { parameters: req.body })
26 checkErrors(req, res, next)
30 const removeFollowingValidator = [
31 body('accountId').custom(isAccountIdValid).withMessage('Should have a valid account id'),
33 (req: express.Request, res: express.Response, next: express.NextFunction) => {
34 logger.debug('Checking follow parameters', { parameters: req.body })
36 checkErrors(req, res, async () => {
38 const serverAccount = await getServerAccount()
39 const following = await db.AccountFollow.loadByAccountAndTarget(serverAccount.id, req.params.accountId)
42 return res.status(404)
46 res.locals.following = following
50 logger.error('Error in remove following validator.', err)
51 return res.sendStatus(500)
57 // ---------------------------------------------------------------------------
61 removeFollowingValidator