This commit is contained in:
luke 2025-06-24 12:33:16 +08:00
parent debf2fbbb2
commit ddd94b3681
6 changed files with 68 additions and 1 deletions

View File

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

View File

@ -21,6 +21,7 @@
<div id="userName">未登录</div> <div id="userName">未登录</div>
<div class="dropdown-item" id="openUploaderMenu">上传文件</div> <div class="dropdown-item" id="openUploaderMenu">上传文件</div>
<div id="settingsBtn" class="logout-option">设置</div> <div id="settingsBtn" class="logout-option">设置</div>
<div id="testBtn" class="logout-option">test</div>
<div id="logoutBtn" class="logout-option">退出登录</div> <div id="logoutBtn" class="logout-option">退出登录</div>
</div> </div>
</div> </div>

13
pages/test.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SSE 测试</title>
</head>
<body>
<h3>SSE 结果:</h3>
<pre id="output"></pre>
<script src="../scripts/test.js"></script>
</body>
</html>

View File

@ -15,4 +15,5 @@
| 2025.06.20 | V2.0.9 | Luke.Ye | 上传记录页面支持删除历史记录会同时清空对象存储和ES | | 2025.06.20 | V2.0.9 | Luke.Ye | 上传记录页面支持删除历史记录会同时清空对象存储和ES |
| 2025.06.22 | V2.0.10 | Luke.Ye | 搜索结果页分页展示优化 | | 2025.06.22 | V2.0.10 | Luke.Ye | 搜索结果页分页展示优化 |
| 2025.06.23 | V2.0.11 | Luke.Ye | 准备做llm接口迁移 | | 2025.06.23 | V2.0.11 | Luke.Ye | 准备做llm接口迁移 |
| 2025.06.24 | V2.0.12 | Luke.Ye | 添加测试页面 |

View File

@ -46,6 +46,7 @@ document.addEventListener("DOMContentLoaded", async () => {
const userDropdown = document.getElementById("userDropdown"); const userDropdown = document.getElementById("userDropdown");
const openTabBtn = document.getElementById("openTabBtn"); const openTabBtn = document.getElementById("openTabBtn");
const settingsBtn = document.getElementById("settingsBtn"); const settingsBtn = document.getElementById("settingsBtn");
const testBtn = document.getElementById("testBtn");
const openUploaderMenu = document.getElementById("openUploaderMenu"); const openUploaderMenu = document.getElementById("openUploaderMenu");
const tabEs = document.getElementById("tabEs"); const tabEs = document.getElementById("tabEs");
const tabAi = document.getElementById("tabAi"); const tabAi = document.getElementById("tabAi");
@ -297,6 +298,9 @@ document.addEventListener("DOMContentLoaded", async () => {
settingsBtn?.addEventListener("click", () => { settingsBtn?.addEventListener("click", () => {
chrome.tabs.create({ url: chrome.runtime.getURL("pages/settings.html") }); chrome.tabs.create({ url: chrome.runtime.getURL("pages/settings.html") });
}); });
testBtn?.addEventListener("click", () => {
chrome.tabs.create({ url: chrome.runtime.getURL("pages/test.html") });
});
openUploaderMenu?.addEventListener("click", () => { openUploaderMenu?.addEventListener("click", () => {
const uploaderUrl = chrome.runtime ? chrome.runtime.getURL("pages/uploader.html") : "pages/uploader.html"; const uploaderUrl = chrome.runtime ? chrome.runtime.getURL("pages/uploader.html") : "pages/uploader.html";
window.open(uploaderUrl, "_blank"); window.open(uploaderUrl, "_blank");

48
scripts/test.js Normal file
View File

@ -0,0 +1,48 @@
const output = document.getElementById("output");
fetch("http://app-test.wisdompulse.cn/api/v1/llm/demo", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "text/event-stream",
"Authorization": "Bearer test"
},
body: JSON.stringify({})
}).then(response => {
const reader = response.body.getReader();
const decoder = new TextDecoder("utf-8");
let buffer = "";
function read() {
reader.read().then(({ done, value }) => {
if (done) {
output.textContent += "\n[连接结束]";
return;
}
buffer += decoder.decode(value, { stream: true });
// 拆解成 SSE 事件格式:每段以 \n\n 分隔
const parts = buffer.split('\n\n');
buffer = parts.pop(); // 留给下一次未完整的部分
for (const part of parts) {
const line = part.trim();
if (line.startsWith('data:')) {
const jsonStr = line.substring(5).trim();
try {
const data = JSON.parse(jsonStr);
output.textContent += `收到:${data.content || '[无内容]'}\n`;
} catch (e) {
output.textContent += `解析失败:${jsonStr}\n`;
}
}
}
read();
});
}
read();
});