frpc-desktop/electron/storage/config.ts

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-11-27 15:03:25 +08:00
import Datastore from "nedb";
import path from "path";
2024-08-05 23:36:33 +08:00
import {app} from "electron";
const log = require('electron-log');
2023-11-27 15:03:25 +08:00
const configDB = new Datastore({
2024-08-05 23:36:33 +08:00
autoload: true,
filename: path.join(app.getPath("userData"), "config.db")
2023-11-27 15:03:25 +08:00
});
export type Config = {
2024-08-05 23:36:33 +08:00
currentVersion: any;
serverAddr: string;
serverPort: number;
authMethod: string;
authToken: string;
logLevel: string;
logMaxDays: number;
tlsConfigEnable: boolean;
tlsConfigCertFile: string;
tlsConfigKeyFile: string;
tlsConfigTrustedCaFile: string;
tlsConfigServerName: string;
proxyConfigEnable: boolean;
proxyConfigProxyUrl: string;
systemSelfStart: boolean;
systemStartupConnect: boolean;
user: string;
metaToken: string;
2023-11-27 15:03:25 +08:00
};
/**
*
*/
export const saveConfig = (
2024-08-05 23:36:33 +08:00
document: Config,
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
2023-11-27 15:03:25 +08:00
) => {
2024-08-05 23:36:33 +08:00
document["_id"] = "1";
2024-08-06 00:17:39 +08:00
log.debug(`保存日志 ${JSON.stringify(document)}`)
2024-08-05 23:36:33 +08:00
configDB.update({_id: "1"}, document, {upsert: true}, cb);
2023-11-27 15:03:25 +08:00
};
/**
*
* @param cb
*/
export const getConfig = (
2024-08-05 23:36:33 +08:00
cb: (err: Error | null, document: Config) => void
2023-11-27 15:03:25 +08:00
) => {
2024-08-05 23:36:33 +08:00
configDB.findOne({_id: "1"}, cb);
2023-11-27 15:03:25 +08:00
};