]>
Commit | Line | Data |
---|---|---|
c3d29f69 | 1 | import { pick } from 'lodash' |
4c7e60bc | 2 | import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList } from '@shared/models' |
c3d29f69 | 3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
254d3579 | 4 | import { PeerTubeServer } from './server' |
c3d29f69 C |
5 | |
6 | export class FollowsCommand extends AbstractCommand { | |
7 | ||
8 | getFollowers (options: OverrideCommandOptions & { | |
9 | start: number | |
10 | count: number | |
11 | sort: string | |
12 | search?: string | |
13 | actorType?: ActivityPubActorType | |
14 | state?: FollowState | |
15 | }) { | |
16 | const path = '/api/v1/server/followers' | |
17 | ||
18 | const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ] | |
19 | const query = pick(options, toPick) | |
20 | ||
21 | return this.getRequestBody<ResultList<ActorFollow>>({ | |
22 | ...options, | |
23 | ||
c3d29f69 C |
24 | path, |
25 | query, | |
a1637fa1 | 26 | implicitToken: false, |
c3d29f69 C |
27 | defaultExpectedStatus: HttpStatusCode.OK_200 |
28 | }) | |
29 | } | |
30 | ||
31 | getFollowings (options: OverrideCommandOptions & { | |
32 | start: number | |
33 | count: number | |
34 | sort: string | |
35 | search?: string | |
36 | actorType?: ActivityPubActorType | |
37 | state?: FollowState | |
38 | }) { | |
39 | const path = '/api/v1/server/following' | |
40 | ||
41 | const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ] | |
42 | const query = pick(options, toPick) | |
43 | ||
44 | return this.getRequestBody<ResultList<ActorFollow>>({ | |
45 | ...options, | |
46 | ||
c3d29f69 C |
47 | path, |
48 | query, | |
a1637fa1 | 49 | implicitToken: false, |
c3d29f69 C |
50 | defaultExpectedStatus: HttpStatusCode.OK_200 |
51 | }) | |
52 | } | |
53 | ||
54 | follow (options: OverrideCommandOptions & { | |
55 | targets: string[] | |
56 | }) { | |
57 | const path = '/api/v1/server/following' | |
58 | ||
59 | const hosts = options.targets.map(f => f.replace(/^http:\/\//, '')) | |
60 | ||
61 | return this.postBodyRequest({ | |
62 | ...options, | |
63 | ||
64 | path, | |
65 | fields: { hosts }, | |
a1637fa1 | 66 | implicitToken: true, |
c3d29f69 C |
67 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 |
68 | }) | |
69 | } | |
70 | ||
71 | async unfollow (options: OverrideCommandOptions & { | |
254d3579 | 72 | target: PeerTubeServer |
c3d29f69 C |
73 | }) { |
74 | const path = '/api/v1/server/following/' + options.target.host | |
75 | ||
76 | return this.deleteRequest({ | |
77 | ...options, | |
78 | ||
79 | path, | |
a1637fa1 | 80 | implicitToken: true, |
c3d29f69 C |
81 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 |
82 | }) | |
83 | } | |
84 | ||
85 | acceptFollower (options: OverrideCommandOptions & { | |
86 | follower: string | |
87 | }) { | |
88 | const path = '/api/v1/server/followers/' + options.follower + '/accept' | |
89 | ||
90 | return this.postBodyRequest({ | |
91 | ...options, | |
92 | ||
93 | path, | |
a1637fa1 | 94 | implicitToken: true, |
c3d29f69 C |
95 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 |
96 | }) | |
97 | } | |
98 | ||
99 | rejectFollower (options: OverrideCommandOptions & { | |
100 | follower: string | |
101 | }) { | |
102 | const path = '/api/v1/server/followers/' + options.follower + '/reject' | |
103 | ||
104 | return this.postBodyRequest({ | |
105 | ...options, | |
106 | ||
107 | path, | |
a1637fa1 | 108 | implicitToken: true, |
c3d29f69 C |
109 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 |
110 | }) | |
111 | } | |
112 | ||
113 | removeFollower (options: OverrideCommandOptions & { | |
254d3579 | 114 | follower: PeerTubeServer |
c3d29f69 C |
115 | }) { |
116 | const path = '/api/v1/server/followers/peertube@' + options.follower.host | |
117 | ||
118 | return this.deleteRequest({ | |
119 | ...options, | |
120 | ||
121 | path, | |
a1637fa1 | 122 | implicitToken: true, |
c3d29f69 C |
123 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 |
124 | }) | |
125 | } | |
126 | } |