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
|
const path = require("path")
const fs = require("fs-extra")
const configPath = path.join(__dirname, "../config/config.json")
const apiPath = path.join(__dirname, "../config/api.json")
const cachePath = path.join(__dirname, "../cache/mod_versions.json")
const LoadConfig = () =>
{
return require(configPath)
}
const LoadApi = () =>
{
try
{
return require(apiPath)
}
catch
{
return {}
}
}
const LoadCache = async () =>
{
try
{
if (await fs.pathExists(cachePath))
return JSON.parse(await fs.readFile(cachePath, "utf8"))
}
catch (err)
{
console.error("[Cache] Failed to load:", err)
}
return {}
}
const SaveCache = async cache =>
{
try
{
await fs.ensureDir(path.dirname(cachePath))
await fs.writeFile(cachePath, JSON.stringify(cache, null, 2))
}
catch (err)
{
console.error("[Cache] Failed to save:", err)
}
}
module.exports =
{
configPath,
apiPath,
cachePath,
LoadConfig,
LoadApi,
LoadCache,
SaveCache
}
|