diff --git a/manifest.json b/manifest.json index 7bde9e3..219f55c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "渠道应用开发部知识库", - "version": "2.0.2", + "version": "2.0.3", "description": "通过关键词快速搜索内部文档", "permissions": ["storage"], "host_permissions": [ diff --git a/readme.md b/readme.md index a2ad6a4..2e1dfc1 100644 --- a/readme.md +++ b/readme.md @@ -6,4 +6,5 @@ | 2025.06.02 | V2.0.0 | Luke.Ye | 完成插件配置化改造 | | 2025.06.03 | V2.0.1 | Luke.Ye | 完成llm token过期时间的配置化 | | 2025.06.03 | V2.0.2 | Luke.Ye | 支持LLM工作区配置化 | +| 2025.06.06 | V2.0.3 | Luke.Ye | 添加跳转页面权限校验 | diff --git a/scripts/auth.js b/scripts/auth.js index c5a0e67..16cd7ce 100644 --- a/scripts/auth.js +++ b/scripts/auth.js @@ -1,9 +1,24 @@ -function handleLogout() { +async function handleLogout(auth) { + let token = auth ? auth.token : null; + const mergedConfig = await loadMergedConfig(); + const logoutConf = mergedConfig.apiConfig.logout || {}; + try { + await fetch(logoutConf.url, { + method: "POST", + credentials: "include", // 关键:带 cookie + headers: token ? { "Authorization": token } : {} + }); + } catch (e) { + log("handleLogout error", e); + // 可以忽略网络异常,保证前端继续登出流程 + } + chrome.storage.local.remove(["token", "loginAt", "username"], () => { window.location.href = chrome.runtime.getURL("pages/login.html"); }); } + async function loadToken() { return new Promise((resolve) => { chrome.storage.local.get(["token", "username", "loginAt"], async (res) => { diff --git a/scripts/config.js b/scripts/config.js index 5bb93b3..b112147 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -35,6 +35,12 @@ const defaultConfig = { { label: "用户名字段", field: "username" } ] }, + logout: { + name: "登出接口", + url: "http://app.wisdompulse.cn/api/v1/user/logout", + requestParams: [], + responseParams: [] + }, filePath: { name: "获取文件路径接口(批量)", url: "http://app.wisdompulse.cn/search/file-path", diff --git a/scripts/popup.js b/scripts/popup.js index 0578ee7..5c60d13 100644 --- a/scripts/popup.js +++ b/scripts/popup.js @@ -76,7 +76,7 @@ document.addEventListener("DOMContentLoaded", async () => { let config = await loadMergedConfig(); const auth = await loadToken(); - if (!auth) return handleLogout(); + if (!auth) return handleLogout(auth); token = auth.token; userNameLabel.textContent = auth.username; @@ -249,7 +249,7 @@ document.addEventListener("DOMContentLoaded", async () => { chrome.storage.local.remove("searchHistory", () => renderHistoryTags()); }); - logoutBtn?.addEventListener("click", () => handleLogout()); + logoutBtn?.addEventListener("click", () => handleLogout(auth)); userAvatar?.addEventListener("click", () => { userDropdown.classList.toggle("hidden"); });