修复切换家用ipv6问题“
This commit is contained in:
parent
500c6b5b19
commit
ea2d83087e
@ -1,13 +1,14 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "私域知识库",
|
||||
"version": "2.1.0",
|
||||
"version": "2.1.2",
|
||||
"description": "通过关键词快速搜索内部文档",
|
||||
"permissions": ["storage"],
|
||||
"host_permissions": [
|
||||
"http://app.wisdompulse.cn/*",
|
||||
"http://share.wisdompulse.cn/*",
|
||||
"http://app-test.wisdompulse.cn/*"
|
||||
"http://app-test.wisdompulse.cn/*",
|
||||
"https://share.wisdompulse.cn/*"
|
||||
],
|
||||
"action": {
|
||||
"default_popup": "pages/index.html",
|
||||
|
||||
@ -5,7 +5,7 @@ const defaultConfig = {
|
||||
apiConfig: {
|
||||
materialPublicUrl: {
|
||||
name: "材料公开地址",
|
||||
url: "http://share.wisdompulse.cn/public",
|
||||
url: "https://share.wisdompulse.cn/public",
|
||||
requestParams: [],
|
||||
responseParams: []
|
||||
},
|
||||
@ -73,7 +73,6 @@ const defaultConfig = {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function loadMergedConfig() {
|
||||
return new Promise((resolve) => {
|
||||
chrome.storage.local.get(["customConfig"], (res) => {
|
||||
@ -85,15 +84,20 @@ function loadMergedConfig() {
|
||||
res.customConfig.llmTokenExpireHours != null ? res.customConfig.llmTokenExpireHours : merged.llmTokenExpireHours;
|
||||
merged.llmWorkspaceName =
|
||||
res.customConfig.llmWorkspaceName != null ? res.customConfig.llmWorkspaceName : merged.llmWorkspaceName;
|
||||
|
||||
for (const key in merged.apiConfig) {
|
||||
const override = res.customConfig.apiConfig?.[key];
|
||||
if (override) {
|
||||
merged.apiConfig[key].url = override.url || merged.apiConfig[key].url;
|
||||
merged.apiConfig[key].requestParams.forEach((param, i) => {
|
||||
if (override.requestParams?.[i]?.field) param.field = override.requestParams[i].field;
|
||||
if (override.requestParams?.[i]?.field) {
|
||||
param.field = override.requestParams[i].field;
|
||||
}
|
||||
});
|
||||
merged.apiConfig[key].responseParams.forEach((param, i) => {
|
||||
if (override.responseParams?.[i]?.field) param.field = override.responseParams[i].field;
|
||||
if (override.responseParams?.[i]?.field) {
|
||||
param.field = override.responseParams[i].field;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -102,4 +106,3 @@ function loadMergedConfig() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async function () {
|
||||
const config = await loadMergedConfig();
|
||||
const loginConf = config.apiConfig.login || {};
|
||||
@ -7,21 +6,25 @@ document.addEventListener("DOMContentLoaded", async function () {
|
||||
const reqParams = loginConf.requestParams || [];
|
||||
const resParams = loginConf.responseParams || [];
|
||||
|
||||
// 提取字段名(带默认值)
|
||||
const reqUsernameField = reqParams.find(p => p.label.includes("用户名"))?.field || "username";
|
||||
const reqPasswordField = reqParams.find(p => p.label.includes("密码"))?.field || "password";
|
||||
const resTokenField = resParams.find(p => p.label.includes("Token"))?.field || "token";
|
||||
const resUsernameField = resParams.find(p => p.label.includes("用户名"))?.field || "username";
|
||||
|
||||
document.getElementById("loginBtn").addEventListener("click", doLogin);
|
||||
const loginBtn = document.getElementById("loginBtn");
|
||||
const errorBox = document.getElementById("errorBox");
|
||||
|
||||
loginBtn.addEventListener("click", doLogin);
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter") doLogin();
|
||||
if (e.key === "Enter") {
|
||||
doLogin();
|
||||
}
|
||||
});
|
||||
|
||||
function doLogin() {
|
||||
async function doLogin() {
|
||||
const username = document.getElementById("username").value.trim();
|
||||
const password = document.getElementById("password").value.trim();
|
||||
const errorBox = document.getElementById("errorBox");
|
||||
|
||||
errorBox.textContent = "";
|
||||
|
||||
if (!username || !password) {
|
||||
@ -33,17 +36,29 @@ document.addEventListener("DOMContentLoaded", async function () {
|
||||
requestBody[reqUsernameField] = username;
|
||||
requestBody[reqPasswordField] = password;
|
||||
|
||||
fetch(loginUrl, {
|
||||
loginBtn.disabled = true;
|
||||
loginBtn.textContent = "登录中...";
|
||||
|
||||
try {
|
||||
const res = await fetch(loginUrl, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(requestBody)
|
||||
})
|
||||
.then(res => res.json().then(data => ({ status: res.status, body: data })))
|
||||
.then(({ status, body }) => {
|
||||
});
|
||||
|
||||
const rawText = await res.text();
|
||||
let body = {};
|
||||
try {
|
||||
body = rawText ? JSON.parse(rawText) : {};
|
||||
} catch (e) {
|
||||
body = {};
|
||||
}
|
||||
|
||||
const token = body[resTokenField];
|
||||
const returnedUser = body[resUsernameField] || username;
|
||||
|
||||
if (status === 200 && token) {
|
||||
if (res.status === 200 && token) {
|
||||
chrome.storage.local.set({
|
||||
token: token,
|
||||
username: returnedUser,
|
||||
@ -51,12 +66,16 @@ document.addEventListener("DOMContentLoaded", async function () {
|
||||
}, () => {
|
||||
window.location.href = chrome.runtime.getURL("pages/popup.html");
|
||||
});
|
||||
} else {
|
||||
errorBox.textContent = body.message || "登录失败";
|
||||
return;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
|
||||
errorBox.textContent = body.message || body.msg || "登录失败";
|
||||
} catch (e) {
|
||||
console.error("login error:", e);
|
||||
errorBox.textContent = "网络错误,请稍后重试";
|
||||
});
|
||||
} finally {
|
||||
loginBtn.disabled = false;
|
||||
loginBtn.textContent = "登录";
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user