From d9297c1e1013f80d62a6cbaff1178211de8b3063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Mon, 2 Feb 2026 15:35:26 +0800 Subject: [PATCH] Bump napcat-types & add plugin static/memory tests Upgrade napcat-types to v0.0.15 and update the built-in plugin UI to test both filesystem and in-memory static resources. dashboard.html: clarify which plugin endpoints require auth, add buttons and a testMemoryResource() function that fetches an in-memory JSON resource, and add staticBase/memBase variables for non-auth static routes. napcat-webui-backend: return after 404 for missing memory files to stop further handling. (Lockfile updated accordingly.) --- packages/napcat-plugin-builtin/package.json | 2 +- .../webui/dashboard.html | 42 ++++++++++++++++--- packages/napcat-types/package.public.json | 2 +- packages/napcat-webui-backend/index.ts | 2 +- pnpm-lock.yaml | 10 ++--- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/packages/napcat-plugin-builtin/package.json b/packages/napcat-plugin-builtin/package.json index b11601e0..6dbb2d8b 100644 --- a/packages/napcat-plugin-builtin/package.json +++ b/packages/napcat-plugin-builtin/package.json @@ -7,7 +7,7 @@ "description": "NapCat 内置插件", "author": "NapNeko", "dependencies": { - "napcat-types": "0.0.14" + "napcat-types": "0.0.15" }, "devDependencies": { "@types/node": "^22.0.1" diff --git a/packages/napcat-plugin-builtin/webui/dashboard.html b/packages/napcat-plugin-builtin/webui/dashboard.html index 32268b40..b0a3f2b2 100644 --- a/packages/napcat-plugin-builtin/webui/dashboard.html +++ b/packages/napcat-plugin-builtin/webui/dashboard.html @@ -259,11 +259,14 @@

- 测试插件静态资源服务是否正常工作 + 测试插件静态资源服务是否正常工作(不需要鉴权)

+
@@ -280,8 +283,12 @@ const urlParams = new URLSearchParams(window.location.search); const webuiToken = urlParams.get('webui_token') || ''; - // 插件自行管理 API 调用 + // 插件 API 基础路径(需要鉴权) const apiBase = '/api/Plugin/ext/napcat-plugin-builtin'; + // 插件静态资源基础路径(不需要鉴权) + const staticBase = '/plugin/napcat-plugin-builtin/files'; + // 插件内存资源基础路径(不需要鉴权) + const memBase = '/plugin/napcat-plugin-builtin/mem'; // 封装 fetch,自动携带认证 async function authFetch (url, options = {}) { @@ -392,12 +399,13 @@ resultDiv.innerHTML = '
加载中
'; try { - const response = await authFetch(`${apiBase}/static/test.txt`); + // 静态资源不需要鉴权,直接请求 + const response = await fetch(`${staticBase}/static/test.txt`); if (response.ok) { const text = await response.text(); resultDiv.innerHTML = `
-
静态资源访问成功
+
文件系统静态资源访问成功
${text}
`; @@ -408,6 +416,30 @@ resultDiv.innerHTML = `
请求失败: ${error.message}
`; } } + + // 测试内存资源 + async function testMemoryResource () { + const resultDiv = document.getElementById('static-result'); + resultDiv.innerHTML = '
加载中
'; + + try { + // 内存资源不需要鉴权,直接请求 + const response = await fetch(`${memBase}/dynamic/info.json`); + if (response.ok) { + const json = await response.json(); + resultDiv.innerHTML = ` +
+
内存生成资源访问成功
+
${JSON.stringify(json, null, 2)}
+
+ `; + } else { + resultDiv.innerHTML = `
请求失败: ${response.status} ${response.statusText}
`; + } + } catch (error) { + resultDiv.innerHTML = `
请求失败: ${error.message}
`; + } + } diff --git a/packages/napcat-types/package.public.json b/packages/napcat-types/package.public.json index 73700bde..5201bb6f 100644 --- a/packages/napcat-types/package.public.json +++ b/packages/napcat-types/package.public.json @@ -1,6 +1,6 @@ { "name": "napcat-types", - "version": "0.0.14", + "version": "0.0.15", "private": false, "type": "module", "types": "./napcat-types/index.d.ts", diff --git a/packages/napcat-webui-backend/index.ts b/packages/napcat-webui-backend/index.ts index 3cb7cb17..e45f0dec 100644 --- a/packages/napcat-webui-backend/index.ts +++ b/packages/napcat-webui-backend/index.ts @@ -329,7 +329,7 @@ export async function InitWebUi (logger: ILogWrapper, pathWrapper: NapCatPathWra } } } - res.status(404).json({ code: -1, message: 'Memory file not found' }); + return res.status(404).json({ code: -1, message: 'Memory file not found' }); }); // 插件文件系统静态资源路由(不需要鉴权) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a5dc338b..37a2c8a7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -232,8 +232,8 @@ importers: packages/napcat-plugin-builtin: dependencies: napcat-types: - specifier: 0.0.14 - version: 0.0.14 + specifier: 0.0.15 + version: 0.0.15 devDependencies: '@types/node': specifier: ^22.0.1 @@ -5448,8 +5448,8 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true - napcat-types@0.0.14: - resolution: {integrity: sha512-q5ke+vzzXeZkYPsr9jmj94NxgH63/xv5yS/lPEU++A3x2mOM8SYJqdFEMbHG1QIFciyH1u3qnnNiJ0mBxOBFbA==} + napcat-types@0.0.15: + resolution: {integrity: sha512-uOkaQPO3SVgkO/Rt0cQ+02wCI9C9jzdYVViHByHrr9sA+2ZjT1HV5nVSgNNQXUaZ9q405LUu45xQ4lysNyLpBA==} napcat.protobuf@1.1.4: resolution: {integrity: sha512-z7XtLSBJ/PxmYb0VD/w+eYr/X3LyGz+SZ2QejFTOczwt6zWNxy2yV1mTMTvJoc3BWkI3ESVFRxkuT6+pj1tb1Q==} @@ -12774,7 +12774,7 @@ snapshots: nanoid@3.3.11: {} - napcat-types@0.0.14: + napcat-types@0.0.15: dependencies: '@sinclair/typebox': 0.34.41 '@types/node': 22.19.1