forked from reruin/sharelist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
77 lines (54 loc) · 1.58 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 fs = require('fs')
const os = require('os')
const config_path = process.cwd() +'/cache/config.json'
const port = process.env.PORT || 33001
var location = {}
var data = {
port ,
proxy_enable : 0 ,
webdav_path : '/webdav/',
//目录刷新时间 15分钟
max_age_dir: 15 * 60 * 1000,
//外链 10分钟
max_age_file: 5 * 60 * 1000
}
const save = async (d) => {
for(var i in d){
data[i] = d[i]
}
let str = JSON.stringify( data )
return new Promise((resolve, reject) => {
fs.writeFile(config_path, str, function(err) {
if (err) {
console.log(err,'save config error')
} else {
console.log('save config success')
}
resolve(true)
})
})
}
const installed = () => data.token && data.path
const getTitle = () => data.title || 'ShareList'
const getConfig = () => ({proxy_enable:data.proxy_enable , max_age_dir:data.max_age_dir , max_age_file:data.max_age_file})
const getToken = () => data.token
const getAllConfig = () => ({...data})
const getPort = () => data.port
const getPath = () => [].concat( data.path || [] )
const setLocation = (d) => { location = d }
const getLocation = () => location
const getWebdavPath = () => data.webdav_path
const setConfig = (d) => {
}
try{
let cfg = fs.readFileSync(config_path,'utf-8');
if(cfg){
cfg = JSON.parse(cfg)
for(var i in cfg){
data[i] = cfg[i]
}
}
console.log('Load config from file')
}catch(e){
}
module.exports = { get:getAllConfig, getConfig , getToken , getPath , getPort , getTitle , save , installed , getLocation , setLocation , getWebdavPath}