From ddd94b3681316404900847f03171f95dbb18d7f5 Mon Sep 17 00:00:00 2001 From: luke Date: Tue, 24 Jun 2025 12:33:16 +0800 Subject: [PATCH] add test --- manifest.json | 2 +- pages/popup.html | 1 + pages/test.html | 13 +++++++++++++ readme.md | 1 + scripts/popup.js | 4 ++++ scripts/test.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 pages/test.html create mode 100644 scripts/test.js diff --git a/manifest.json b/manifest.json index 6c825af..de79670 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "渠道应用开发部知识库", - "version": "2.0.11", + "version": "2.0.12", "description": "通过关键词快速搜索内部文档", "permissions": ["storage"], "host_permissions": [ diff --git a/pages/popup.html b/pages/popup.html index 76992d6..2048683 100644 --- a/pages/popup.html +++ b/pages/popup.html @@ -21,6 +21,7 @@
未登录
设置
+
test
退出登录
diff --git a/pages/test.html b/pages/test.html new file mode 100644 index 0000000..dc11e86 --- /dev/null +++ b/pages/test.html @@ -0,0 +1,13 @@ + + + + + SSE 测试 + + +

SSE 结果:

+

+
+
+
+
diff --git a/readme.md b/readme.md
index 559f51d..a30447c 100644
--- a/readme.md
+++ b/readme.md
@@ -15,4 +15,5 @@
 | 2025.06.20 | V2.0.9  | Luke.Ye | 上传记录页面支持删除历史记录(会同时清空对象存储和ES) |
 | 2025.06.22 | V2.0.10 | Luke.Ye | 搜索结果页分页展示优化                  |
 | 2025.06.23 | V2.0.11 | Luke.Ye | 准备做llm接口迁移                   |
+| 2025.06.24 | V2.0.12 | Luke.Ye | 添加测试页面                       |
 
diff --git a/scripts/popup.js b/scripts/popup.js
index a4f4169..c577135 100644
--- a/scripts/popup.js
+++ b/scripts/popup.js
@@ -46,6 +46,7 @@ document.addEventListener("DOMContentLoaded", async () => {
     const userDropdown = document.getElementById("userDropdown");
     const openTabBtn = document.getElementById("openTabBtn");
     const settingsBtn = document.getElementById("settingsBtn");
+    const testBtn = document.getElementById("testBtn");
     const openUploaderMenu = document.getElementById("openUploaderMenu");
     const tabEs = document.getElementById("tabEs");
     const tabAi = document.getElementById("tabAi");
@@ -297,6 +298,9 @@ document.addEventListener("DOMContentLoaded", async () => {
     settingsBtn?.addEventListener("click", () => {
         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", () => {
         const uploaderUrl = chrome.runtime ? chrome.runtime.getURL("pages/uploader.html") : "pages/uploader.html";
         window.open(uploaderUrl, "_blank");
diff --git a/scripts/test.js b/scripts/test.js
new file mode 100644
index 0000000..cd63da9
--- /dev/null
+++ b/scripts/test.js
@@ -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();
+});
+