forked from reruin/sharelist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
67 lines (52 loc) · 1.26 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
const fs = require('fs')
const os = require('os')
const config_path = process.cwd() +'/cache/config.json'
const port = process.env.PORT || 33001
const providers = [
{name:'GoogleDrive',code:'gd'},
{name:'OneDrive',code:'od'},
{name:'VirtualFile',code:'xd'},
{name:'LocalFileSystem',code:'ld'},
]
//onedrive 链接有效期 10 分钟
var data = {
port ,
enabled_proxy : 0 ,
enabled_proxy_header: 0 ,
//目录刷新时间 15分钟
cache_refresh_dir:15 * 60 * 1000,
//外链 10分钟
cache_refresh_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'
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 = {
data, save , installed , port , providers , getTitle
}