import * as express from 'express'
+import { getServerActor } from '@server/models/application/application'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { UserRight } from '../../../../shared/models/users'
import { logger } from '../../../helpers/logger'
-import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
+import { getFormattedObjects } from '../../../helpers/utils'
import { SERVER_ACTOR_NAME } from '../../../initializers/constants'
+import { sequelizeTypescript } from '../../../initializers/database'
+import { autoFollowBackIfNeeded } from '../../../lib/activitypub/follow'
import { sendAccept, sendReject, sendUndoFollow } from '../../../lib/activitypub/send'
+import { JobQueue } from '../../../lib/job-queue'
+import { removeRedundanciesOfServer } from '../../../lib/redundancy'
import {
asyncMiddleware,
authenticate,
followingSortValidator,
followValidator,
getFollowerValidator,
+ listFollowsValidator,
removeFollowingValidator
} from '../../../middlewares/validators'
-import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
-import { JobQueue } from '../../../lib/job-queue'
-import { removeRedundancyOf } from '../../../lib/redundancy'
-import { sequelizeTypescript } from '../../../initializers/database'
-import { autoFollowBackIfNeeded } from '../../../lib/activitypub/follow'
+import { ActorFollowModel } from '../../../models/actor/actor-follow'
const serverFollowsRouter = express.Router()
serverFollowsRouter.get('/following',
+ listFollowsValidator,
paginationValidator,
followingSortValidator,
setDefaultSort,
)
serverFollowsRouter.get('/followers',
+ listFollowsValidator,
paginationValidator,
followersSortValidator,
setDefaultSort,
async function listFollowing (req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
- const resultList = await ActorFollowModel.listFollowingForApi(
- serverActor.id,
- req.query.start,
- req.query.count,
- req.query.sort,
- req.query.search
- )
+ const resultList = await ActorFollowModel.listFollowingForApi({
+ id: serverActor.id,
+ start: req.query.start,
+ count: req.query.count,
+ sort: req.query.sort,
+ search: req.query.search,
+ actorType: req.query.actorType,
+ state: req.query.state
+ })
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
async function listFollowers (req: express.Request, res: express.Response) {
const serverActor = await getServerActor()
- const resultList = await ActorFollowModel.listFollowersForApi(
- serverActor.id,
- req.query.start,
- req.query.count,
- req.query.sort,
- req.query.search
- )
+ const resultList = await ActorFollowModel.listFollowersForApi({
+ actorId: serverActor.id,
+ start: req.query.start,
+ count: req.query.count,
+ sort: req.query.sort,
+ search: req.query.search,
+ actorType: req.query.actorType,
+ state: req.query.state
+ })
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
}
JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
- .catch(err => logger.error('Cannot create follow job for %s.', host, err))
}
- return res.status(204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
}
async function removeFollowing (req: express.Request, res: express.Response) {
await server.save({ transaction: t })
// Async, could be long
- removeRedundancyOf(server.id)
+ removeRedundanciesOfServer(server.id)
.catch(err => logger.error('Cannot remove redundancy of %s.', server.host, err))
await follow.destroy({ transaction: t })
})
- return res.status(204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
}
async function removeOrRejectFollower (req: express.Request, res: express.Response) {
const follow = res.locals.follow
- await sendReject(follow.ActorFollower, follow.ActorFollowing)
+ await sendReject(follow.url, follow.ActorFollower, follow.ActorFollowing)
await follow.destroy()
- return res.status(204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
}
async function acceptFollower (req: express.Request, res: express.Response) {
await autoFollowBackIfNeeded(follow)
- return res.status(204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
}