aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-20 14:15:15 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 13:35:31 +0200
commit4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef (patch)
tree20bcdd660ab4eb731814db3a4a40fffb48ce7482 /shared/extra-utils/server
parent7f28f2ddbaeecf451d501e99ded0408c14a33600 (diff)
downloadPeerTube-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')
-rw-r--r--shared/extra-utils/server/follows-command.ts35
-rw-r--r--shared/extra-utils/server/follows.ts4
2 files changed, 27 insertions, 12 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 @@
1import { pick } from 'lodash' 1import { pick } from 'lodash'
2import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList } from '@shared/models' 2import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList, ServerFollowCreate } from '@shared/models'
3import { AbstractCommand, OverrideCommandOptions } from '../shared' 3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4import { PeerTubeServer } from './server' 4import { 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,
diff --git a/shared/extra-utils/server/follows.ts b/shared/extra-utils/server/follows.ts
index 0188be1aa..698238f29 100644
--- a/shared/extra-utils/server/follows.ts
+++ b/shared/extra-utils/server/follows.ts
@@ -3,8 +3,8 @@ import { PeerTubeServer } from './server'
3 3
4async function doubleFollow (server1: PeerTubeServer, server2: PeerTubeServer) { 4async function doubleFollow (server1: PeerTubeServer, server2: PeerTubeServer) {
5 await Promise.all([ 5 await Promise.all([
6 server1.follows.follow({ targets: [ server2.url ] }), 6 server1.follows.follow({ hosts: [ server2.url ] }),
7 server2.follows.follow({ targets: [ server1.url ] }) 7 server2.follows.follow({ hosts: [ server1.url ] })
8 ]) 8 ])
9 9
10 // Wait request propagation 10 // Wait request propagation