完成跳转页面权限校验

This commit is contained in:
luke 2025-06-05 23:53:12 +08:00
parent e34711793e
commit 2600624049
5 changed files with 26 additions and 4 deletions

View File

@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "渠道应用开发部知识库",
"version": "2.0.2",
"version": "2.0.3",
"description": "通过关键词快速搜索内部文档",
"permissions": ["storage"],
"host_permissions": [

View File

@ -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 | 添加跳转页面权限校验 |

View File

@ -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) => {

View File

@ -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",

View File

@ -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");
});