-
Notifications
You must be signed in to change notification settings - Fork 141
/
qbittorrent.setup.js
34 lines (28 loc) · 1.04 KB
/
qbittorrent.setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import crypto from 'crypto';
import fs from 'fs';
import os from 'os';
import path from 'path';
import {spawn} from 'child_process';
const temporaryRuntimeDirectory = path.resolve(os.tmpdir(), `flood.test.${crypto.randomBytes(12).toString('hex')}`);
fs.mkdirSync(temporaryRuntimeDirectory, {recursive: true});
const qbtPort = Math.floor(Math.random() * (65534 - 20000) + 20000);
const qBittorrentDaemon = spawn(
'qbittorrent-nox',
[`--webui-port=${qbtPort}`, `--profile=${temporaryRuntimeDirectory}`],
{
stdio: 'ignore',
killSignal: 'SIGKILL',
},
);
process.argv = ['node', 'flood'];
process.argv.push('--rundir', temporaryRuntimeDirectory);
process.argv.push('--allowedpath', temporaryRuntimeDirectory);
process.argv.push('--auth', 'none');
process.argv.push('--qburl', `http://127.0.0.1:${qbtPort}`);
process.argv.push('--qbuser', 'admin');
process.argv.push('--qbpass', 'adminadmin');
process.argv.push('--assets', 'false');
afterAll(() => {
qBittorrentDaemon.kill('SIGKILL');
fs.rmdirSync(temporaryRuntimeDirectory, {recursive: true});
});