diff options
Diffstat (limited to 'packages/server-commands/src/server/servers.ts')
-rw-r--r-- | packages/server-commands/src/server/servers.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/packages/server-commands/src/server/servers.ts b/packages/server-commands/src/server/servers.ts new file mode 100644 index 000000000..caf9866e1 --- /dev/null +++ b/packages/server-commands/src/server/servers.ts | |||
@@ -0,0 +1,68 @@ | |||
1 | import { ensureDir } from 'fs-extra/esm' | ||
2 | import { isGithubCI } from '@peertube/peertube-node-utils' | ||
3 | import { PeerTubeServer, RunServerOptions } from './server.js' | ||
4 | |||
5 | async 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 | |||
13 | function 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 | |||
23 | function killallServers (servers: PeerTubeServer[]) { | ||
24 | return Promise.all(servers.map(s => s.kill())) | ||
25 | } | ||
26 | |||
27 | async 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 | function getServerImportConfig (mode: 'youtube-dl' | 'yt-dlp') { | ||
43 | return { | ||
44 | import: { | ||
45 | videos: { | ||
46 | http: { | ||
47 | youtube_dl_release: { | ||
48 | url: mode === 'youtube-dl' | ||
49 | ? 'https://yt-dl.org/downloads/latest/youtube-dl' | ||
50 | : 'https://api.github.com/repos/yt-dlp/yt-dlp/releases', | ||
51 | |||
52 | name: mode | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | |||
60 | // --------------------------------------------------------------------------- | ||
61 | |||
62 | export { | ||
63 | createSingleServer, | ||
64 | createMultipleServers, | ||
65 | cleanupTests, | ||
66 | killallServers, | ||
67 | getServerImportConfig | ||
68 | } | ||