+const getFollowerValidator = [
+ param('nameWithHost').custom(isValidActorHandle).withMessage('Should have a valid nameWithHost'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking get follower parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+
+ let follow: ActorFollowModel
+ try {
+ const actorUrl = await loadActorUrlOrGetFromWebfinger(req.params.nameWithHost)
+ const actor = await ActorModel.loadByUrl(actorUrl)
+
+ const serverActor = await getServerActor()
+ follow = await ActorFollowModel.loadByActorAndTarget(actor.id, serverActor.id)
+ } catch (err) {
+ logger.warn('Cannot get actor from handle.', { handle: req.params.nameWithHost, err })
+ }
+
+ if (!follow) {
+ return res
+ .status(404)
+ .json({
+ error: `Follower ${req.params.nameWithHost} not found.`
+ })
+ .end()
+ }
+
+ res.locals.follow = follow
+ return next()
+ }
+]
+
+const acceptOrRejectFollowerValidator = [
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking accept/reject follower parameters', { parameters: req.params })
+
+ const follow = res.locals.follow
+ if (follow.state !== 'pending') {
+ return res.status(400).json({ error: 'Follow is not in pending state.' }).end()
+ }
+
+ return next()
+ }
+]
+