ref: db api 修改为同步

This commit is contained in:
muwoo
2021-07-12 12:54:08 +08:00
parent 70bbe8ab49
commit e4e7dbbe9a
7 changed files with 151 additions and 51 deletions

27
static/utils.js Normal file
View File

@@ -0,0 +1,27 @@
const fs = require("fs");
const getlocalDataFile = () => {
let localDataFile = process.env.HOME;
if (!localDataFile) {
localDataFile = process.env.LOCALAPPDATA;
}
return localDataFile;
};
function saveData(path, value) {
fs.writeFileSync(path, JSON.stringify(value));
}
function getData(path, defaultValue) {
try {
return JSON.parse(fs.readFileSync(path, 'utf8'));
} catch (e) {
return defaultValue || undefined;
}
}
module.exports = {
getlocalDataFile,
saveData,
getData
}