-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindexer.js
37 lines (32 loc) · 1.06 KB
/
indexer.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
35
36
37
const fs = require("fs");
const path = require("path");
const envPaths = require("env-paths");
const TorrentIndexer = require("torrent-indexer");
const indexerSources = require("torrent-indexer/src/config.json");
const systemPaths = envPaths("torrenter");
const config = path.join(systemPaths.config, "config.json");
let sources = {};
try {
if (!fs.existsSync(config)) {
fs.writeFileSync(config, JSON.stringify(indexerSources, null, 2));
sources = indexerSources;
console.log("\ntorrenter config created:\n" + config);
} else {
sources = JSON.parse(fs.readFileSync(config));
}
} catch (e) {
sources = indexerSources;
fs.mkdirSync(systemPaths.config, {
recursive: true
});
}
if (!sources.path) {
if (process.env.HOME == "/data/data/com.termux/files/home") {
sources.path = "/data/data/com.termux/files/home/storage/downloads";
} else {
sources.path = "downloads";
}
fs.writeFileSync(config, JSON.stringify(sources, null, 2));
}
const torrentIndexer = new TorrentIndexer(sources);
module.exports = { torrentIndexer, config: sources };