2021-07-16 09:47:51 +02:00
|
|
|
import { ensureDir } from 'fs-extra'
|
2021-12-17 11:58:15 +01:00
|
|
|
import { isGithubCI } from '@shared/core-utils'
|
2021-07-16 09:47:51 +02:00
|
|
|
import { PeerTubeServer, RunServerOptions } from './server'
|
2018-12-11 09:16:41 +01:00
|
|
|
|
2023-02-16 11:56:58 +01:00
|
|
|
async function createSingleServer (serverNumber: number, configOverride?: object, options: RunServerOptions = {}) {
|
2021-07-16 09:47:51 +02:00
|
|
|
const server = new PeerTubeServer({ serverNumber })
|
2017-09-04 21:21:47 +02:00
|
|
|
|
2021-07-22 12:07:26 +02:00
|
|
|
await server.flushAndRun(configOverride, options)
|
2020-11-02 15:43:44 +01:00
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
return server
|
2019-04-24 14:00:30 +02:00
|
|
|
}
|
|
|
|
|
2023-02-16 11:56:58 +01:00
|
|
|
function createMultipleServers (totalServers: number, configOverride?: object, options: RunServerOptions = {}) {
|
2021-07-16 09:47:51 +02:00
|
|
|
const serverPromises: Promise<PeerTubeServer>[] = []
|
2019-04-24 11:54:23 +02:00
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
for (let i = 1; i <= totalServers; i++) {
|
2021-08-17 08:26:20 +02:00
|
|
|
serverPromises.push(createSingleServer(i, configOverride, options))
|
2017-09-04 21:21:47 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
return Promise.all(serverPromises)
|
2018-01-11 11:40:18 +01:00
|
|
|
}
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
async function killallServers (servers: PeerTubeServer[]) {
|
|
|
|
return Promise.all(servers.map(s => s.kill()))
|
2017-09-04 21:21:47 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
async function cleanupTests (servers: PeerTubeServer[]) {
|
2021-07-09 15:37:43 +02:00
|
|
|
await killallServers(servers)
|
2019-04-24 11:54:23 +02:00
|
|
|
|
2020-12-10 11:24:17 +01:00
|
|
|
if (isGithubCI()) {
|
|
|
|
await ensureDir('artifacts')
|
|
|
|
}
|
|
|
|
|
2021-07-13 09:43:59 +02:00
|
|
|
let p: Promise<any>[] = []
|
2019-04-24 11:54:23 +02:00
|
|
|
for (const server of servers) {
|
2021-07-16 09:04:35 +02:00
|
|
|
p = p.concat(server.servers.cleanupTests())
|
2019-04-24 11:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.all(p)
|
|
|
|
}
|
|
|
|
|
2022-08-10 09:53:39 +02:00
|
|
|
function getServerImportConfig (mode: 'youtube-dl' | 'yt-dlp') {
|
|
|
|
return {
|
|
|
|
import: {
|
|
|
|
videos: {
|
|
|
|
http: {
|
|
|
|
youtube_dl_release: {
|
|
|
|
url: mode === 'youtube-dl'
|
|
|
|
? 'https://yt-dl.org/downloads/latest/youtube-dl'
|
|
|
|
: 'https://api.github.com/repos/yt-dlp/yt-dlp/releases',
|
|
|
|
|
|
|
|
name: mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-04 21:21:47 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2021-07-16 09:47:51 +02:00
|
|
|
createSingleServer,
|
|
|
|
createMultipleServers,
|
2019-04-24 11:54:23 +02:00
|
|
|
cleanupTests,
|
2022-08-10 09:53:39 +02:00
|
|
|
killallServers,
|
|
|
|
getServerImportConfig
|
2017-09-04 21:21:47 +02:00
|
|
|
}
|