2023-11-27 15:03:25 +08:00
|
|
|
import Datastore from "nedb";
|
|
|
|
import path from "path";
|
2024-08-16 23:59:40 +08:00
|
|
|
import { app } from "electron";
|
2024-08-05 23:36:33 +08:00
|
|
|
|
2024-08-16 23:59:40 +08:00
|
|
|
const log = require("electron-log");
|
2023-11-27 15:03:25 +08:00
|
|
|
|
|
|
|
const configDB = new Datastore({
|
2024-08-16 23:59:40 +08:00
|
|
|
autoload: true,
|
|
|
|
filename: path.join(app.getPath("userData"), "config.db")
|
2023-11-27 15:03:25 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 保存
|
|
|
|
*/
|
|
|
|
export const saveConfig = (
|
2024-08-16 23:59:40 +08:00
|
|
|
document: FrpConfig,
|
|
|
|
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
2023-11-27 15:03:25 +08:00
|
|
|
) => {
|
2024-08-16 23:59:40 +08:00
|
|
|
document["_id"] = "1";
|
|
|
|
log.debug(`保存日志 ${JSON.stringify(document)}`);
|
|
|
|
configDB.update({ _id: "1" }, document, { upsert: true }, cb);
|
2023-11-27 15:03:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查找
|
|
|
|
* @param cb
|
|
|
|
*/
|
|
|
|
export const getConfig = (
|
2024-08-16 23:59:40 +08:00
|
|
|
cb: (err: Error | null, document: FrpConfig) => void
|
2023-11-27 15:03:25 +08:00
|
|
|
) => {
|
2024-08-16 23:59:40 +08:00
|
|
|
configDB.findOne({ _id: "1" }, cb);
|
2023-11-27 15:03:25 +08:00
|
|
|
};
|
2024-08-22 14:19:19 +08:00
|
|
|
|
|
|
|
export const clearConfig = (cb?: (err: Error | null, n: number) => void) => {
|
|
|
|
configDB.remove({}, { multi: true }, cb);
|
|
|
|
};
|