fix online status && license revoke

This commit is contained in:
rangang
2026-07-30 13:55:54 +08:00
parent e12134e40d
commit 66b7b73e75
7 changed files with 58 additions and 190 deletions
+22 -4
View File
@@ -20,6 +20,14 @@ const connectionState = {
};
let pendingReview = null;
function resolveCredentials(credentials = {}) {
return {
apiUrl: String(credentials.apiUrl || connectionState.apiUrl || API_URL).trim(),
adminToken: String(credentials.adminToken || connectionState.adminToken || process.env.B_ADMIN_TOKEN || ""),
deviceId: String(credentials.deviceId || connectionState.deviceId || "").trim()
};
}
function startPanelInboxPoller(window) {
if (!Number.isFinite(INBOX_POLL_INTERVAL_MS) || INBOX_POLL_INTERVAL_MS < 500) {
window.webContents.send("csv:watch-error", "POLL_INTERVAL_MS 必须大于或等于 500");
@@ -199,13 +207,23 @@ function registerHandlers() {
}
});
ipcMain.handle("license:list", (_event, credentials) =>
callServer({ type: "listLicenses" }, credentials));
callServer({ type: "listLicenses" }, resolveCredentials(credentials)));
ipcMain.handle("license:get", (_event, request) =>
callServer({ type: "getLicense", licenseId: request.licenseId }, request.credentials));
callServer(
{ type: "getLicense", licenseId: request.licenseId },
resolveCredentials(request.credentials)
));
ipcMain.handle("license:revoke", (_event, request) =>
callServer({ type: "revokeLicense", licenseId: request.licenseId, reason: request.reason }, request.credentials));
callServer(
{ type: "revokeLicense", licenseId: request.licenseId, reason: request.reason },
resolveCredentials(request.credentials)
));
ipcMain.handle("license:download", async (_event, request) => {
const result = await callServer({ type: "getLicense", licenseId: request.licenseId }, request.credentials);
const resolvedCredentials = resolveCredentials(request.credentials);
const result = await callServer(
{ type: "getLicense", licenseId: request.licenseId },
resolvedCredentials
);
if (typeof result.license?.license !== "string" || !result.license.license) {
throw new Error("Server 未返回许可证原文,无法下载");
}
+15 -3
View File
@@ -20,9 +20,21 @@ async function callServer(payload, options = {}) {
headers: { "content-type": "application/json" },
body: JSON.stringify({ ...payload, adminToken })
});
if (!response.ok) throw new Error(`server 请求失败: HTTP ${response.status}`);
const result = await response.json();
let result = null;
try {
result = await response.json();
} catch {
result = null;
}
if (!response.ok) {
const message = result && typeof result.errMsg === "string" && result.errMsg
? result.errMsg
: `server 请求失败: HTTP ${response.status}`;
throw new Error(message);
}
if (!result || typeof result !== "object") {
throw new Error("server 返回格式无效");
}
if (!result.success) throw new Error(result.errMsg || "server 返回失败");
return result;
}