修复登录token无效bug

This commit is contained in:
luke 2025-06-02 19:31:51 +08:00
parent 1398827d0e
commit e0b6401eab
3 changed files with 33 additions and 14 deletions

View File

@ -1,6 +1,12 @@
const defaultConfig = { const defaultConfig = {
tokenExpireHours: 24, tokenExpireHours: 24,
apiConfig: { apiConfig: {
materialPublicUrl: {
name: "材料公开地址",
url: "http://share.wisdompulse.cn/public",
requestParams: [],
responseParams: []
},
esSearch: { esSearch: {
name: "ES 搜索接口", name: "ES 搜索接口",
url: "http://app.wisdompulse.cn/search", url: "http://app.wisdompulse.cn/search",
@ -15,12 +21,6 @@ const defaultConfig = {
{ label: "分页大小字段", field: "size" } { label: "分页大小字段", field: "size" }
] ]
}, },
materialPublicUrl: {
name: "材料公开地址",
url: "http://share.wisdompulse.cn/public",
requestParams: [],
responseParams: []
},
login: { login: {
name: "登录接口", name: "登录接口",
url: "http://app.wisdompulse.cn/api/v1/user/login", url: "http://app.wisdompulse.cn/api/v1/user/login",
@ -34,20 +34,20 @@ const defaultConfig = {
] ]
}, },
filePath: { filePath: {
name: "获取文件路径接口", name: "获取文件路径接口(批量)",
url: "http://app.wisdompulse.cn/search/file-path", url: "http://app.wisdompulse.cn/search/file-path",
requestParams: [ requestParams: [
{ label: "文件名字段", field: "filename" } { label: "文件名数组字段", field: "fileNames" }
], ],
responseParams: [ responseParams: [
{ label: "路径字段", field: "filepath" } { label: "路径映射字段", field: "filePaths" }
] ]
}, },
llmToken: { llmToken: {
name: "获取 AnythingLLM Token 接口", name: "获取 AnythingLLM Token 接口",
url: "http://llm.wisdompulse.cn/api/request-token", url: "http://llm.wisdompulse.cn/api/request-token",
requestParams: [ requestParams: [
{ label: "用户名字段", field: "username" } { label: "密码字段", field: "password" }
], ],
responseParams: [ responseParams: [
{ label: "Token 字段", field: "token" } { label: "Token 字段", field: "token" }
@ -65,8 +65,8 @@ const defaultConfig = {
name: "指定工作区对话接口", name: "指定工作区对话接口",
url: "http://llm.wisdompulse.cn/api/workspace/${workId}/stream-chat", url: "http://llm.wisdompulse.cn/api/workspace/${workId}/stream-chat",
requestParams: [ requestParams: [
{ label: "问题字段", field: "prompt" }, { label: "问题字段", field: "message" },
{ label: "历史字段", field: "messages" } { label: "历史字段", field: "attachments" }
], ],
responseParams: [] responseParams: []
} }
@ -98,4 +98,3 @@ function loadMergedConfig() {
}); });
} }
window.loadMergedConfig = loadMergedConfig;

View File

@ -1,6 +1,6 @@
document.addEventListener("DOMContentLoaded", async function () { document.addEventListener("DOMContentLoaded", async function () {
const config = await window.loadMergedConfig(); const config = await loadMergedConfig();
const loginConf = config.apiConfig.login || {}; const loginConf = config.apiConfig.login || {};
const loginUrl = loginConf.url; const loginUrl = loginConf.url;

View File

@ -29,6 +29,26 @@ document.addEventListener("DOMContentLoaded", async () => {
}); });
} }
async function loadToken() {
return new Promise((resolve) => {
chrome.storage.local.get(["token", "username", "loginAt"], async (res) => {
const mergedConfig = await loadMergedConfig();
const expireMs = mergedConfig.tokenExpireHours * 60 * 60 * 1000;
const now = Date.now();
if (res.token && res.loginAt && now - res.loginAt < expireMs) {
resolve({ token: res.token, username: res.username });
} else {
resolve(null);
}
});
});
}
async function handleLogout() {
await chrome.storage.local.remove(["token", "username", "loginAt"]);
location.href = chrome.runtime.getURL("pages/login.html");
}
const input = document.getElementById("searchInput"); const input = document.getElementById("searchInput");
const searchBtn = document.getElementById("searchBtn"); const searchBtn = document.getElementById("searchBtn");
const clearBtn = document.getElementById("clearHistoryBtn"); const clearBtn = document.getElementById("clearHistoryBtn");