-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfig.js
77 lines (52 loc) · 1.98 KB
/
config.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const commentJson = require('comment-json')
const path = require('path')
const rootDir = path.dirname(process.execPath)
const fs = require('fs')
const configFile = 'config.json'
const defaultConfig = {
"// autoLaunch": [["// if this is set to true, the add-on will run on system start-up"]],
"autoLaunch": false,
"// responseTimeout": [["// for stremio add-on, in milliseconds, if timeout is reached it will respond with whatever results it already has, 0 = no timeout"]],
"responseTimeout": 11000,
"// addonPort": [["// port to use for stremio add-on, default is 7000"]],
"addonPort": 7000,
"// minimumSeeds": [["// remove torrents with less then X seeds"]],
"minimumSeeds": 3,
"// maximumResults": [["// maximum number of torrents to respond with, 0 = no limit"]],
"maximumResults": 15,
"// remote": [["// make add-on available remotely too, through LAN and the Internet"]],
"remote": false,
"// subdomain": [["// set the preferred subdomain (if available), only applicable if remote is set to true"]],
"subdomain": false,
"jackett": {
"// host": [["// self explanatory, the default port is presumed"]],
"host": "http://127.0.0.1:9117/",
"// readTimeout": [["// read timeout in milliseconds for http requests to jackett server, 0 = no timeout"]],
"readTimeout": 10000,
"// openTimeout": [["// open timeout in milliseconds for http requests to jackett server, 0 = no timeout"]],
"openTimeout": 10000
}
}
const readConfig = () => {
const configFilePath = path.join(rootDir, configFile)
if (fs.existsSync(configFilePath)) {
var config
try {
config = fs.readFileSync(configFilePath)
} catch(e) {
// ignore read file issues
return defaultConfig
}
return commentJson.parse(config.toString())
} else {
const configString = commentJson.stringify(defaultConfig, null, 4)
try {
fs.writeFileSync(configFilePath, configString)
} catch(e) {
// ignore write file issues
return defaultConfig
}
return readConfig()
}
}
module.exports = readConfig()