aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
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
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')
-rw-r--r--shared/extra-utils/server/follows-command.ts35
-rw-r--r--shared/extra-utils/server/follows.ts4
-rw-r--r--shared/extra-utils/users/actors.ts (renamed from shared/extra-utils/users/accounts.ts)43
-rw-r--r--shared/extra-utils/users/index.ts2
-rw-r--r--shared/extra-utils/videos/comments-command.ts21
-rw-r--r--shared/extra-utils/videos/videos-command.ts10
-rw-r--r--shared/models/server/index.ts1
-rw-r--r--shared/models/server/server-follow-create.model.ts4
8 files changed, 100 insertions, 20 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
diff --git a/shared/extra-utils/users/accounts.ts b/shared/extra-utils/users/actors.ts
index 9fc1bcfc4..cfcc7d0a7 100644
--- a/shared/extra-utils/users/accounts.ts
+++ b/shared/extra-utils/users/actors.ts
@@ -4,22 +4,31 @@ import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path' 5import { join } from 'path'
6import { root } from '@server/helpers/core-utils' 6import { root } from '@server/helpers/core-utils'
7import { Account, VideoChannel } from '@shared/models'
7import { PeerTubeServer } from '../server' 8import { PeerTubeServer } from '../server'
8 9
9async function expectAccountFollows (options: { 10async function expectChannelsFollows (options: {
10 server: PeerTubeServer 11 server: PeerTubeServer
11 handle: string 12 handle: string
12 followers: number 13 followers: number
13 following: number 14 following: number
14}) { 15}) {
15 const { server, handle, followers, following } = options 16 const { server } = options
17 const { data } = await server.channels.list()
16 18
17 const body = await server.accounts.list() 19 return expectActorFollow({ ...options, data })
18 const account = body.data.find(a => a.name + '@' + a.host === handle) 20}
19 21
20 const message = `${handle} on ${server.url}` 22async function expectAccountFollows (options: {
21 expect(account.followersCount).to.equal(followers, message) 23 server: PeerTubeServer
22 expect(account.followingCount).to.equal(following, message) 24 handle: string
25 followers: number
26 following: number
27}) {
28 const { server } = options
29 const { data } = await server.accounts.list()
30
31 return expectActorFollow({ ...options, data })
23} 32}
24 33
25async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { 34async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
@@ -40,5 +49,25 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe
40 49
41export { 50export {
42 expectAccountFollows, 51 expectAccountFollows,
52 expectChannelsFollows,
43 checkActorFilesWereRemoved 53 checkActorFilesWereRemoved
44} 54}
55
56// ---------------------------------------------------------------------------
57
58function expectActorFollow (options: {
59 server: PeerTubeServer
60 data: (Account | VideoChannel)[]
61 handle: string
62 followers: number
63 following: number
64}) {
65 const { server, data, handle, followers, following } = options
66
67 const actor = data.find(a => a.name + '@' + a.host === handle)
68 const message = `${handle} on ${server.url}`
69
70 expect(actor, message).to.exist
71 expect(actor.followersCount).to.equal(followers, message)
72 expect(actor.followingCount).to.equal(following, message)
73}
diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.ts
index fbb454e8f..460a06f70 100644
--- a/shared/extra-utils/users/index.ts
+++ b/shared/extra-utils/users/index.ts
@@ -1,5 +1,5 @@
1export * from './accounts-command' 1export * from './accounts-command'
2export * from './accounts' 2export * from './actors'
3export * from './blocklist-command' 3export * from './blocklist-command'
4export * from './login' 4export * from './login'
5export * from './login-command' 5export * from './login-command'
diff --git a/shared/extra-utils/videos/comments-command.ts b/shared/extra-utils/videos/comments-command.ts
index dd14e4b64..5034c57ad 100644
--- a/shared/extra-utils/videos/comments-command.ts
+++ b/shared/extra-utils/videos/comments-command.ts
@@ -5,6 +5,10 @@ import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 5
6export class CommentsCommand extends AbstractCommand { 6export class CommentsCommand extends AbstractCommand {
7 7
8 private lastVideoId: number | string
9 private lastThreadId: number
10 private lastReplyId: number
11
8 listForAdmin (options: OverrideCommandOptions & { 12 listForAdmin (options: OverrideCommandOptions & {
9 start?: number 13 start?: number
10 count?: number 14 count?: number
@@ -80,6 +84,9 @@ export class CommentsCommand extends AbstractCommand {
80 defaultExpectedStatus: HttpStatusCode.OK_200 84 defaultExpectedStatus: HttpStatusCode.OK_200
81 })) 85 }))
82 86
87 this.lastThreadId = body.comment.id
88 this.lastVideoId = videoId
89
83 return body.comment 90 return body.comment
84 } 91 }
85 92
@@ -100,9 +107,23 @@ export class CommentsCommand extends AbstractCommand {
100 defaultExpectedStatus: HttpStatusCode.OK_200 107 defaultExpectedStatus: HttpStatusCode.OK_200
101 })) 108 }))
102 109
110 this.lastReplyId = body.comment.id
111
103 return body.comment 112 return body.comment
104 } 113 }
105 114
115 async addReplyToLastReply (options: OverrideCommandOptions & {
116 text: string
117 }) {
118 return this.addReply({ ...options, videoId: this.lastVideoId, toCommentId: this.lastReplyId })
119 }
120
121 async addReplyToLastThread (options: OverrideCommandOptions & {
122 text: string
123 }) {
124 return this.addReply({ ...options, videoId: this.lastVideoId, toCommentId: this.lastThreadId })
125 }
126
106 async findCommentId (options: OverrideCommandOptions & { 127 async findCommentId (options: OverrideCommandOptions & {
107 videoId: number | string 128 videoId: number | string
108 text: string 129 text: string
diff --git a/shared/extra-utils/videos/videos-command.ts b/shared/extra-utils/videos/videos-command.ts
index 40cc4dc28..98465e8f6 100644
--- a/shared/extra-utils/videos/videos-command.ts
+++ b/shared/extra-utils/videos/videos-command.ts
@@ -267,6 +267,16 @@ export class VideosCommand extends AbstractCommand {
267 267
268 // --------------------------------------------------------------------------- 268 // ---------------------------------------------------------------------------
269 269
270 async find (options: OverrideCommandOptions & {
271 name: string
272 }) {
273 const { data } = await this.list(options)
274
275 return data.find(v => v.name === options.name)
276 }
277
278 // ---------------------------------------------------------------------------
279
270 update (options: OverrideCommandOptions & { 280 update (options: OverrideCommandOptions & {
271 id: number | string 281 id: number | string
272 attributes?: VideoEdit 282 attributes?: VideoEdit
diff --git a/shared/models/server/index.ts b/shared/models/server/index.ts
index 06bf5c599..0f7646c7a 100644
--- a/shared/models/server/index.ts
+++ b/shared/models/server/index.ts
@@ -10,4 +10,5 @@ export * from './peertube-problem-document.model'
10export * from './server-config.model' 10export * from './server-config.model'
11export * from './server-debug.model' 11export * from './server-debug.model'
12export * from './server-error-code.enum' 12export * from './server-error-code.enum'
13export * from './server-follow-create.model'
13export * from './server-stats.model' 14export * from './server-stats.model'
diff --git a/shared/models/server/server-follow-create.model.ts b/shared/models/server/server-follow-create.model.ts
new file mode 100644
index 000000000..3f90c7d6f
--- /dev/null
+++ b/shared/models/server/server-follow-create.model.ts
@@ -0,0 +1,4 @@
1export interface ServerFollowCreate {
2 hosts?: string[]
3 handles?: string[]
4}