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