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(`