1 import { pick } from 'lodash'
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 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 & {
58 const path = '/api/v1/server/following'
60 const fields: ServerFollowCreate = {}
63 fields.hosts = options.hosts.map(f => f.replace(/^http:\/\//, ''))
66 if (options.handles) {
67 fields.handles = options.handles
70 return this.postBodyRequest({
76 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
80 async unfollow (options: OverrideCommandOptions & {
81 target: PeerTubeServer | string
83 const { target } = options
85 const handle = typeof target === 'string'
89 const path = '/api/v1/server/following/' + handle
91 return this.deleteRequest({
96 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
100 acceptFollower (options: OverrideCommandOptions & {
103 const path = '/api/v1/server/followers/' + options.follower + '/accept'
105 return this.postBodyRequest({
110 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
114 rejectFollower (options: OverrideCommandOptions & {
117 const path = '/api/v1/server/followers/' + options.follower + '/reject'
119 return this.postBodyRequest({
124 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
128 removeFollower (options: OverrideCommandOptions & {
129 follower: PeerTubeServer
131 const path = '/api/v1/server/followers/peertube@' + options.follower.host
133 return this.deleteRequest({
138 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204