From e3dfffad7d99cfd348fef30548ab86578ac1ab8e Mon Sep 17 00:00:00 2001 From: iHeyTang Date: Mon, 11 Aug 2025 10:32:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=AF=B9=E8=AF=9D=E6=A1=86=E7=9A=84API=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86=E5=92=8C=E9=BB=98=E8=AE=A4=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/publisher.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/js/publisher.js b/js/publisher.js index abfbc10..aba716b 100644 --- a/js/publisher.js +++ b/js/publisher.js @@ -349,27 +349,25 @@ app.registerExtension({ } async function showSettingsDialog() { try { - const resp = await api.fetchApi("/publisher/settings", { - cache: "no-store", - }); - if (!resp.ok) { - throw new Error(`服务器错误: ${resp.status} ${resp.statusText}`); - } - const text = await resp.text(); - let settings; - try { - settings = text ? JSON.parse(text) : {}; - } catch (parseError) { - console.error("JSON解析失败:", parseError, "原始响应:", text); - settings = { api_url: "", host: "" }; - } + let settings = { api_url: "", host: "" }; - // 确保设置对象有必需的字段 - settings = { - api_url: settings.api_url || "", - host: settings.host || "", - ...settings, - }; + await api + .fetchApi("/publisher/settings", { + cache: "no-store", + }) + .then(async (resp) => { + if (!resp.ok) { + console.error(`服务器错误: ${resp.status} ${resp.statusText}`); + return; + } + const text = await resp.text(); + try { + settings = text ? JSON.parse(text) : {}; + } catch (parseError) { + console.error("JSON解析失败:", parseError, "原始响应:", text); + settings = { api_url: "", host: "" }; + } + }); settingsDialog.setContent(`