aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-17 09:29:23 +0100
committerChocobozzz <me@florianbigard.com>2021-12-17 09:29:23 +0100
commitbf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (patch)
tree54b40aaf01bae210632473285c3c7571d51e4f89 /shared/extra-utils/server
parent6b5f72beda96d8b7e4d6329c4001827334de27dd (diff)
downloadPeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.gz
PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.zst
PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.zip
shared/ typescript types dir server-commands
Diffstat (limited to 'shared/extra-utils/server')
-rw-r--r--shared/extra-utils/server/config-command.ts353
-rw-r--r--shared/extra-utils/server/contact-form-command.ts31
-rw-r--r--shared/extra-utils/server/debug-command.ts33
-rw-r--r--shared/extra-utils/server/directories.ts34
-rw-r--r--shared/extra-utils/server/follows-command.ts139
-rw-r--r--shared/extra-utils/server/follows.ts20
-rw-r--r--shared/extra-utils/server/index.ts17
-rw-r--r--shared/extra-utils/server/jobs-command.ts61
-rw-r--r--shared/extra-utils/server/jobs.ts84
-rw-r--r--shared/extra-utils/server/object-storage-command.ts77
-rw-r--r--shared/extra-utils/server/plugins-command.ts257
-rw-r--r--shared/extra-utils/server/plugins.ts18
-rw-r--r--shared/extra-utils/server/redundancy-command.ts80
-rw-r--r--shared/extra-utils/server/server.ts392
-rw-r--r--shared/extra-utils/server/servers-command.ts92
-rw-r--r--shared/extra-utils/server/servers.ts49
-rw-r--r--shared/extra-utils/server/stats-command.ts25
-rw-r--r--shared/extra-utils/server/tracker.ts27
18 files changed, 0 insertions, 1789 deletions
diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts
deleted file mode 100644
index 89ae8eb4f..000000000
--- a/shared/extra-utils/server/config-command.ts
+++ /dev/null
@@ -1,353 +0,0 @@
1import { merge } from 'lodash'
2import { DeepPartial } from '@shared/typescript-utils'
3import { About, HttpStatusCode, ServerConfig } from '@shared/models'
4import { CustomConfig } from '../../models/server/custom-config.model'
5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6
7export class ConfigCommand extends AbstractCommand {
8
9 static getCustomConfigResolutions (enabled: boolean) {
10 return {
11 '144p': enabled,
12 '240p': enabled,
13 '360p': enabled,
14 '480p': enabled,
15 '720p': enabled,
16 '1080p': enabled,
17 '1440p': enabled,
18 '2160p': enabled
19 }
20 }
21
22 enableImports () {
23 return this.updateExistingSubConfig({
24 newConfig: {
25 import: {
26 videos: {
27 http: {
28 enabled: true
29 },
30
31 torrent: {
32 enabled: true
33 }
34 }
35 }
36 }
37 })
38 }
39
40 enableLive (options: {
41 allowReplay?: boolean
42 transcoding?: boolean
43 } = {}) {
44 return this.updateExistingSubConfig({
45 newConfig: {
46 live: {
47 enabled: true,
48 allowReplay: options.allowReplay ?? true,
49 transcoding: {
50 enabled: options.transcoding ?? true,
51 resolutions: ConfigCommand.getCustomConfigResolutions(true)
52 }
53 }
54 }
55 })
56 }
57
58 disableTranscoding () {
59 return this.updateExistingSubConfig({
60 newConfig: {
61 transcoding: {
62 enabled: false
63 }
64 }
65 })
66 }
67
68 enableTranscoding (webtorrent = true, hls = true) {
69 return this.updateExistingSubConfig({
70 newConfig: {
71 transcoding: {
72 enabled: true,
73 resolutions: ConfigCommand.getCustomConfigResolutions(true),
74
75 webtorrent: {
76 enabled: webtorrent
77 },
78 hls: {
79 enabled: hls
80 }
81 }
82 }
83 })
84 }
85
86 getConfig (options: OverrideCommandOptions = {}) {
87 const path = '/api/v1/config'
88
89 return this.getRequestBody<ServerConfig>({
90 ...options,
91
92 path,
93 implicitToken: false,
94 defaultExpectedStatus: HttpStatusCode.OK_200
95 })
96 }
97
98 getAbout (options: OverrideCommandOptions = {}) {
99 const path = '/api/v1/config/about'
100
101 return this.getRequestBody<About>({
102 ...options,
103
104 path,
105 implicitToken: false,
106 defaultExpectedStatus: HttpStatusCode.OK_200
107 })
108 }
109
110 getCustomConfig (options: OverrideCommandOptions = {}) {
111 const path = '/api/v1/config/custom'
112
113 return this.getRequestBody<CustomConfig>({
114 ...options,
115
116 path,
117 implicitToken: true,
118 defaultExpectedStatus: HttpStatusCode.OK_200
119 })
120 }
121
122 updateCustomConfig (options: OverrideCommandOptions & {
123 newCustomConfig: CustomConfig
124 }) {
125 const path = '/api/v1/config/custom'
126
127 return this.putBodyRequest({
128 ...options,
129
130 path,
131 fields: options.newCustomConfig,
132 implicitToken: true,
133 defaultExpectedStatus: HttpStatusCode.OK_200
134 })
135 }
136
137 deleteCustomConfig (options: OverrideCommandOptions = {}) {
138 const path = '/api/v1/config/custom'
139
140 return this.deleteRequest({
141 ...options,
142
143 path,
144 implicitToken: true,
145 defaultExpectedStatus: HttpStatusCode.OK_200
146 })
147 }
148
149 async updateExistingSubConfig (options: OverrideCommandOptions & {
150 newConfig: DeepPartial<CustomConfig>
151 }) {
152 const existing = await this.getCustomConfig(options)
153
154 return this.updateCustomConfig({ ...options, newCustomConfig: merge({}, existing, options.newConfig) })
155 }
156
157 updateCustomSubConfig (options: OverrideCommandOptions & {
158 newConfig: DeepPartial<CustomConfig>
159 }) {
160 const newCustomConfig: CustomConfig = {
161 instance: {
162 name: 'PeerTube updated',
163 shortDescription: 'my short description',
164 description: 'my super description',
165 terms: 'my super terms',
166 codeOfConduct: 'my super coc',
167
168 creationReason: 'my super creation reason',
169 moderationInformation: 'my super moderation information',
170 administrator: 'Kuja',
171 maintenanceLifetime: 'forever',
172 businessModel: 'my super business model',
173 hardwareInformation: '2vCore 3GB RAM',
174
175 languages: [ 'en', 'es' ],
176 categories: [ 1, 2 ],
177
178 isNSFW: true,
179 defaultNSFWPolicy: 'blur',
180
181 defaultClientRoute: '/videos/recently-added',
182
183 customizations: {
184 javascript: 'alert("coucou")',
185 css: 'body { background-color: red; }'
186 }
187 },
188 theme: {
189 default: 'default'
190 },
191 services: {
192 twitter: {
193 username: '@MySuperUsername',
194 whitelisted: true
195 }
196 },
197 client: {
198 videos: {
199 miniature: {
200 preferAuthorDisplayName: false
201 }
202 },
203 menu: {
204 login: {
205 redirectOnSingleExternalAuth: false
206 }
207 }
208 },
209 cache: {
210 previews: {
211 size: 2
212 },
213 captions: {
214 size: 3
215 },
216 torrents: {
217 size: 4
218 }
219 },
220 signup: {
221 enabled: false,
222 limit: 5,
223 requiresEmailVerification: false,
224 minimumAge: 16
225 },
226 admin: {
227 email: 'superadmin1@example.com'
228 },
229 contactForm: {
230 enabled: true
231 },
232 user: {
233 videoQuota: 5242881,
234 videoQuotaDaily: 318742
235 },
236 videoChannels: {
237 maxPerUser: 20
238 },
239 transcoding: {
240 enabled: true,
241 allowAdditionalExtensions: true,
242 allowAudioFiles: true,
243 threads: 1,
244 concurrency: 3,
245 profile: 'default',
246 resolutions: {
247 '0p': false,
248 '144p': false,
249 '240p': false,
250 '360p': true,
251 '480p': true,
252 '720p': false,
253 '1080p': false,
254 '1440p': false,
255 '2160p': false
256 },
257 webtorrent: {
258 enabled: true
259 },
260 hls: {
261 enabled: false
262 }
263 },
264 live: {
265 enabled: true,
266 allowReplay: false,
267 maxDuration: -1,
268 maxInstanceLives: -1,
269 maxUserLives: 50,
270 transcoding: {
271 enabled: true,
272 threads: 4,
273 profile: 'default',
274 resolutions: {
275 '144p': true,
276 '240p': true,
277 '360p': true,
278 '480p': true,
279 '720p': true,
280 '1080p': true,
281 '1440p': true,
282 '2160p': true
283 }
284 }
285 },
286 import: {
287 videos: {
288 concurrency: 3,
289 http: {
290 enabled: false
291 },
292 torrent: {
293 enabled: false
294 }
295 }
296 },
297 trending: {
298 videos: {
299 algorithms: {
300 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
301 default: 'hot'
302 }
303 }
304 },
305 autoBlacklist: {
306 videos: {
307 ofUsers: {
308 enabled: false
309 }
310 }
311 },
312 followers: {
313 instance: {
314 enabled: true,
315 manualApproval: false
316 }
317 },
318 followings: {
319 instance: {
320 autoFollowBack: {
321 enabled: false
322 },
323 autoFollowIndex: {
324 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
325 enabled: false
326 }
327 }
328 },
329 broadcastMessage: {
330 enabled: true,
331 level: 'warning',
332 message: 'hello',
333 dismissable: true
334 },
335 search: {
336 remoteUri: {
337 users: true,
338 anonymous: true
339 },
340 searchIndex: {
341 enabled: true,
342 url: 'https://search.joinpeertube.org',
343 disableLocalSearch: true,
344 isDefaultSearch: true
345 }
346 }
347 }
348
349 merge(newCustomConfig, options.newConfig)
350
351 return this.updateCustomConfig({ ...options, newCustomConfig })
352 }
353}
diff --git a/shared/extra-utils/server/contact-form-command.ts b/shared/extra-utils/server/contact-form-command.ts
deleted file mode 100644
index 0e8fd6d84..000000000
--- a/shared/extra-utils/server/contact-form-command.ts
+++ /dev/null
@@ -1,31 +0,0 @@
1import { HttpStatusCode } from '@shared/models'
2import { ContactForm } from '../../models/server'
3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4
5export class ContactFormCommand extends AbstractCommand {
6
7 send (options: OverrideCommandOptions & {
8 fromEmail: string
9 fromName: string
10 subject: string
11 body: string
12 }) {
13 const path = '/api/v1/server/contact'
14
15 const body: ContactForm = {
16 fromEmail: options.fromEmail,
17 fromName: options.fromName,
18 subject: options.subject,
19 body: options.body
20 }
21
22 return this.postBodyRequest({
23 ...options,
24
25 path,
26 fields: body,
27 implicitToken: false,
28 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
29 })
30 }
31}
diff --git a/shared/extra-utils/server/debug-command.ts b/shared/extra-utils/server/debug-command.ts
deleted file mode 100644
index 3c5a785bb..000000000
--- a/shared/extra-utils/server/debug-command.ts
+++ /dev/null
@@ -1,33 +0,0 @@
1import { Debug, HttpStatusCode, SendDebugCommand } from '@shared/models'
2import { AbstractCommand, OverrideCommandOptions } from '../shared'
3
4export class DebugCommand extends AbstractCommand {
5
6 getDebug (options: OverrideCommandOptions = {}) {
7 const path = '/api/v1/server/debug'
8
9 return this.getRequestBody<Debug>({
10 ...options,
11
12 path,
13 implicitToken: true,
14 defaultExpectedStatus: HttpStatusCode.OK_200
15 })
16 }
17
18 sendCommand (options: OverrideCommandOptions & {
19 body: SendDebugCommand
20 }) {
21 const { body } = options
22 const path = '/api/v1/server/debug/run-command'
23
24 return this.postBodyRequest({
25 ...options,
26
27 path,
28 fields: body,
29 implicitToken: true,
30 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
31 })
32 }
33}
diff --git a/shared/extra-utils/server/directories.ts b/shared/extra-utils/server/directories.ts
deleted file mode 100644
index e6f72d6fc..000000000
--- a/shared/extra-utils/server/directories.ts
+++ /dev/null
@@ -1,34 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra'
5import { join } from 'path'
6import { root } from '@shared/core-utils'
7import { PeerTubeServer } from './server'
8
9async function checkTmpIsEmpty (server: PeerTubeServer) {
10 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])
11
12 if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) {
13 await checkDirectoryIsEmpty(server, 'tmp/hls')
14 }
15}
16
17async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) {
18 const testDirectory = 'test' + server.internalServerNumber
19
20 const directoryPath = join(root(), testDirectory, directory)
21
22 const directoryExists = await pathExists(directoryPath)
23 expect(directoryExists).to.be.true
24
25 const files = await readdir(directoryPath)
26 const filtered = files.filter(f => exceptions.includes(f) === false)
27
28 expect(filtered).to.have.lengthOf(0)
29}
30
31export {
32 checkTmpIsEmpty,
33 checkDirectoryIsEmpty
34}
diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts
deleted file mode 100644
index 01ef6f179..000000000
--- a/shared/extra-utils/server/follows-command.ts
+++ /dev/null
@@ -1,139 +0,0 @@
1import { pick } from '@shared/core-utils'
2import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList, ServerFollowCreate } from '@shared/models'
3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4import { PeerTubeServer } from './server'
5
6export 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 query = pick(options, [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ])
19
20 return this.getRequestBody<ResultList<ActorFollow>>({
21 ...options,
22
23 path,
24 query,
25 implicitToken: false,
26 defaultExpectedStatus: HttpStatusCode.OK_200
27 })
28 }
29
30 getFollowings (options: OverrideCommandOptions & {
31 start?: number
32 count?: number
33 sort?: string
34 search?: string
35 actorType?: ActivityPubActorType
36 state?: FollowState
37 } = {}) {
38 const path = '/api/v1/server/following'
39
40 const query = pick(options, [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ])
41
42 return this.getRequestBody<ResultList<ActorFollow>>({
43 ...options,
44
45 path,
46 query,
47 implicitToken: false,
48 defaultExpectedStatus: HttpStatusCode.OK_200
49 })
50 }
51
52 follow (options: OverrideCommandOptions & {
53 hosts?: string[]
54 handles?: string[]
55 }) {
56 const path = '/api/v1/server/following'
57
58 const fields: ServerFollowCreate = {}
59
60 if (options.hosts) {
61 fields.hosts = options.hosts.map(f => f.replace(/^http:\/\//, ''))
62 }
63
64 if (options.handles) {
65 fields.handles = options.handles
66 }
67
68 return this.postBodyRequest({
69 ...options,
70
71 path,
72 fields,
73 implicitToken: true,
74 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
75 })
76 }
77
78 async unfollow (options: OverrideCommandOptions & {
79 target: PeerTubeServer | string
80 }) {
81 const { target } = options
82
83 const handle = typeof target === 'string'
84 ? target
85 : target.host
86
87 const path = '/api/v1/server/following/' + handle
88
89 return this.deleteRequest({
90 ...options,
91
92 path,
93 implicitToken: true,
94 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
95 })
96 }
97
98 acceptFollower (options: OverrideCommandOptions & {
99 follower: string
100 }) {
101 const path = '/api/v1/server/followers/' + options.follower + '/accept'
102
103 return this.postBodyRequest({
104 ...options,
105
106 path,
107 implicitToken: true,
108 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
109 })
110 }
111
112 rejectFollower (options: OverrideCommandOptions & {
113 follower: string
114 }) {
115 const path = '/api/v1/server/followers/' + options.follower + '/reject'
116
117 return this.postBodyRequest({
118 ...options,
119
120 path,
121 implicitToken: true,
122 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
123 })
124 }
125
126 removeFollower (options: OverrideCommandOptions & {
127 follower: PeerTubeServer
128 }) {
129 const path = '/api/v1/server/followers/peertube@' + options.follower.host
130
131 return this.deleteRequest({
132 ...options,
133
134 path,
135 implicitToken: true,
136 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
137 })
138 }
139}
diff --git a/shared/extra-utils/server/follows.ts b/shared/extra-utils/server/follows.ts
deleted file mode 100644
index 698238f29..000000000
--- a/shared/extra-utils/server/follows.ts
+++ /dev/null
@@ -1,20 +0,0 @@
1import { waitJobs } from './jobs'
2import { PeerTubeServer } from './server'
3
4async function doubleFollow (server1: PeerTubeServer, server2: PeerTubeServer) {
5 await Promise.all([
6 server1.follows.follow({ hosts: [ server2.url ] }),
7 server2.follows.follow({ hosts: [ server1.url ] })
8 ])
9
10 // Wait request propagation
11 await waitJobs([ server1, server2 ])
12
13 return true
14}
15
16// ---------------------------------------------------------------------------
17
18export {
19 doubleFollow
20}
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts
deleted file mode 100644
index 76a2099da..000000000
--- a/shared/extra-utils/server/index.ts
+++ /dev/null
@@ -1,17 +0,0 @@
1export * from './config-command'
2export * from './contact-form-command'
3export * from './debug-command'
4export * from './directories'
5export * from './follows-command'
6export * from './follows'
7export * from './jobs'
8export * from './jobs-command'
9export * from './object-storage-command'
10export * from './plugins-command'
11export * from './plugins'
12export * from './redundancy-command'
13export * from './server'
14export * from './servers-command'
15export * from './servers'
16export * from './stats-command'
17export * from './tracker'
diff --git a/shared/extra-utils/server/jobs-command.ts b/shared/extra-utils/server/jobs-command.ts
deleted file mode 100644
index 6636e7e4d..000000000
--- a/shared/extra-utils/server/jobs-command.ts
+++ /dev/null
@@ -1,61 +0,0 @@
1import { pick } from '@shared/core-utils'
2import { HttpStatusCode } from '@shared/models'
3import { Job, JobState, JobType, ResultList } from '../../models'
4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5
6export class JobsCommand extends AbstractCommand {
7
8 async getLatest (options: OverrideCommandOptions & {
9 jobType: JobType
10 }) {
11 const { data } = await this.list({ ...options, start: 0, count: 1, sort: '-createdAt' })
12
13 if (data.length === 0) return undefined
14
15 return data[0]
16 }
17
18 list (options: OverrideCommandOptions & {
19 state?: JobState
20 jobType?: JobType
21 start?: number
22 count?: number
23 sort?: string
24 } = {}) {
25 const path = this.buildJobsUrl(options.state)
26
27 const query = pick(options, [ 'start', 'count', 'sort', 'jobType' ])
28
29 return this.getRequestBody<ResultList<Job>>({
30 ...options,
31
32 path,
33 query,
34 implicitToken: true,
35 defaultExpectedStatus: HttpStatusCode.OK_200
36 })
37 }
38
39 listFailed (options: OverrideCommandOptions & {
40 jobType?: JobType
41 }) {
42 const path = this.buildJobsUrl('failed')
43
44 return this.getRequestBody<ResultList<Job>>({
45 ...options,
46
47 path,
48 query: { start: 0, count: 50 },
49 implicitToken: true,
50 defaultExpectedStatus: HttpStatusCode.OK_200
51 })
52 }
53
54 private buildJobsUrl (state?: JobState) {
55 let path = '/api/v1/jobs'
56
57 if (state) path += '/' + state
58
59 return path
60 }
61}
diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts
deleted file mode 100644
index 34fefd444..000000000
--- a/shared/extra-utils/server/jobs.ts
+++ /dev/null
@@ -1,84 +0,0 @@
1
2import { expect } from 'chai'
3import { JobState, JobType } from '../../models'
4import { wait } from '../miscs'
5import { PeerTubeServer } from './server'
6
7async function waitJobs (serversArg: PeerTubeServer[] | PeerTubeServer, skipDelayed = false) {
8 const pendingJobWait = process.env.NODE_PENDING_JOB_WAIT
9 ? parseInt(process.env.NODE_PENDING_JOB_WAIT, 10)
10 : 250
11
12 let servers: PeerTubeServer[]
13
14 if (Array.isArray(serversArg) === false) servers = [ serversArg as PeerTubeServer ]
15 else servers = serversArg as PeerTubeServer[]
16
17 const states: JobState[] = [ 'waiting', 'active' ]
18 if (!skipDelayed) states.push('delayed')
19
20 const repeatableJobs: JobType[] = [ 'videos-views-stats', 'activitypub-cleaner' ]
21 let pendingRequests: boolean
22
23 function tasksBuilder () {
24 const tasks: Promise<any>[] = []
25
26 // Check if each server has pending request
27 for (const server of servers) {
28 for (const state of states) {
29 const p = server.jobs.list({
30 state,
31 start: 0,
32 count: 10,
33 sort: '-createdAt'
34 }).then(body => body.data)
35 .then(jobs => jobs.filter(j => !repeatableJobs.includes(j.type)))
36 .then(jobs => {
37 if (jobs.length !== 0) {
38 pendingRequests = true
39 }
40 })
41
42 tasks.push(p)
43 }
44
45 const p = server.debug.getDebug()
46 .then(obj => {
47 if (obj.activityPubMessagesWaiting !== 0) {
48 pendingRequests = true
49 }
50 })
51
52 tasks.push(p)
53 }
54
55 return tasks
56 }
57
58 do {
59 pendingRequests = false
60 await Promise.all(tasksBuilder())
61
62 // Retry, in case of new jobs were created
63 if (pendingRequests === false) {
64 await wait(pendingJobWait)
65 await Promise.all(tasksBuilder())
66 }
67
68 if (pendingRequests) {
69 await wait(pendingJobWait)
70 }
71 } while (pendingRequests)
72}
73
74async function expectNoFailedTranscodingJob (server: PeerTubeServer) {
75 const { data } = await server.jobs.listFailed({ jobType: 'video-transcoding' })
76 expect(data).to.have.lengthOf(0)
77}
78
79// ---------------------------------------------------------------------------
80
81export {
82 waitJobs,
83 expectNoFailedTranscodingJob
84}
diff --git a/shared/extra-utils/server/object-storage-command.ts b/shared/extra-utils/server/object-storage-command.ts
deleted file mode 100644
index b4de8f4cb..000000000
--- a/shared/extra-utils/server/object-storage-command.ts
+++ /dev/null
@@ -1,77 +0,0 @@
1
2import { HttpStatusCode } from '@shared/models'
3import { makePostBodyRequest } from '../requests'
4import { AbstractCommand } from '../shared'
5
6export class ObjectStorageCommand extends AbstractCommand {
7 static readonly DEFAULT_PLAYLIST_BUCKET = 'streaming-playlists'
8 static readonly DEFAULT_WEBTORRENT_BUCKET = 'videos'
9
10 static getDefaultConfig () {
11 return {
12 object_storage: {
13 enabled: true,
14 endpoint: 'http://' + this.getEndpointHost(),
15 region: this.getRegion(),
16
17 credentials: this.getCredentialsConfig(),
18
19 streaming_playlists: {
20 bucket_name: this.DEFAULT_PLAYLIST_BUCKET
21 },
22
23 videos: {
24 bucket_name: this.DEFAULT_WEBTORRENT_BUCKET
25 }
26 }
27 }
28 }
29
30 static getCredentialsConfig () {
31 return {
32 access_key_id: 'AKIAIOSFODNN7EXAMPLE',
33 secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
34 }
35 }
36
37 static getEndpointHost () {
38 return 'localhost:9444'
39 }
40
41 static getRegion () {
42 return 'us-east-1'
43 }
44
45 static getWebTorrentBaseUrl () {
46 return `http://${this.DEFAULT_WEBTORRENT_BUCKET}.${this.getEndpointHost()}/`
47 }
48
49 static getPlaylistBaseUrl () {
50 return `http://${this.DEFAULT_PLAYLIST_BUCKET}.${this.getEndpointHost()}/`
51 }
52
53 static async prepareDefaultBuckets () {
54 await this.createBucket(this.DEFAULT_PLAYLIST_BUCKET)
55 await this.createBucket(this.DEFAULT_WEBTORRENT_BUCKET)
56 }
57
58 static async createBucket (name: string) {
59 await makePostBodyRequest({
60 url: this.getEndpointHost(),
61 path: '/ui/' + name + '?delete',
62 expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
63 })
64
65 await makePostBodyRequest({
66 url: this.getEndpointHost(),
67 path: '/ui/' + name + '?create',
68 expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
69 })
70
71 await makePostBodyRequest({
72 url: this.getEndpointHost(),
73 path: '/ui/' + name + '?make-public',
74 expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
75 })
76 }
77}
diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.ts
deleted file mode 100644
index 1c44711da..000000000
--- a/shared/extra-utils/server/plugins-command.ts
+++ /dev/null
@@ -1,257 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { readJSON, writeJSON } from 'fs-extra'
4import { join } from 'path'
5import { root } from '@shared/core-utils'
6import {
7 HttpStatusCode,
8 PeerTubePlugin,
9 PeerTubePluginIndex,
10 PeertubePluginIndexList,
11 PluginPackageJson,
12 PluginTranslation,
13 PluginType,
14 PublicServerSetting,
15 RegisteredServerSettings,
16 ResultList
17} from '@shared/models'
18import { AbstractCommand, OverrideCommandOptions } from '../shared'
19
20export class PluginsCommand extends AbstractCommand {
21
22 static getPluginTestPath (suffix = '') {
23 return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)
24 }
25
26 list (options: OverrideCommandOptions & {
27 start?: number
28 count?: number
29 sort?: string
30 pluginType?: PluginType
31 uninstalled?: boolean
32 }) {
33 const { start, count, sort, pluginType, uninstalled } = options
34 const path = '/api/v1/plugins'
35
36 return this.getRequestBody<ResultList<PeerTubePlugin>>({
37 ...options,
38
39 path,
40 query: {
41 start,
42 count,
43 sort,
44 pluginType,
45 uninstalled
46 },
47 implicitToken: true,
48 defaultExpectedStatus: HttpStatusCode.OK_200
49 })
50 }
51
52 listAvailable (options: OverrideCommandOptions & {
53 start?: number
54 count?: number
55 sort?: string
56 pluginType?: PluginType
57 currentPeerTubeEngine?: string
58 search?: string
59 expectedStatus?: HttpStatusCode
60 }) {
61 const { start, count, sort, pluginType, search, currentPeerTubeEngine } = options
62 const path = '/api/v1/plugins/available'
63
64 const query: PeertubePluginIndexList = {
65 start,
66 count,
67 sort,
68 pluginType,
69 currentPeerTubeEngine,
70 search
71 }
72
73 return this.getRequestBody<ResultList<PeerTubePluginIndex>>({
74 ...options,
75
76 path,
77 query,
78 implicitToken: true,
79 defaultExpectedStatus: HttpStatusCode.OK_200
80 })
81 }
82
83 get (options: OverrideCommandOptions & {
84 npmName: string
85 }) {
86 const path = '/api/v1/plugins/' + options.npmName
87
88 return this.getRequestBody<PeerTubePlugin>({
89 ...options,
90
91 path,
92 implicitToken: true,
93 defaultExpectedStatus: HttpStatusCode.OK_200
94 })
95 }
96
97 updateSettings (options: OverrideCommandOptions & {
98 npmName: string
99 settings: any
100 }) {
101 const { npmName, settings } = options
102 const path = '/api/v1/plugins/' + npmName + '/settings'
103
104 return this.putBodyRequest({
105 ...options,
106
107 path,
108 fields: { settings },
109 implicitToken: true,
110 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
111 })
112 }
113
114 getRegisteredSettings (options: OverrideCommandOptions & {
115 npmName: string
116 }) {
117 const path = '/api/v1/plugins/' + options.npmName + '/registered-settings'
118
119 return this.getRequestBody<RegisteredServerSettings>({
120 ...options,
121
122 path,
123 implicitToken: true,
124 defaultExpectedStatus: HttpStatusCode.OK_200
125 })
126 }
127
128 getPublicSettings (options: OverrideCommandOptions & {
129 npmName: string
130 }) {
131 const { npmName } = options
132 const path = '/api/v1/plugins/' + npmName + '/public-settings'
133
134 return this.getRequestBody<PublicServerSetting>({
135 ...options,
136
137 path,
138 implicitToken: false,
139 defaultExpectedStatus: HttpStatusCode.OK_200
140 })
141 }
142
143 getTranslations (options: OverrideCommandOptions & {
144 locale: string
145 }) {
146 const { locale } = options
147 const path = '/plugins/translations/' + locale + '.json'
148
149 return this.getRequestBody<PluginTranslation>({
150 ...options,
151
152 path,
153 implicitToken: false,
154 defaultExpectedStatus: HttpStatusCode.OK_200
155 })
156 }
157
158 install (options: OverrideCommandOptions & {
159 path?: string
160 npmName?: string
161 pluginVersion?: string
162 }) {
163 const { npmName, path, pluginVersion } = options
164 const apiPath = '/api/v1/plugins/install'
165
166 return this.postBodyRequest({
167 ...options,
168
169 path: apiPath,
170 fields: { npmName, path, pluginVersion },
171 implicitToken: true,
172 defaultExpectedStatus: HttpStatusCode.OK_200
173 })
174 }
175
176 update (options: OverrideCommandOptions & {
177 path?: string
178 npmName?: string
179 }) {
180 const { npmName, path } = options
181 const apiPath = '/api/v1/plugins/update'
182
183 return this.postBodyRequest({
184 ...options,
185
186 path: apiPath,
187 fields: { npmName, path },
188 implicitToken: true,
189 defaultExpectedStatus: HttpStatusCode.OK_200
190 })
191 }
192
193 uninstall (options: OverrideCommandOptions & {
194 npmName: string
195 }) {
196 const { npmName } = options
197 const apiPath = '/api/v1/plugins/uninstall'
198
199 return this.postBodyRequest({
200 ...options,
201
202 path: apiPath,
203 fields: { npmName },
204 implicitToken: true,
205 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
206 })
207 }
208
209 getCSS (options: OverrideCommandOptions = {}) {
210 const path = '/plugins/global.css'
211
212 return this.getRequestText({
213 ...options,
214
215 path,
216 implicitToken: false,
217 defaultExpectedStatus: HttpStatusCode.OK_200
218 })
219 }
220
221 getExternalAuth (options: OverrideCommandOptions & {
222 npmName: string
223 npmVersion: string
224 authName: string
225 query?: any
226 }) {
227 const { npmName, npmVersion, authName, query } = options
228
229 const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName
230
231 return this.getRequest({
232 ...options,
233
234 path,
235 query,
236 implicitToken: false,
237 defaultExpectedStatus: HttpStatusCode.OK_200,
238 redirects: 0
239 })
240 }
241
242 updatePackageJSON (npmName: string, json: any) {
243 const path = this.getPackageJSONPath(npmName)
244
245 return writeJSON(path, json)
246 }
247
248 getPackageJSON (npmName: string): Promise<PluginPackageJson> {
249 const path = this.getPackageJSONPath(npmName)
250
251 return readJSON(path)
252 }
253
254 private getPackageJSONPath (npmName: string) {
255 return this.server.servers.buildDirectory(join('plugins', 'node_modules', npmName, 'package.json'))
256 }
257}
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts
deleted file mode 100644
index 0f5fabd5a..000000000
--- a/shared/extra-utils/server/plugins.ts
+++ /dev/null
@@ -1,18 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { PeerTubeServer } from '../server/server'
5
6async function testHelloWorldRegisteredSettings (server: PeerTubeServer) {
7 const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' })
8
9 const registeredSettings = body.registeredSettings
10 expect(registeredSettings).to.have.length.at.least(1)
11
12 const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name')
13 expect(adminNameSettings).to.not.be.undefined
14}
15
16export {
17 testHelloWorldRegisteredSettings
18}
diff --git a/shared/extra-utils/server/redundancy-command.ts b/shared/extra-utils/server/redundancy-command.ts
deleted file mode 100644
index e7a8b3c29..000000000
--- a/shared/extra-utils/server/redundancy-command.ts
+++ /dev/null
@@ -1,80 +0,0 @@
1import { HttpStatusCode, ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
2import { AbstractCommand, OverrideCommandOptions } from '../shared'
3
4export class RedundancyCommand extends AbstractCommand {
5
6 updateRedundancy (options: OverrideCommandOptions & {
7 host: string
8 redundancyAllowed: boolean
9 }) {
10 const { host, redundancyAllowed } = options
11 const path = '/api/v1/server/redundancy/' + host
12
13 return this.putBodyRequest({
14 ...options,
15
16 path,
17 fields: { redundancyAllowed },
18 implicitToken: true,
19 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
20 })
21 }
22
23 listVideos (options: OverrideCommandOptions & {
24 target: VideoRedundanciesTarget
25 start?: number
26 count?: number
27 sort?: string
28 }) {
29 const path = '/api/v1/server/redundancy/videos'
30
31 const { target, start, count, sort } = options
32
33 return this.getRequestBody<ResultList<VideoRedundancy>>({
34 ...options,
35
36 path,
37
38 query: {
39 start: start ?? 0,
40 count: count ?? 5,
41 sort: sort ?? 'name',
42 target
43 },
44
45 implicitToken: true,
46 defaultExpectedStatus: HttpStatusCode.OK_200
47 })
48 }
49
50 addVideo (options: OverrideCommandOptions & {
51 videoId: number
52 }) {
53 const path = '/api/v1/server/redundancy/videos'
54 const { videoId } = options
55
56 return this.postBodyRequest({
57 ...options,
58
59 path,
60 fields: { videoId },
61 implicitToken: true,
62 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
63 })
64 }
65
66 removeVideo (options: OverrideCommandOptions & {
67 redundancyId: number
68 }) {
69 const { redundancyId } = options
70 const path = '/api/v1/server/redundancy/videos/' + redundancyId
71
72 return this.deleteRequest({
73 ...options,
74
75 path,
76 implicitToken: true,
77 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
78 })
79 }
80}
diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts
deleted file mode 100644
index 339b9cabb..000000000
--- a/shared/extra-utils/server/server.ts
+++ /dev/null
@@ -1,392 +0,0 @@
1import { ChildProcess, fork } from 'child_process'
2import { copy } from 'fs-extra'
3import { join } from 'path'
4import { root, randomInt } from '@shared/core-utils'
5import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '../../models/videos'
6import { BulkCommand } from '../bulk'
7import { CLICommand } from '../cli'
8import { CustomPagesCommand } from '../custom-pages'
9import { FeedCommand } from '../feeds'
10import { LogsCommand } from '../logs'
11import { parallelTests, SQLCommand } from '../miscs'
12import { AbusesCommand } from '../moderation'
13import { OverviewsCommand } from '../overviews'
14import { SearchCommand } from '../search'
15import { SocketIOCommand } from '../socket'
16import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users'
17import {
18 BlacklistCommand,
19 CaptionsCommand,
20 ChangeOwnershipCommand,
21 ChannelsCommand,
22 HistoryCommand,
23 ImportsCommand,
24 LiveCommand,
25 PlaylistsCommand,
26 ServicesCommand,
27 StreamingPlaylistsCommand,
28 VideosCommand
29} from '../videos'
30import { CommentsCommand } from '../videos/comments-command'
31import { ConfigCommand } from './config-command'
32import { ContactFormCommand } from './contact-form-command'
33import { DebugCommand } from './debug-command'
34import { FollowsCommand } from './follows-command'
35import { JobsCommand } from './jobs-command'
36import { PluginsCommand } from './plugins-command'
37import { RedundancyCommand } from './redundancy-command'
38import { ServersCommand } from './servers-command'
39import { StatsCommand } from './stats-command'
40import { ObjectStorageCommand } from './object-storage-command'
41
42export type RunServerOptions = {
43 hideLogs?: boolean
44 nodeArgs?: string[]
45 peertubeArgs?: string[]
46 env?: { [ id: string ]: string }
47}
48
49export class PeerTubeServer {
50 app?: ChildProcess
51
52 url: string
53 host?: string
54 hostname?: string
55 port?: number
56
57 rtmpPort?: number
58 rtmpsPort?: number
59
60 parallel?: boolean
61 internalServerNumber: number
62
63 serverNumber?: number
64 customConfigFile?: string
65
66 store?: {
67 client?: {
68 id?: string
69 secret?: string
70 }
71
72 user?: {
73 username: string
74 password: string
75 email?: string
76 }
77
78 channel?: VideoChannel
79
80 video?: Video
81 videoCreated?: VideoCreateResult
82 videoDetails?: VideoDetails
83
84 videos?: { id: number, uuid: string }[]
85 }
86
87 accessToken?: string
88 refreshToken?: string
89
90 bulk?: BulkCommand
91 cli?: CLICommand
92 customPage?: CustomPagesCommand
93 feed?: FeedCommand
94 logs?: LogsCommand
95 abuses?: AbusesCommand
96 overviews?: OverviewsCommand
97 search?: SearchCommand
98 contactForm?: ContactFormCommand
99 debug?: DebugCommand
100 follows?: FollowsCommand
101 jobs?: JobsCommand
102 plugins?: PluginsCommand
103 redundancy?: RedundancyCommand
104 stats?: StatsCommand
105 config?: ConfigCommand
106 socketIO?: SocketIOCommand
107 accounts?: AccountsCommand
108 blocklist?: BlocklistCommand
109 subscriptions?: SubscriptionsCommand
110 live?: LiveCommand
111 services?: ServicesCommand
112 blacklist?: BlacklistCommand
113 captions?: CaptionsCommand
114 changeOwnership?: ChangeOwnershipCommand
115 playlists?: PlaylistsCommand
116 history?: HistoryCommand
117 imports?: ImportsCommand
118 streamingPlaylists?: StreamingPlaylistsCommand
119 channels?: ChannelsCommand
120 comments?: CommentsCommand
121 sql?: SQLCommand
122 notifications?: NotificationsCommand
123 servers?: ServersCommand
124 login?: LoginCommand
125 users?: UsersCommand
126 objectStorage?: ObjectStorageCommand
127 videos?: VideosCommand
128
129 constructor (options: { serverNumber: number } | { url: string }) {
130 if ((options as any).url) {
131 this.setUrl((options as any).url)
132 } else {
133 this.setServerNumber((options as any).serverNumber)
134 }
135
136 this.store = {
137 client: {
138 id: null,
139 secret: null
140 },
141 user: {
142 username: null,
143 password: null
144 }
145 }
146
147 this.assignCommands()
148 }
149
150 setServerNumber (serverNumber: number) {
151 this.serverNumber = serverNumber
152
153 this.parallel = parallelTests()
154
155 this.internalServerNumber = this.parallel ? this.randomServer() : this.serverNumber
156 this.rtmpPort = this.parallel ? this.randomRTMP() : 1936
157 this.rtmpsPort = this.parallel ? this.randomRTMP() : 1937
158 this.port = 9000 + this.internalServerNumber
159
160 this.url = `http://localhost:${this.port}`
161 this.host = `localhost:${this.port}`
162 this.hostname = 'localhost'
163 }
164
165 setUrl (url: string) {
166 const parsed = new URL(url)
167
168 this.url = url
169 this.host = parsed.host
170 this.hostname = parsed.hostname
171 this.port = parseInt(parsed.port)
172 }
173
174 async flushAndRun (configOverride?: Object, options: RunServerOptions = {}) {
175 await ServersCommand.flushTests(this.internalServerNumber)
176
177 return this.run(configOverride, options)
178 }
179
180 async run (configOverrideArg?: any, options: RunServerOptions = {}) {
181 // These actions are async so we need to be sure that they have both been done
182 const serverRunString = {
183 'HTTP server listening': false
184 }
185 const key = 'Database peertube_test' + this.internalServerNumber + ' is ready'
186 serverRunString[key] = false
187
188 const regexps = {
189 client_id: 'Client id: (.+)',
190 client_secret: 'Client secret: (.+)',
191 user_username: 'Username: (.+)',
192 user_password: 'User password: (.+)'
193 }
194
195 await this.assignCustomConfigFile()
196
197 const configOverride = this.buildConfigOverride()
198
199 if (configOverrideArg !== undefined) {
200 Object.assign(configOverride, configOverrideArg)
201 }
202
203 // Share the environment
204 const env = Object.create(process.env)
205 env['NODE_ENV'] = 'test'
206 env['NODE_APP_INSTANCE'] = this.internalServerNumber.toString()
207 env['NODE_CONFIG'] = JSON.stringify(configOverride)
208
209 if (options.env) {
210 Object.assign(env, options.env)
211 }
212
213 const forkOptions = {
214 silent: true,
215 env,
216 detached: true,
217 execArgv: options.nodeArgs || []
218 }
219
220 return new Promise<void>((res, rej) => {
221 const self = this
222 let aggregatedLogs = ''
223
224 this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions)
225
226 const onPeerTubeExit = () => rej(new Error('Process exited:\n' + aggregatedLogs))
227 const onParentExit = () => {
228 if (!this.app || !this.app.pid) return
229
230 try {
231 process.kill(self.app.pid)
232 } catch { /* empty */ }
233 }
234
235 this.app.on('exit', onPeerTubeExit)
236 process.on('exit', onParentExit)
237
238 this.app.stdout.on('data', function onStdout (data) {
239 let dontContinue = false
240
241 const log: string = data.toString()
242 aggregatedLogs += log
243
244 // Capture things if we want to
245 for (const key of Object.keys(regexps)) {
246 const regexp = regexps[key]
247 const matches = log.match(regexp)
248 if (matches !== null) {
249 if (key === 'client_id') self.store.client.id = matches[1]
250 else if (key === 'client_secret') self.store.client.secret = matches[1]
251 else if (key === 'user_username') self.store.user.username = matches[1]
252 else if (key === 'user_password') self.store.user.password = matches[1]
253 }
254 }
255
256 // Check if all required sentences are here
257 for (const key of Object.keys(serverRunString)) {
258 if (log.includes(key)) serverRunString[key] = true
259 if (serverRunString[key] === false) dontContinue = true
260 }
261
262 // If no, there is maybe one thing not already initialized (client/user credentials generation...)
263 if (dontContinue === true) return
264
265 if (options.hideLogs === false) {
266 console.log(log)
267 } else {
268 process.removeListener('exit', onParentExit)
269 self.app.stdout.removeListener('data', onStdout)
270 self.app.removeListener('exit', onPeerTubeExit)
271 }
272
273 res()
274 })
275 })
276 }
277
278 async kill () {
279 if (!this.app) return
280
281 await this.sql.cleanup()
282
283 process.kill(-this.app.pid)
284
285 this.app = null
286 }
287
288 private randomServer () {
289 const low = 10
290 const high = 10000
291
292 return randomInt(low, high)
293 }
294
295 private randomRTMP () {
296 const low = 1900
297 const high = 2100
298
299 return randomInt(low, high)
300 }
301
302 private async assignCustomConfigFile () {
303 if (this.internalServerNumber === this.serverNumber) return
304
305 const basePath = join(root(), 'config')
306
307 const tmpConfigFile = join(basePath, `test-${this.internalServerNumber}.yaml`)
308 await copy(join(basePath, `test-${this.serverNumber}.yaml`), tmpConfigFile)
309
310 this.customConfigFile = tmpConfigFile
311 }
312
313 private buildConfigOverride () {
314 if (!this.parallel) return {}
315
316 return {
317 listen: {
318 port: this.port
319 },
320 webserver: {
321 port: this.port
322 },
323 database: {
324 suffix: '_test' + this.internalServerNumber
325 },
326 storage: {
327 tmp: `test${this.internalServerNumber}/tmp/`,
328 bin: `test${this.internalServerNumber}/bin/`,
329 avatars: `test${this.internalServerNumber}/avatars/`,
330 videos: `test${this.internalServerNumber}/videos/`,
331 streaming_playlists: `test${this.internalServerNumber}/streaming-playlists/`,
332 redundancy: `test${this.internalServerNumber}/redundancy/`,
333 logs: `test${this.internalServerNumber}/logs/`,
334 previews: `test${this.internalServerNumber}/previews/`,
335 thumbnails: `test${this.internalServerNumber}/thumbnails/`,
336 torrents: `test${this.internalServerNumber}/torrents/`,
337 captions: `test${this.internalServerNumber}/captions/`,
338 cache: `test${this.internalServerNumber}/cache/`,
339 plugins: `test${this.internalServerNumber}/plugins/`
340 },
341 admin: {
342 email: `admin${this.internalServerNumber}@example.com`
343 },
344 live: {
345 rtmp: {
346 port: this.rtmpPort
347 }
348 }
349 }
350 }
351
352 private assignCommands () {
353 this.bulk = new BulkCommand(this)
354 this.cli = new CLICommand(this)
355 this.customPage = new CustomPagesCommand(this)
356 this.feed = new FeedCommand(this)
357 this.logs = new LogsCommand(this)
358 this.abuses = new AbusesCommand(this)
359 this.overviews = new OverviewsCommand(this)
360 this.search = new SearchCommand(this)
361 this.contactForm = new ContactFormCommand(this)
362 this.debug = new DebugCommand(this)
363 this.follows = new FollowsCommand(this)
364 this.jobs = new JobsCommand(this)
365 this.plugins = new PluginsCommand(this)
366 this.redundancy = new RedundancyCommand(this)
367 this.stats = new StatsCommand(this)
368 this.config = new ConfigCommand(this)
369 this.socketIO = new SocketIOCommand(this)
370 this.accounts = new AccountsCommand(this)
371 this.blocklist = new BlocklistCommand(this)
372 this.subscriptions = new SubscriptionsCommand(this)
373 this.live = new LiveCommand(this)
374 this.services = new ServicesCommand(this)
375 this.blacklist = new BlacklistCommand(this)
376 this.captions = new CaptionsCommand(this)
377 this.changeOwnership = new ChangeOwnershipCommand(this)
378 this.playlists = new PlaylistsCommand(this)
379 this.history = new HistoryCommand(this)
380 this.imports = new ImportsCommand(this)
381 this.streamingPlaylists = new StreamingPlaylistsCommand(this)
382 this.channels = new ChannelsCommand(this)
383 this.comments = new CommentsCommand(this)
384 this.sql = new SQLCommand(this)
385 this.notifications = new NotificationsCommand(this)
386 this.servers = new ServersCommand(this)
387 this.login = new LoginCommand(this)
388 this.users = new UsersCommand(this)
389 this.videos = new VideosCommand(this)
390 this.objectStorage = new ObjectStorageCommand(this)
391 }
392}
diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts
deleted file mode 100644
index 47420c95f..000000000
--- a/shared/extra-utils/server/servers-command.ts
+++ /dev/null
@@ -1,92 +0,0 @@
1import { exec } from 'child_process'
2import { copy, ensureDir, readFile, remove } from 'fs-extra'
3import { basename, join } from 'path'
4import { root } from '@shared/core-utils'
5import { HttpStatusCode } from '@shared/models'
6import { getFileSize, isGithubCI, wait } from '../miscs'
7import { AbstractCommand, OverrideCommandOptions } from '../shared'
8
9export class ServersCommand extends AbstractCommand {
10
11 static flushTests (internalServerNumber: number) {
12 return new Promise<void>((res, rej) => {
13 const suffix = ` -- ${internalServerNumber}`
14
15 return exec('npm run clean:server:test' + suffix, (err, _stdout, stderr) => {
16 if (err || stderr) return rej(err || new Error(stderr))
17
18 return res()
19 })
20 })
21 }
22
23 ping (options: OverrideCommandOptions = {}) {
24 return this.getRequestBody({
25 ...options,
26
27 path: '/api/v1/ping',
28 implicitToken: false,
29 defaultExpectedStatus: HttpStatusCode.OK_200
30 })
31 }
32
33 async cleanupTests () {
34 const p: Promise<any>[] = []
35
36 if (isGithubCI()) {
37 await ensureDir('artifacts')
38
39 const origin = this.buildDirectory('logs/peertube.log')
40 const destname = `peertube-${this.server.internalServerNumber}.log`
41 console.log('Saving logs %s.', destname)
42
43 await copy(origin, join('artifacts', destname))
44 }
45
46 if (this.server.parallel) {
47 p.push(ServersCommand.flushTests(this.server.internalServerNumber))
48 }
49
50 if (this.server.customConfigFile) {
51 p.push(remove(this.server.customConfigFile))
52 }
53
54 return p
55 }
56
57 async waitUntilLog (str: string, count = 1, strictCount = true) {
58 const logfile = this.buildDirectory('logs/peertube.log')
59
60 while (true) {
61 const buf = await readFile(logfile)
62
63 const matches = buf.toString().match(new RegExp(str, 'g'))
64 if (matches && matches.length === count) return
65 if (matches && strictCount === false && matches.length >= count) return
66
67 await wait(1000)
68 }
69 }
70
71 buildDirectory (directory: string) {
72 return join(root(), 'test' + this.server.internalServerNumber, directory)
73 }
74
75 buildWebTorrentFilePath (fileUrl: string) {
76 return this.buildDirectory(join('videos', basename(fileUrl)))
77 }
78
79 buildFragmentedFilePath (videoUUID: string, fileUrl: string) {
80 return this.buildDirectory(join('streaming-playlists', 'hls', videoUUID, basename(fileUrl)))
81 }
82
83 getLogContent () {
84 return readFile(this.buildDirectory('logs/peertube.log'))
85 }
86
87 async getServerFileSize (subPath: string) {
88 const path = this.server.servers.buildDirectory(subPath)
89
90 return getFileSize(path)
91 }
92}
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
deleted file mode 100644
index 21ab9405b..000000000
--- a/shared/extra-utils/server/servers.ts
+++ /dev/null
@@ -1,49 +0,0 @@
1import { ensureDir } from 'fs-extra'
2import { isGithubCI } from '../miscs'
3import { PeerTubeServer, RunServerOptions } from './server'
4
5async function createSingleServer (serverNumber: number, configOverride?: Object, options: RunServerOptions = {}) {
6 const server = new PeerTubeServer({ serverNumber })
7
8 await server.flushAndRun(configOverride, options)
9
10 return server
11}
12
13function createMultipleServers (totalServers: number, configOverride?: Object, options: RunServerOptions = {}) {
14 const serverPromises: Promise<PeerTubeServer>[] = []
15
16 for (let i = 1; i <= totalServers; i++) {
17 serverPromises.push(createSingleServer(i, configOverride, options))
18 }
19
20 return Promise.all(serverPromises)
21}
22
23async function killallServers (servers: PeerTubeServer[]) {
24 return Promise.all(servers.map(s => s.kill()))
25}
26
27async function cleanupTests (servers: PeerTubeServer[]) {
28 await killallServers(servers)
29
30 if (isGithubCI()) {
31 await ensureDir('artifacts')
32 }
33
34 let p: Promise<any>[] = []
35 for (const server of servers) {
36 p = p.concat(server.servers.cleanupTests())
37 }
38
39 return Promise.all(p)
40}
41
42// ---------------------------------------------------------------------------
43
44export {
45 createSingleServer,
46 createMultipleServers,
47 cleanupTests,
48 killallServers
49}
diff --git a/shared/extra-utils/server/stats-command.ts b/shared/extra-utils/server/stats-command.ts
deleted file mode 100644
index 64a452306..000000000
--- a/shared/extra-utils/server/stats-command.ts
+++ /dev/null
@@ -1,25 +0,0 @@
1import { HttpStatusCode, ServerStats } from '@shared/models'
2import { AbstractCommand, OverrideCommandOptions } from '../shared'
3
4export class StatsCommand extends AbstractCommand {
5
6 get (options: OverrideCommandOptions & {
7 useCache?: boolean // default false
8 } = {}) {
9 const { useCache = false } = options
10 const path = '/api/v1/server/stats'
11
12 const query = {
13 t: useCache ? undefined : new Date().getTime()
14 }
15
16 return this.getRequestBody<ServerStats>({
17 ...options,
18
19 path,
20 query,
21 implicitToken: false,
22 defaultExpectedStatus: HttpStatusCode.OK_200
23 })
24 }
25}
diff --git a/shared/extra-utils/server/tracker.ts b/shared/extra-utils/server/tracker.ts
deleted file mode 100644
index ed43a5924..000000000
--- a/shared/extra-utils/server/tracker.ts
+++ /dev/null
@@ -1,27 +0,0 @@
1import { expect } from 'chai'
2import { sha1 } from '@shared/core-utils/crypto'
3import { makeGetRequest } from '../requests'
4
5async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) {
6 const path = '/tracker/announce'
7
8 const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`)
9
10 // From bittorrent-tracker
11 const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) {
12 return '%' + char.charCodeAt(0).toString(16).toUpperCase()
13 })
14
15 const res = await makeGetRequest({
16 url: serverUrl,
17 path,
18 rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`,
19 expectedStatus: 200
20 })
21
22 expect(res.text).to.not.contain('failure')
23}
24
25export {
26 hlsInfohashExist
27}