mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-15 06:44:53 +08:00
ref: db api 修改为同步
This commit is contained in:
27
static/utils.js
Normal file
27
static/utils.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user