1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Add ability to remove an instance follower in API

This commit is contained in:
Chocobozzz 2019-04-08 11:52:29 +02:00
parent ae9bbed46d
commit 0e9c48c2ed
No known key found for this signature in database
GPG key ID: 583A612D890159BE
8 changed files with 202 additions and 11 deletions

View file

@ -7,6 +7,10 @@ import { getServerActor } from '../../helpers/utils'
import { CONFIG, SERVER_ACTOR_NAME } from '../../initializers'
import { ActorFollowModel } from '../../models/activitypub/actor-follow'
import { areValidationErrors } from './utils'
import { ActorModel } from '../../models/activitypub/actor'
import { loadActorUrlOrGetFromWebfinger } from '../../helpers/webfinger'
import { getOrCreateActorAndServerAndModel } from '../../lib/activitypub'
import { isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
const followValidator = [
body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'),
@ -33,7 +37,7 @@ const removeFollowingValidator = [
param('host').custom(isHostValid).withMessage('Should have a valid host'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking unfollow parameters', { parameters: req.params })
logger.debug('Checking unfollowing parameters', { parameters: req.params })
if (areValidationErrors(req, res)) return
@ -44,7 +48,36 @@ const removeFollowingValidator = [
return res
.status(404)
.json({
error: `Follower ${req.params.host} not found.`
error: `Following ${req.params.host} not found.`
})
.end()
}
res.locals.follow = follow
return next()
}
]
const removeFollowerValidator = [
param('nameWithHost').custom(isValidActorHandle).withMessage('Should have a valid nameWithHost'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking remove follower parameters', { parameters: req.params })
if (areValidationErrors(req, res)) return
const serverActor = await getServerActor()
const actorUrl = await loadActorUrlOrGetFromWebfinger(req.params.nameWithHost)
const actor = await ActorModel.loadByUrl(actorUrl)
const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, serverActor.id)
if (!follow) {
return res
.status(404)
.json({
error: `Follower ${req.params.nameWithHost} not found.`
})
.end()
}
@ -58,5 +91,6 @@ const removeFollowingValidator = [
export {
followValidator,
removeFollowingValidator
removeFollowingValidator,
removeFollowerValidator
}