🔊 Refactor logging across multiple modules: Updated logging statements to utilize a new structured logging utility for improved traceability and consistency. Enhanced error handling and added informative logs for database operations, configuration management, and proxy handling. Masked sensitive data in logs to improve security during configuration operations.
This commit is contained in:
parent
9ab29259b1
commit
ffb42bd131
@ -7,7 +7,6 @@ import path from "path";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { logDebug, logError, logInfo, LogModule, logWarn } from "../utils/log";
|
import { logDebug, logError, logInfo, LogModule, logWarn } from "../utils/log";
|
||||||
|
|
||||||
const log = require("electron-log");
|
|
||||||
const toml = require("@iarna/toml");
|
const toml = require("@iarna/toml");
|
||||||
const { v4: uuidv4 } = require("uuid");
|
const { v4: uuidv4 } = require("uuid");
|
||||||
|
|
||||||
@ -83,7 +82,9 @@ export const initConfigApi = win => {
|
|||||||
logWarn(LogModule.APP, "Export canceled by user.");
|
logWarn(LogModule.APP, "Export canceled by user.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info(
|
|
||||||
|
logInfo(
|
||||||
|
LogModule.APP,
|
||||||
`Exporting configuration to directory ${outputDirectory} with type: ${args}`
|
`Exporting configuration to directory ${outputDirectory} with type: ${args}`
|
||||||
);
|
);
|
||||||
getConfig((err1, config) => {
|
getConfig((err1, config) => {
|
||||||
@ -279,7 +280,10 @@ export const initConfigApi = win => {
|
|||||||
} else {
|
} else {
|
||||||
const filePath = result.filePaths[0];
|
const filePath = result.filePaths[0];
|
||||||
const fileExtension = path.extname(filePath); // 获取文件后缀名
|
const fileExtension = path.extname(filePath); // 获取文件后缀名
|
||||||
log.info(`Importing file ${filePath} with extension ${fileExtension}`);
|
logWarn(
|
||||||
|
LogModule.APP,
|
||||||
|
`Importing file ${filePath} with extension ${fileExtension}`
|
||||||
|
);
|
||||||
if (fileExtension === ".toml") {
|
if (fileExtension === ".toml") {
|
||||||
parseTomlConfig(filePath);
|
parseTomlConfig(filePath);
|
||||||
event.reply("Config.importConfig.hook", {
|
event.reply("Config.importConfig.hook", {
|
||||||
|
@ -344,7 +344,6 @@ export const initGitHubApi = () => {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
onCompleted: () => {
|
onCompleted: () => {
|
||||||
log.info(`frp下载完成 url:${url} asset:${asset.name}`);
|
|
||||||
logInfo(
|
logInfo(
|
||||||
LogModule.GITHUB,
|
LogModule.GITHUB,
|
||||||
`Download completed for versionId: ${versionId}, asset: ${asset.name}`
|
`Download completed for versionId: ${versionId}, asset: ${asset.name}`
|
||||||
|
@ -9,43 +9,43 @@ export const initLoggerApi = () => {
|
|||||||
const readLogger = (callback: (content: string) => void) => {
|
const readLogger = (callback: (content: string) => void) => {
|
||||||
fs.readFile(logPath, "utf-8", (error, data) => {
|
fs.readFile(logPath, "utf-8", (error, data) => {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
logInfo(LogModule.LOGGER, "Log file read successfully.");
|
logInfo(LogModule.APP, "Log file read successfully.");
|
||||||
callback(data);
|
callback(data);
|
||||||
} else {
|
} else {
|
||||||
logError(LogModule.LOGGER, `Error reading log file: ${error.message}`);
|
logError(LogModule.APP, `Error reading log file: ${error.message}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ipcMain.on("logger.getLog", async (event, args) => {
|
ipcMain.on("logger.getLog", async (event, args) => {
|
||||||
logInfo(LogModule.LOGGER, "Received request to get log.");
|
logInfo(LogModule.APP, "Received request to get log.");
|
||||||
readLogger(content => {
|
readLogger(content => {
|
||||||
event.reply("Logger.getLog.hook", content);
|
event.reply("Logger.getLog.hook", content);
|
||||||
logInfo(LogModule.LOGGER, "Log data sent to client.");
|
logInfo(LogModule.APP, "Log data sent to client.");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("logger.update", (event, args) => {
|
ipcMain.on("logger.update", (event, args) => {
|
||||||
logInfo(LogModule.LOGGER, "Watching log file for changes.");
|
logInfo(LogModule.APP, "Watching log file for changes.");
|
||||||
fs.watch(logPath, (eventType, filename) => {
|
fs.watch(logPath, (eventType, filename) => {
|
||||||
if (eventType === "change") {
|
if (eventType === "change") {
|
||||||
logInfo(LogModule.LOGGER, "Log file changed, reading new content.");
|
logInfo(LogModule.APP, "Log file changed, reading new content.");
|
||||||
readLogger(content => {
|
readLogger(content => {
|
||||||
event.reply("Logger.update.hook", content);
|
event.reply("Logger.update.hook", content);
|
||||||
logInfo(LogModule.LOGGER, "Updated log data sent to client.");
|
logInfo(LogModule.APP, "Updated log data sent to client.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("logger.openLog", (event, args) => {
|
ipcMain.on("logger.openLog", (event, args) => {
|
||||||
logInfo(LogModule.LOGGER, "Attempting to open log file.");
|
logInfo(LogModule.APP, "Attempting to open log file.");
|
||||||
shell.openPath(logPath).then((errorMessage) => {
|
shell.openPath(logPath).then((errorMessage) => {
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
logError(LogModule.LOGGER, `Failed to open Logger: ${errorMessage}`);
|
logError(LogModule.APP, `Failed to open Logger: ${errorMessage}`);
|
||||||
event.reply("Logger.openLog.hook", false);
|
event.reply("Logger.openLog.hook", false);
|
||||||
} else {
|
} else {
|
||||||
logInfo(LogModule.LOGGER, "Logger opened successfully.");
|
logInfo(LogModule.APP, "Logger opened successfully.");
|
||||||
event.reply("Logger.openLog.hook", true);
|
event.reply("Logger.openLog.hook", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,13 +2,13 @@ import Datastore from "nedb";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
|
|
||||||
const log = require("electron-log");
|
import { logInfo, logError, LogModule, logDebug } from "../utils/log";
|
||||||
|
import { maskSensitiveData } from "../utils/desensitize";
|
||||||
|
|
||||||
const configDB = new Datastore({
|
const configDB = new Datastore({
|
||||||
autoload: true,
|
autoload: true,
|
||||||
filename: path.join(app.getPath("userData"), "config.db")
|
filename: path.join(app.getPath("userData"), "config.db")
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存
|
* 保存
|
||||||
*/
|
*/
|
||||||
@ -17,8 +17,37 @@ export const saveConfig = (
|
|||||||
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
||||||
) => {
|
) => {
|
||||||
document["_id"] = "1";
|
document["_id"] = "1";
|
||||||
log.debug(`保存日志 ${JSON.stringify(document)}`);
|
logDebug(
|
||||||
configDB.update({ _id: "1" }, document, { upsert: true }, cb);
|
LogModule.DB,
|
||||||
|
`Saving configuration to the database. ${JSON.stringify(
|
||||||
|
maskSensitiveData(document, [
|
||||||
|
"serverAddr",
|
||||||
|
"serverPort",
|
||||||
|
"authToken",
|
||||||
|
"user",
|
||||||
|
"metaToken"
|
||||||
|
])
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
configDB.update(
|
||||||
|
{ _id: "1" },
|
||||||
|
document,
|
||||||
|
{ upsert: true },
|
||||||
|
(err, numberOfUpdated, upsert) => {
|
||||||
|
if (err) {
|
||||||
|
logError(
|
||||||
|
LogModule.DB,
|
||||||
|
`Error saving configuration: ${err.message}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
logInfo(
|
||||||
|
LogModule.DB,
|
||||||
|
`Configuration saved successfully. Updated: ${numberOfUpdated}, Upsert: ${upsert}`
|
||||||
|
); // 添加成功日志
|
||||||
|
}
|
||||||
|
if (cb) cb(err, numberOfUpdated, upsert);
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,9 +57,34 @@ export const saveConfig = (
|
|||||||
export const getConfig = (
|
export const getConfig = (
|
||||||
cb: (err: Error | null, document: FrpConfig) => void
|
cb: (err: Error | null, document: FrpConfig) => void
|
||||||
) => {
|
) => {
|
||||||
configDB.findOne({ _id: "1" }, cb);
|
logInfo(LogModule.DB, "Retrieving configuration from the database."); // 添加信息日志
|
||||||
|
configDB.findOne({ _id: "1" }, (err, document) => {
|
||||||
|
if (err) {
|
||||||
|
logError(
|
||||||
|
LogModule.DB,
|
||||||
|
`Error retrieving configuration: ${err.message}`
|
||||||
|
); // 添加错误日志
|
||||||
|
} else {
|
||||||
|
logInfo(LogModule.DB, "Configuration retrieved successfully."); // 添加成功日志
|
||||||
|
}
|
||||||
|
cb(err, document);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const clearConfig = (cb?: (err: Error | null, n: number) => void) => {
|
export const clearConfig = (cb?: (err: Error | null, n: number) => void) => {
|
||||||
configDB.remove({}, { multi: true }, cb);
|
logInfo(LogModule.DB, "Clearing all configurations from the database."); // 添加信息日志
|
||||||
};
|
configDB.remove({}, { multi: true }, (err, n) => {
|
||||||
|
if (err) {
|
||||||
|
logError(
|
||||||
|
LogModule.DB,
|
||||||
|
`Error clearing configurations: ${err.message}`
|
||||||
|
); // 添加错误日志
|
||||||
|
} else {
|
||||||
|
logInfo(
|
||||||
|
LogModule.DB,
|
||||||
|
`Successfully cleared configurations. Number of documents removed: ${n}`
|
||||||
|
); // 添加成功日志
|
||||||
|
}
|
||||||
|
if (cb) cb(err, n);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
@ -2,90 +2,147 @@ import Datastore from "nedb";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
|
|
||||||
const log = require("electron-log");
|
import { logInfo, logError, LogModule, logDebug } from "../utils/log";
|
||||||
|
|
||||||
const proxyDB = new Datastore({
|
const proxyDB = new Datastore({
|
||||||
autoload: true,
|
autoload: true,
|
||||||
filename: path.join(app.getPath("userData"), "proxy.db")
|
filename: path.join(app.getPath("userData"), "proxy.db")
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增代理
|
|
||||||
* @param proxy
|
|
||||||
* @param cb
|
|
||||||
*/
|
|
||||||
export const insertProxy = (
|
export const insertProxy = (
|
||||||
proxy: Proxy,
|
proxy: Proxy,
|
||||||
cb?: (err: Error | null, document: Proxy) => void
|
cb?: (err: Error | null, document: Proxy) => void
|
||||||
) => {
|
) => {
|
||||||
log.debug(`新增代理:${JSON.stringify(proxy)}`);
|
logInfo(LogModule.DB, `Inserting proxy: ${JSON.stringify(proxy)}`);
|
||||||
proxyDB.insert(proxy, cb);
|
proxyDB.insert(proxy, (err, document) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error inserting proxy: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(
|
||||||
|
LogModule.DB,
|
||||||
|
`Proxy inserted successfully: ${JSON.stringify(document)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (cb) cb(err, document);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除代理
|
|
||||||
* @param _id
|
|
||||||
* @param cb
|
|
||||||
*/
|
|
||||||
export const deleteProxyById = (
|
export const deleteProxyById = (
|
||||||
_id: string,
|
_id: string,
|
||||||
cb?: (err: Error | null, n: number) => void
|
cb?: (err: Error | null, n: number) => void
|
||||||
) => {
|
) => {
|
||||||
log.debug(`删除代理:${_id}`);
|
logDebug(`删除代理:${_id}`);
|
||||||
proxyDB.remove({ _id: _id }, cb);
|
logInfo(LogModule.DB, `Deleting proxy with ID: ${_id}`);
|
||||||
|
proxyDB.remove({ _id: _id }, (err, n) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error deleting proxy: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(
|
||||||
|
LogModule.DB,
|
||||||
|
`Proxy deleted successfully. Number of documents removed: ${n}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (cb) cb(err, n);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改代理
|
|
||||||
*/
|
|
||||||
export const updateProxyById = (
|
export const updateProxyById = (
|
||||||
proxy: Proxy,
|
proxy: Proxy,
|
||||||
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
||||||
) => {
|
) => {
|
||||||
log.debug(`修改代理:${proxy}`);
|
logDebug(`修改代理:${proxy}`);
|
||||||
proxyDB.update({ _id: proxy._id }, proxy, {}, cb);
|
logInfo(LogModule.DB, `Updating proxy: ${JSON.stringify(proxy)}`);
|
||||||
|
proxyDB.update(
|
||||||
|
{ _id: proxy._id },
|
||||||
|
proxy,
|
||||||
|
{},
|
||||||
|
(err, numberOfUpdated, upsert) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error updating proxy: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(
|
||||||
|
LogModule.DB,
|
||||||
|
`Proxy updated successfully. Updated: ${numberOfUpdated}, Upsert: ${upsert}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (cb) cb(err, numberOfUpdated, upsert);
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 查找
|
|
||||||
* @param cb
|
|
||||||
*/
|
|
||||||
export const listProxy = (
|
export const listProxy = (
|
||||||
callback: (err: Error | null, documents: Proxy[]) => void
|
callback: (err: Error | null, documents: Proxy[]) => void
|
||||||
) => {
|
) => {
|
||||||
proxyDB.find({}, callback);
|
logInfo(LogModule.DB, `Listing all proxies`);
|
||||||
|
proxyDB.find({}, (err, documents) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error listing proxies: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(
|
||||||
|
LogModule.DB,
|
||||||
|
`Proxies listed successfully. Count: ${documents.length}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
callback(err, documents);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据id查询
|
|
||||||
* @param id
|
|
||||||
* @param callback
|
|
||||||
*/
|
|
||||||
export const getProxyById = (
|
export const getProxyById = (
|
||||||
id: string,
|
id: string,
|
||||||
callback: (err: Error | null, document: Proxy) => void
|
callback: (err: Error | null, document: Proxy) => void
|
||||||
) => {
|
) => {
|
||||||
proxyDB.findOne({ _id: id }, callback);
|
logInfo(LogModule.DB, `Getting proxy by ID: ${id}`);
|
||||||
|
proxyDB.findOne({ _id: id }, (err, document) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error getting proxy by ID: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(
|
||||||
|
LogModule.DB,
|
||||||
|
`Proxy retrieved successfully: ${JSON.stringify(document)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
callback(err, document);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空代理
|
|
||||||
* @param cb
|
|
||||||
*/
|
|
||||||
export const clearProxy = (cb?: (err: Error | null, n: number) => void) => {
|
export const clearProxy = (cb?: (err: Error | null, n: number) => void) => {
|
||||||
proxyDB.remove({}, { multi: true }, cb);
|
logInfo(LogModule.DB, `Clearing all proxies`);
|
||||||
|
proxyDB.remove({}, { multi: true }, (err, n) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error clearing proxies: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(
|
||||||
|
LogModule.DB,
|
||||||
|
`Proxies cleared successfully. Number of documents removed: ${n}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (cb) cb(err, n);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新代理状态
|
|
||||||
* @param id id
|
|
||||||
* @param st 状态
|
|
||||||
* @param cb 回调
|
|
||||||
*/
|
|
||||||
export const updateProxyStatus = (
|
export const updateProxyStatus = (
|
||||||
id: string,
|
id: string,
|
||||||
st: boolean,
|
st: boolean,
|
||||||
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
|
||||||
) => {
|
) => {
|
||||||
proxyDB.update({ _id: id }, { $set: { status: st } }, {}, cb);
|
logInfo(LogModule.DB, `Updating proxy status for ID: ${id} to ${st}`);
|
||||||
|
proxyDB.update(
|
||||||
|
{ _id: id },
|
||||||
|
{ $set: { status: st } },
|
||||||
|
{},
|
||||||
|
(err, numberOfUpdated, upsert) => {
|
||||||
|
if (err) {
|
||||||
|
logError(
|
||||||
|
LogModule.DB,
|
||||||
|
`Error updating proxy status: ${err.message}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
logInfo(
|
||||||
|
LogModule.DB,
|
||||||
|
`Proxy status updated successfully. Updated: ${numberOfUpdated}, Upsert: ${upsert}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (cb) cb(err, numberOfUpdated, upsert);
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,7 +2,7 @@ import Datastore from "nedb";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
|
|
||||||
const log = require("electron-log");
|
import { logInfo, logError, LogModule, logDebug } from "../utils/log";
|
||||||
|
|
||||||
const versionDB = new Datastore({
|
const versionDB = new Datastore({
|
||||||
autoload: true,
|
autoload: true,
|
||||||
@ -10,7 +10,7 @@ const versionDB = new Datastore({
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增版本
|
* Insert version
|
||||||
* @param version
|
* @param version
|
||||||
* @param cb
|
* @param cb
|
||||||
*/
|
*/
|
||||||
@ -18,35 +18,73 @@ export const insertVersion = (
|
|||||||
version: FrpVersion,
|
version: FrpVersion,
|
||||||
cb?: (err: Error | null, document: any) => void
|
cb?: (err: Error | null, document: any) => void
|
||||||
) => {
|
) => {
|
||||||
log.debug(`新增版本:${JSON.stringify(version)}`);
|
logInfo(LogModule.DB, `Inserting version: ${JSON.stringify(version)}`);
|
||||||
versionDB.insert(version, cb);
|
versionDB.insert(version, (err, document) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error inserting version: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(LogModule.DB, `Version inserted successfully: ${JSON.stringify(document)}`);
|
||||||
|
}
|
||||||
|
if (cb) cb(err, document);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找
|
* List versions
|
||||||
* @param cb
|
* @param cb
|
||||||
*/
|
*/
|
||||||
export const listVersion = (
|
export const listVersion = (
|
||||||
callback: (err: Error | null, documents: FrpVersion[]) => void
|
callback: (err: Error | null, documents: FrpVersion[]) => void
|
||||||
) => {
|
) => {
|
||||||
versionDB.find({}, callback);
|
logInfo(LogModule.DB, "Listing all versions.");
|
||||||
|
versionDB.find({}, (err, documents) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error listing versions: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(LogModule.DB, `Successfully listed versions: ${documents.length} found.`);
|
||||||
|
}
|
||||||
|
callback(err, documents);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getVersionById = (
|
export const getVersionById = (
|
||||||
id: number,
|
id: number,
|
||||||
callback: (err: Error | null, document: FrpVersion) => void
|
callback: (err: Error | null, document: FrpVersion) => void
|
||||||
) => {
|
) => {
|
||||||
versionDB.findOne({ id: id }, callback);
|
logInfo(LogModule.DB, `Retrieving version by ID: ${id}`);
|
||||||
|
versionDB.findOne({ id: id }, (err, document) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error retrieving version by ID: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(LogModule.DB, `Version retrieved successfully: ${JSON.stringify(document)}`);
|
||||||
|
}
|
||||||
|
callback(err, document);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteVersionById = (
|
export const deleteVersionById = (
|
||||||
id: string,
|
id: string,
|
||||||
callback: (err: Error | null, document: any) => void
|
callback: (err: Error | null, document: any) => void
|
||||||
) => {
|
) => {
|
||||||
log.debug(`删除版本:${id}`);
|
logInfo(LogModule.DB, `Deleting version: ${id}`);
|
||||||
versionDB.remove({ id: id }, callback);
|
versionDB.remove({ id: id }, (err, document) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error deleting version: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(LogModule.DB, `Version deleted successfully: ${id}`);
|
||||||
|
}
|
||||||
|
callback(err, document);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const clearVersion = (cb?: (err: Error | null, n: number) => void) => {
|
export const clearVersion = (cb?: (err: Error | null, n: number) => void) => {
|
||||||
versionDB.remove({}, { multi: true }, cb);
|
logInfo(LogModule.DB, "Clearing all versions from the database.");
|
||||||
|
versionDB.remove({}, { multi: true }, (err, n) => {
|
||||||
|
if (err) {
|
||||||
|
logError(LogModule.DB, `Error clearing versions: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
logInfo(LogModule.DB, `Successfully cleared versions. Number of documents removed: ${n}`);
|
||||||
|
}
|
||||||
|
if (cb) cb(err, n);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -3,9 +3,8 @@ import log from "electron-log";
|
|||||||
export enum LogModule {
|
export enum LogModule {
|
||||||
APP = "app",
|
APP = "app",
|
||||||
FRP_CLIENT = "frpc client",
|
FRP_CLIENT = "frpc client",
|
||||||
LOGGER = "logger",
|
|
||||||
GITHUB = "github",
|
GITHUB = "github",
|
||||||
STORAGE = ""
|
DB = "db"
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initLog = () => {
|
export const initLog = () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user