diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-20 14:15:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 13:35:31 +0200 |
commit | 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef (patch) | |
tree | 20bcdd660ab4eb731814db3a4a40fffb48ce7482 /shared/extra-utils/server/follows-command.ts | |
parent | 7f28f2ddbaeecf451d501e99ded0408c14a33600 (diff) | |
download | PeerTube-4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef.tar.gz PeerTube-4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef.tar.zst PeerTube-4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef.zip |
Add ability for instances to follow any actor
Diffstat (limited to 'shared/extra-utils/server/follows-command.ts')
-rw-r--r-- | shared/extra-utils/server/follows-command.ts | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts index dce674ac5..2b889cf66 100644 --- a/shared/extra-utils/server/follows-command.ts +++ b/shared/extra-utils/server/follows-command.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { pick } from 'lodash' | 1 | import { pick } from 'lodash' |
2 | import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList } from '@shared/models' | 2 | import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList, ServerFollowCreate } from '@shared/models' |
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | 3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
4 | import { PeerTubeServer } from './server' | 4 | import { PeerTubeServer } from './server' |
5 | 5 | ||
@@ -29,13 +29,13 @@ export class FollowsCommand extends AbstractCommand { | |||
29 | } | 29 | } |
30 | 30 | ||
31 | getFollowings (options: OverrideCommandOptions & { | 31 | getFollowings (options: OverrideCommandOptions & { |
32 | start: number | 32 | start?: number |
33 | count: number | 33 | count?: number |
34 | sort: string | 34 | sort?: string |
35 | search?: string | 35 | search?: string |
36 | actorType?: ActivityPubActorType | 36 | actorType?: ActivityPubActorType |
37 | state?: FollowState | 37 | state?: FollowState |
38 | }) { | 38 | } = {}) { |
39 | const path = '/api/v1/server/following' | 39 | const path = '/api/v1/server/following' |
40 | 40 | ||
41 | const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ] | 41 | const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ] |
@@ -52,26 +52,41 @@ export class FollowsCommand extends AbstractCommand { | |||
52 | } | 52 | } |
53 | 53 | ||
54 | follow (options: OverrideCommandOptions & { | 54 | follow (options: OverrideCommandOptions & { |
55 | targets: string[] | 55 | hosts?: string[] |
56 | handles?: string[] | ||
56 | }) { | 57 | }) { |
57 | const path = '/api/v1/server/following' | 58 | const path = '/api/v1/server/following' |
58 | 59 | ||
59 | const hosts = options.targets.map(f => f.replace(/^http:\/\//, '')) | 60 | const fields: ServerFollowCreate = {} |
61 | |||
62 | if (options.hosts) { | ||
63 | fields.hosts = options.hosts.map(f => f.replace(/^http:\/\//, '')) | ||
64 | } | ||
65 | |||
66 | if (options.handles) { | ||
67 | fields.handles = options.handles | ||
68 | } | ||
60 | 69 | ||
61 | return this.postBodyRequest({ | 70 | return this.postBodyRequest({ |
62 | ...options, | 71 | ...options, |
63 | 72 | ||
64 | path, | 73 | path, |
65 | fields: { hosts }, | 74 | fields, |
66 | implicitToken: true, | 75 | implicitToken: true, |
67 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | 76 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 |
68 | }) | 77 | }) |
69 | } | 78 | } |
70 | 79 | ||
71 | async unfollow (options: OverrideCommandOptions & { | 80 | async unfollow (options: OverrideCommandOptions & { |
72 | target: PeerTubeServer | 81 | target: PeerTubeServer | string |
73 | }) { | 82 | }) { |
74 | const path = '/api/v1/server/following/' + options.target.host | 83 | const { target } = options |
84 | |||
85 | const handle = typeof target === 'string' | ||
86 | ? target | ||
87 | : target.host | ||
88 | |||
89 | const path = '/api/v1/server/following/' + handle | ||
75 | 90 | ||
76 | return this.deleteRequest({ | 91 | return this.deleteRequest({ |
77 | ...options, | 92 | ...options, |