-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
78 lines (69 loc) · 2.29 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
78
const fs = require("fs-extra")
const path = require('node:path');
const crypto = require('node:crypto');
const configFolderDir = process.pkg
? path.join(process.execPath, '..', 'config')
: path.join(__dirname);
const configPath = path.join(configFolderDir, 'config.json')
let config = {}
const defaultConfig = {
img_folder: process.pkg
? path.join(process.execPath, '..', 'static', 'img')
: path.join(__dirname, 'static', 'img'),
db_path: process.pkg
? path.join(process.execPath, '..', 'database') : path.join(__dirname, 'appDatabase'),
rootFolders: [],
maxParallelism: 16,
worksPerPage: 12,
offloadMedia: false,
offloadStreamPath: "/media/stream/",
offloadDownloadPath: "/media/download/",
scannerMaxRecursionDepth: 2,
issue: "http://ashless.io",
audience: "http://ashless.io/api",
JWTsecret: crypto.randomBytes(32).toString('hex'),
JWTexpiration: "1w",
auth: process.env.NODE_ENV === 'production' ? true : false,
production: process.env.NODE_ENV === 'production' ? true : false,
getFileDurationMaxParallelism: 2,
openRegister: false
}
/**
*
* @param {boolean} writeConfigToFile Is allow to write config file to disk?
* Default controlled by process.env.FREEZE_CONFIG_FILE.
*/
function initConfig(writeConfigToFile = !process.env.FREEZE_CONFIG_FILE) {
config = Object.assign(config, defaultConfig);
if (writeConfigToFile) {
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, "\t"));
}
}
/**
*
* @param {object} newConfig New config object.
* @param {boolean} writeConfigToFile Is allow to write config file to disk?
* Default controlled by process.env.FREEZE_CONFIG_FILE.
*/
function setConfig(newConfig, writeConfigToFile = !process.env.FREEZE_CONFIG_FILE) {
newConfig.production = config.production
if (process.env.NODE_ENV === 'production' || config.production) {
newConfig.auth = true
}
newConfig.JWTsecret = config.JWTsecret
config = Object.assign(config, newConfig)
if (writeConfigToFile) {
fs.writeFileSync(configPath, JSON.stringify(config, null, "\t"))
}
}
if (!fs.existsSync(configPath)) {
initConfig()
}
else {
config = JSON.parse(fs.readFileSync(configPath));
}
module.exports = {
initConfig,
config,
setConfig
}