1 import { pick } from 'lodash'
2 import { ActivityPubActorType, ActorFollow, FollowState, ResultList } from '@shared/models'
3 import { HttpStatusCode } from '@shared/models'
4 import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 import { PeerTubeServer } from './server'
7 export class FollowsCommand extends AbstractCommand {
9 getFollowers (options: OverrideCommandOptions & {
14 actorType?: ActivityPubActorType
17 const path = '/api/v1/server/followers'
19 const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
20 const query = pick(options, toPick)
22 return this.getRequestBody<ResultList<ActorFollow>>({
28 defaultExpectedStatus: HttpStatusCode.OK_200
32 getFollowings (options: OverrideCommandOptions & {
37 actorType?: ActivityPubActorType
40 const path = '/api/v1/server/following'
42 const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
43 const query = pick(options, toPick)
45 return this.getRequestBody<ResultList<ActorFollow>>({
51 defaultExpectedStatus: HttpStatusCode.OK_200
55 follow (options: OverrideCommandOptions & {
58 const path = '/api/v1/server/following'
60 const hosts = options.targets.map(f => f.replace(/^http:\/\//, ''))
62 return this.postBodyRequest({
68 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
72 async unfollow (options: OverrideCommandOptions & {
73 target: PeerTubeServer
75 const path = '/api/v1/server/following/' + options.target.host
77 return this.deleteRequest({
82 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
86 acceptFollower (options: OverrideCommandOptions & {
89 const path = '/api/v1/server/followers/' + options.follower + '/accept'
91 return this.postBodyRequest({
96 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
100 rejectFollower (options: OverrideCommandOptions & {
103 const path = '/api/v1/server/followers/' + options.follower + '/reject'
105 return this.postBodyRequest({
110 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
114 removeFollower (options: OverrideCommandOptions & {
115 follower: PeerTubeServer
117 const path = '/api/v1/server/followers/peertube@' + options.follower.host
119 return this.deleteRequest({
124 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204