1 import { pick } from '@shared/core-utils'
2 import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList, ServerFollowCreate } 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 query = pick(options, [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ])
20 return this.getRequestBody<ResultList<ActorFollow>>({
26 defaultExpectedStatus: HttpStatusCode.OK_200
30 getFollowings (options: OverrideCommandOptions & {
35 actorType?: ActivityPubActorType
38 const path = '/api/v1/server/following'
40 const query = pick(options, [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ])
42 return this.getRequestBody<ResultList<ActorFollow>>({
48 defaultExpectedStatus: HttpStatusCode.OK_200
52 follow (options: OverrideCommandOptions & {
56 const path = '/api/v1/server/following'
58 const fields: ServerFollowCreate = {}
61 fields.hosts = options.hosts.map(f => f.replace(/^http:\/\//, ''))
64 if (options.handles) {
65 fields.handles = options.handles
68 return this.postBodyRequest({
74 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
78 async unfollow (options: OverrideCommandOptions & {
79 target: PeerTubeServer | string
81 const { target } = options
83 const handle = typeof target === 'string'
87 const path = '/api/v1/server/following/' + handle
89 return this.deleteRequest({
94 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
98 acceptFollower (options: OverrideCommandOptions & {
101 const path = '/api/v1/server/followers/' + options.follower + '/accept'
103 return this.postBodyRequest({
108 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
112 rejectFollower (options: OverrideCommandOptions & {
115 const path = '/api/v1/server/followers/' + options.follower + '/reject'
117 return this.postBodyRequest({
122 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
126 removeFollower (options: OverrideCommandOptions & {
127 follower: PeerTubeServer
129 const path = '/api/v1/server/followers/peertube@' + options.follower.host
131 return this.deleteRequest({
136 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204