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