1 import { pick } from 'lodash'
2 import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList } from '@shared/models'
3 import { AbstractCommand, OverrideCommandOptions } from '../shared'
4 import { PeerTubeServer } from './server'
6 export class FollowsCommand extends AbstractCommand {
8 getFollowers (options: OverrideCommandOptions & {
13 actorType?: ActivityPubActorType
16 const path = '/api/v1/server/followers'
18 const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
19 const query = pick(options, toPick)
21 return this.getRequestBody<ResultList<ActorFollow>>({
27 defaultExpectedStatus: HttpStatusCode.OK_200
31 getFollowings (options: OverrideCommandOptions & {
36 actorType?: ActivityPubActorType
39 const path = '/api/v1/server/following'
41 const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]
42 const query = pick(options, toPick)
44 return this.getRequestBody<ResultList<ActorFollow>>({
50 defaultExpectedStatus: HttpStatusCode.OK_200
54 follow (options: OverrideCommandOptions & {
57 const path = '/api/v1/server/following'
59 const hosts = options.targets.map(f => f.replace(/^http:\/\//, ''))
61 return this.postBodyRequest({
67 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
71 async unfollow (options: OverrideCommandOptions & {
72 target: PeerTubeServer
74 const path = '/api/v1/server/following/' + options.target.host
76 return this.deleteRequest({
81 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
85 acceptFollower (options: OverrideCommandOptions & {
88 const path = '/api/v1/server/followers/' + options.follower + '/accept'
90 return this.postBodyRequest({
95 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
99 rejectFollower (options: OverrideCommandOptions & {
102 const path = '/api/v1/server/followers/' + options.follower + '/reject'
104 return this.postBodyRequest({
109 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
113 removeFollower (options: OverrideCommandOptions & {
114 follower: PeerTubeServer
116 const path = '/api/v1/server/followers/peertube@' + options.follower.host
118 return this.deleteRequest({
123 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204