2023-11-27 15:03:25 +08:00
|
|
|
import Datastore from "nedb";
|
|
|
|
import path from "path";
|
|
|
|
import { app } from "electron";
|
|
|
|
|
|
|
|
const configDB = new Datastore({
|
|
|
|
autoload: true,
|
|
|
|
filename: path.join(app.getPath("userData"), "config.db")
|
|
|
|
});
|
|
|
|
|
|
|
|
export type Config = {
|
|
|
|
currentVersion: any;
|
|
|
|
serverAddr: string;
|
|
|
|
serverPort: number;
|
|
|
|
authMethod: string;
|
|
|
|
authToken: string;
|
2023-11-28 17:49:08 +08:00
|
|
|
logLevel: string;
|
|
|
|
logMaxDays: number;
|
2023-12-01 14:16:53 +08:00
|
|
|
tlsConfigEnable: boolean;
|
|
|
|
tlsConfigCertFile: string;
|
|
|
|
tlsConfigKeyFile: string;
|
|
|
|
tlsConfigTrustedCaFile: string;
|
|
|
|
tlsConfigServerName: string;
|
2024-01-20 11:24:59 +08:00
|
|
|
proxyConfigEnable: boolean;
|
|
|
|
proxyConfigProxyUrl: string;
|
2024-08-05 20:05:16 +08:00
|
|
|
systemSelfStart: boolean;
|
|
|
|
systemStartupConnect: boolean;
|
|
|
|
user: string;
|
|
|
|
metaToken: string;
|
2023-11-27 15:03:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 保存
|
|
|
|
*/
|
|
|
|
export const saveConfig = (
|
|
|
|
document: Config,
|
|
|
|
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
|
|
|
) => {
|
|
|
|
document["_id"] = "1";
|
|
|
|
configDB.update({ _id: "1" }, document, { upsert: true }, cb);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查找
|
|
|
|
* @param cb
|
|
|
|
*/
|
|
|
|
export const getConfig = (
|
|
|
|
cb: (err: Error | null, document: Config) => void
|
|
|
|
) => {
|
|
|
|
configDB.findOne({ _id: "1" }, cb);
|
|
|
|
};
|