aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/server')
-rw-r--r--shared/extra-utils/server/config-command.ts341
-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.ts256
-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.ts389
-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, 1773 deletions
diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts
deleted file mode 100644
index 7a768b4df..000000000
--- a/shared/extra-utils/server/config-command.ts
+++ /dev/null
@@ -1,341 +0,0 @@
1import { merge } from 'lodash'
2import { DeepPartial } from '@shared/core-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 cache: {
198 previews: {
199 size: 2
200 },
201 captions: {
202 size: 3
203 },
204 torrents: {
205 size: 4
206 }
207 },
208 signup: {
209 enabled: false,
210 limit: 5,
211 requiresEmailVerification: false,
212 minimumAge: 16
213 },
214 admin: {
215 email: 'superadmin1@example.com'
216 },
217 contactForm: {
218 enabled: true
219 },
220 user: {
221 videoQuota: 5242881,
222 videoQuotaDaily: 318742
223 },
224 videoChannels: {
225 maxPerUser: 20
226 },
227 transcoding: {
228 enabled: true,
229 allowAdditionalExtensions: true,
230 allowAudioFiles: true,
231 threads: 1,
232 concurrency: 3,
233 profile: 'default',
234 resolutions: {
235 '0p': false,
236 '144p': false,
237 '240p': false,
238 '360p': true,
239 '480p': true,
240 '720p': false,
241 '1080p': false,
242 '1440p': false,
243 '2160p': false
244 },
245 webtorrent: {
246 enabled: true
247 },
248 hls: {
249 enabled: false
250 }
251 },
252 live: {
253 enabled: true,
254 allowReplay: false,
255 maxDuration: -1,
256 maxInstanceLives: -1,
257 maxUserLives: 50,
258 transcoding: {
259 enabled: true,
260 threads: 4,
261 profile: 'default',
262 resolutions: {
263 '144p': true,
264 '240p': true,
265 '360p': true,
266 '480p': true,
267 '720p': true,
268 '1080p': true,
269 '1440p': true,
270 '2160p': true
271 }
272 }
273 },
274 import: {
275 videos: {
276 concurrency: 3,
277 http: {
278 enabled: false
279 },
280 torrent: {
281 enabled: false
282 }
283 }
284 },
285 trending: {
286 videos: {
287 algorithms: {
288 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
289 default: 'hot'
290 }
291 }
292 },
293 autoBlacklist: {
294 videos: {
295 ofUsers: {
296 enabled: false
297 }
298 }
299 },
300 followers: {
301 instance: {
302 enabled: true,
303 manualApproval: false
304 }
305 },
306 followings: {
307 instance: {
308 autoFollowBack: {
309 enabled: false
310 },
311 autoFollowIndex: {
312 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
313 enabled: false
314 }
315 }
316 },
317 broadcastMessage: {
318 enabled: true,
319 level: 'warning',
320 message: 'hello',
321 dismissable: true
322 },
323 search: {
324 remoteUri: {
325 users: true,
326 anonymous: true
327 },
328 searchIndex: {
329 enabled: true,
330 url: 'https://search.joinpeertube.org',
331 disableLocalSearch: true,
332 isDefaultSearch: true
333 }
334 }
335 }
336
337 merge(newCustomConfig, options.newConfig)
338
339 return this.updateCustomConfig({ ...options, newCustomConfig })
340 }
341}
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 b6465cbf4..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 '@server/helpers/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 b944475a2..000000000
--- a/shared/extra-utils/server/plugins-command.ts
+++ /dev/null
@@ -1,256 +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 '@server/helpers/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 }) {
162 const { npmName, path } = options
163 const apiPath = '/api/v1/plugins/install'
164
165 return this.postBodyRequest({
166 ...options,
167
168 path: apiPath,
169 fields: { npmName, path },
170 implicitToken: true,
171 defaultExpectedStatus: HttpStatusCode.OK_200
172 })
173 }
174
175 update (options: OverrideCommandOptions & {
176 path?: string
177 npmName?: string
178 }) {
179 const { npmName, path } = options
180 const apiPath = '/api/v1/plugins/update'
181
182 return this.postBodyRequest({
183 ...options,
184
185 path: apiPath,
186 fields: { npmName, path },
187 implicitToken: true,
188 defaultExpectedStatus: HttpStatusCode.OK_200
189 })
190 }
191
192 uninstall (options: OverrideCommandOptions & {
193 npmName: string
194 }) {
195 const { npmName } = options
196 const apiPath = '/api/v1/plugins/uninstall'
197
198 return this.postBodyRequest({
199 ...options,
200
201 path: apiPath,
202 fields: { npmName },
203 implicitToken: true,
204 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
205 })
206 }
207
208 getCSS (options: OverrideCommandOptions = {}) {
209 const path = '/plugins/global.css'
210
211 return this.getRequestText({
212 ...options,
213
214 path,
215 implicitToken: false,
216 defaultExpectedStatus: HttpStatusCode.OK_200
217 })
218 }
219
220 getExternalAuth (options: OverrideCommandOptions & {
221 npmName: string
222 npmVersion: string
223 authName: string
224 query?: any
225 }) {
226 const { npmName, npmVersion, authName, query } = options
227
228 const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName
229
230 return this.getRequest({
231 ...options,
232
233 path,
234 query,
235 implicitToken: false,
236 defaultExpectedStatus: HttpStatusCode.OK_200,
237 redirects: 0
238 })
239 }
240
241 updatePackageJSON (npmName: string, json: any) {
242 const path = this.getPackageJSONPath(npmName)
243
244 return writeJSON(path, json)
245 }
246
247 getPackageJSON (npmName: string): Promise<PluginPackageJson> {
248 const path = this.getPackageJSONPath(npmName)
249
250 return readJSON(path)
251 }
252
253 private getPackageJSONPath (npmName: string) {
254 return this.server.servers.buildDirectory(join('plugins', 'node_modules', npmName, 'package.json'))
255 }
256}
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 31224ebe9..000000000
--- a/shared/extra-utils/server/server.ts
+++ /dev/null
@@ -1,389 +0,0 @@
1import { ChildProcess, fork } from 'child_process'
2import { copy } from 'fs-extra'
3import { join } from 'path'
4import { root } from '@server/helpers/core-utils'
5import { randomInt } from '@shared/core-utils'
6import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '../../models/videos'
7import { BulkCommand } from '../bulk'
8import { CLICommand } from '../cli'
9import { CustomPagesCommand } from '../custom-pages'
10import { FeedCommand } from '../feeds'
11import { LogsCommand } from '../logs'
12import { parallelTests, SQLCommand } from '../miscs'
13import { AbusesCommand } from '../moderation'
14import { OverviewsCommand } from '../overviews'
15import { SearchCommand } from '../search'
16import { SocketIOCommand } from '../socket'
17import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users'
18import {
19 BlacklistCommand,
20 CaptionsCommand,
21 ChangeOwnershipCommand,
22 ChannelsCommand,
23 HistoryCommand,
24 ImportsCommand,
25 LiveCommand,
26 PlaylistsCommand,
27 ServicesCommand,
28 StreamingPlaylistsCommand,
29 VideosCommand
30} from '../videos'
31import { CommentsCommand } from '../videos/comments-command'
32import { ConfigCommand } from './config-command'
33import { ContactFormCommand } from './contact-form-command'
34import { DebugCommand } from './debug-command'
35import { FollowsCommand } from './follows-command'
36import { JobsCommand } from './jobs-command'
37import { PluginsCommand } from './plugins-command'
38import { RedundancyCommand } from './redundancy-command'
39import { ServersCommand } from './servers-command'
40import { StatsCommand } from './stats-command'
41import { ObjectStorageCommand } from './object-storage-command'
42
43export type RunServerOptions = {
44 hideLogs?: boolean
45 nodeArgs?: string[]
46 peertubeArgs?: string[]
47 env?: { [ id: string ]: string }
48}
49
50export class PeerTubeServer {
51 app?: ChildProcess
52
53 url: string
54 host?: string
55 hostname?: string
56 port?: number
57
58 rtmpPort?: number
59 rtmpsPort?: number
60
61 parallel?: boolean
62 internalServerNumber: number
63
64 serverNumber?: number
65 customConfigFile?: string
66
67 store?: {
68 client?: {
69 id?: string
70 secret?: string
71 }
72
73 user?: {
74 username: string
75 password: string
76 email?: string
77 }
78
79 channel?: VideoChannel
80
81 video?: Video
82 videoCreated?: VideoCreateResult
83 videoDetails?: VideoDetails
84
85 videos?: { id: number, uuid: string }[]
86 }
87
88 accessToken?: string
89 refreshToken?: string
90
91 bulk?: BulkCommand
92 cli?: CLICommand
93 customPage?: CustomPagesCommand
94 feed?: FeedCommand
95 logs?: LogsCommand
96 abuses?: AbusesCommand
97 overviews?: OverviewsCommand
98 search?: SearchCommand
99 contactForm?: ContactFormCommand
100 debug?: DebugCommand
101 follows?: FollowsCommand
102 jobs?: JobsCommand
103 plugins?: PluginsCommand
104 redundancy?: RedundancyCommand
105 stats?: StatsCommand
106 config?: ConfigCommand
107 socketIO?: SocketIOCommand
108 accounts?: AccountsCommand
109 blocklist?: BlocklistCommand
110 subscriptions?: SubscriptionsCommand
111 live?: LiveCommand
112 services?: ServicesCommand
113 blacklist?: BlacklistCommand
114 captions?: CaptionsCommand
115 changeOwnership?: ChangeOwnershipCommand
116 playlists?: PlaylistsCommand
117 history?: HistoryCommand
118 imports?: ImportsCommand
119 streamingPlaylists?: StreamingPlaylistsCommand
120 channels?: ChannelsCommand
121 comments?: CommentsCommand
122 sql?: SQLCommand
123 notifications?: NotificationsCommand
124 servers?: ServersCommand
125 login?: LoginCommand
126 users?: UsersCommand
127 objectStorage?: ObjectStorageCommand
128 videos?: VideosCommand
129
130 constructor (options: { serverNumber: number } | { url: string }) {
131 if ((options as any).url) {
132 this.setUrl((options as any).url)
133 } else {
134 this.setServerNumber((options as any).serverNumber)
135 }
136
137 this.store = {
138 client: {
139 id: null,
140 secret: null
141 },
142 user: {
143 username: null,
144 password: null
145 }
146 }
147
148 this.assignCommands()
149 }
150
151 setServerNumber (serverNumber: number) {
152 this.serverNumber = serverNumber
153
154 this.parallel = parallelTests()
155
156 this.internalServerNumber = this.parallel ? this.randomServer() : this.serverNumber
157 this.rtmpPort = this.parallel ? this.randomRTMP() : 1936
158 this.rtmpsPort = this.parallel ? this.randomRTMP() : 1937
159 this.port = 9000 + this.internalServerNumber
160
161 this.url = `http://localhost:${this.port}`
162 this.host = `localhost:${this.port}`
163 this.hostname = 'localhost'
164 }
165
166 setUrl (url: string) {
167 const parsed = new URL(url)
168
169 this.url = url
170 this.host = parsed.host
171 this.hostname = parsed.hostname
172 this.port = parseInt(parsed.port)
173 }
174
175 async flushAndRun (configOverride?: Object, options: RunServerOptions = {}) {
176 await ServersCommand.flushTests(this.internalServerNumber)
177
178 return this.run(configOverride, options)
179 }
180
181 async run (configOverrideArg?: any, options: RunServerOptions = {}) {
182 // These actions are async so we need to be sure that they have both been done
183 const serverRunString = {
184 'HTTP server listening': false
185 }
186 const key = 'Database peertube_test' + this.internalServerNumber + ' is ready'
187 serverRunString[key] = false
188
189 const regexps = {
190 client_id: 'Client id: (.+)',
191 client_secret: 'Client secret: (.+)',
192 user_username: 'Username: (.+)',
193 user_password: 'User password: (.+)'
194 }
195
196 await this.assignCustomConfigFile()
197
198 const configOverride = this.buildConfigOverride()
199
200 if (configOverrideArg !== undefined) {
201 Object.assign(configOverride, configOverrideArg)
202 }
203
204 // Share the environment
205 const env = Object.create(process.env)
206 env['NODE_ENV'] = 'test'
207 env['NODE_APP_INSTANCE'] = this.internalServerNumber.toString()
208 env['NODE_CONFIG'] = JSON.stringify(configOverride)
209
210 if (options.env) {
211 Object.assign(env, options.env)
212 }
213
214 const forkOptions = {
215 silent: true,
216 env,
217 detached: true,
218 execArgv: options.nodeArgs || []
219 }
220
221 return new Promise<void>((res, rej) => {
222 const self = this
223
224 this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions)
225
226 const onPeerTubeExit = () => rej(new Error('Process exited'))
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 // Capture things if we want to
242 for (const key of Object.keys(regexps)) {
243 const regexp = regexps[key]
244 const matches = data.toString().match(regexp)
245 if (matches !== null) {
246 if (key === 'client_id') self.store.client.id = matches[1]
247 else if (key === 'client_secret') self.store.client.secret = matches[1]
248 else if (key === 'user_username') self.store.user.username = matches[1]
249 else if (key === 'user_password') self.store.user.password = matches[1]
250 }
251 }
252
253 // Check if all required sentences are here
254 for (const key of Object.keys(serverRunString)) {
255 if (data.toString().indexOf(key) !== -1) serverRunString[key] = true
256 if (serverRunString[key] === false) dontContinue = true
257 }
258
259 // If no, there is maybe one thing not already initialized (client/user credentials generation...)
260 if (dontContinue === true) return
261
262 if (options.hideLogs === false) {
263 console.log(data.toString())
264 } else {
265 process.removeListener('exit', onParentExit)
266 self.app.stdout.removeListener('data', onStdout)
267 self.app.removeListener('exit', onPeerTubeExit)
268 }
269
270 res()
271 })
272 })
273 }
274
275 async kill () {
276 if (!this.app) return
277
278 await this.sql.cleanup()
279
280 process.kill(-this.app.pid)
281
282 this.app = null
283 }
284
285 private randomServer () {
286 const low = 10
287 const high = 10000
288
289 return randomInt(low, high)
290 }
291
292 private randomRTMP () {
293 const low = 1900
294 const high = 2100
295
296 return randomInt(low, high)
297 }
298
299 private async assignCustomConfigFile () {
300 if (this.internalServerNumber === this.serverNumber) return
301
302 const basePath = join(root(), 'config')
303
304 const tmpConfigFile = join(basePath, `test-${this.internalServerNumber}.yaml`)
305 await copy(join(basePath, `test-${this.serverNumber}.yaml`), tmpConfigFile)
306
307 this.customConfigFile = tmpConfigFile
308 }
309
310 private buildConfigOverride () {
311 if (!this.parallel) return {}
312
313 return {
314 listen: {
315 port: this.port
316 },
317 webserver: {
318 port: this.port
319 },
320 database: {
321 suffix: '_test' + this.internalServerNumber
322 },
323 storage: {
324 tmp: `test${this.internalServerNumber}/tmp/`,
325 bin: `test${this.internalServerNumber}/bin/`,
326 avatars: `test${this.internalServerNumber}/avatars/`,
327 videos: `test${this.internalServerNumber}/videos/`,
328 streaming_playlists: `test${this.internalServerNumber}/streaming-playlists/`,
329 redundancy: `test${this.internalServerNumber}/redundancy/`,
330 logs: `test${this.internalServerNumber}/logs/`,
331 previews: `test${this.internalServerNumber}/previews/`,
332 thumbnails: `test${this.internalServerNumber}/thumbnails/`,
333 torrents: `test${this.internalServerNumber}/torrents/`,
334 captions: `test${this.internalServerNumber}/captions/`,
335 cache: `test${this.internalServerNumber}/cache/`,
336 plugins: `test${this.internalServerNumber}/plugins/`
337 },
338 admin: {
339 email: `admin${this.internalServerNumber}@example.com`
340 },
341 live: {
342 rtmp: {
343 port: this.rtmpPort
344 }
345 }
346 }
347 }
348
349 private assignCommands () {
350 this.bulk = new BulkCommand(this)
351 this.cli = new CLICommand(this)
352 this.customPage = new CustomPagesCommand(this)
353 this.feed = new FeedCommand(this)
354 this.logs = new LogsCommand(this)
355 this.abuses = new AbusesCommand(this)
356 this.overviews = new OverviewsCommand(this)
357 this.search = new SearchCommand(this)
358 this.contactForm = new ContactFormCommand(this)
359 this.debug = new DebugCommand(this)
360 this.follows = new FollowsCommand(this)
361 this.jobs = new JobsCommand(this)
362 this.plugins = new PluginsCommand(this)
363 this.redundancy = new RedundancyCommand(this)
364 this.stats = new StatsCommand(this)
365 this.config = new ConfigCommand(this)
366 this.socketIO = new SocketIOCommand(this)
367 this.accounts = new AccountsCommand(this)
368 this.blocklist = new BlocklistCommand(this)
369 this.subscriptions = new SubscriptionsCommand(this)
370 this.live = new LiveCommand(this)
371 this.services = new ServicesCommand(this)
372 this.blacklist = new BlacklistCommand(this)
373 this.captions = new CaptionsCommand(this)
374 this.changeOwnership = new ChangeOwnershipCommand(this)
375 this.playlists = new PlaylistsCommand(this)
376 this.history = new HistoryCommand(this)
377 this.imports = new ImportsCommand(this)
378 this.streamingPlaylists = new StreamingPlaylistsCommand(this)
379 this.channels = new ChannelsCommand(this)
380 this.comments = new CommentsCommand(this)
381 this.sql = new SQLCommand(this)
382 this.notifications = new NotificationsCommand(this)
383 this.servers = new ServersCommand(this)
384 this.login = new LoginCommand(this)
385 this.users = new UsersCommand(this)
386 this.videos = new VideosCommand(this)
387 this.objectStorage = new ObjectStorageCommand(this)
388 }
389}
diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts
deleted file mode 100644
index 776d2123c..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 '@server/helpers/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 f04e8f8a1..000000000
--- a/shared/extra-utils/server/tracker.ts
+++ /dev/null
@@ -1,27 +0,0 @@
1import { expect } from 'chai'
2import { sha1 } from '@server/helpers/core-utils'
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}