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.)
This commit is contained in:
手瓜一十雪 2026-02-02 15:35:26 +08:00
parent 94f07ab98b
commit d9297c1e10
5 changed files with 45 additions and 13 deletions

View File

@ -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"

View File

@ -259,11 +259,14 @@
</div>
<div id="static-content">
<p style="color: var(--text-secondary); font-size: 13px; margin-bottom: 12px;">
测试插件静态资源服务是否正常工作
测试插件静态资源服务是否正常工作(不需要鉴权)
</p>
<div class="actions" style="margin-top: 0;">
<button class="btn btn-primary" onclick="testStaticResource()">
获取 test.txt
获取 test.txt文件系统
</button>
<button class="btn btn-primary" onclick="testMemoryResource()">
获取 info.json内存生成
</button>
</div>
<div id="static-result" style="margin-top: 12px;"></div>
@ -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 = '<div class="loading">加载中</div>';
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 = `
<div style="background: var(--bg-item); border: 1px solid var(--border-color); border-radius: 8px; padding: 12px;">
<div style="font-size: 11px; color: var(--success-color); margin-bottom: 8px;">静态资源访问成功</div>
<div style="font-size: 11px; color: var(--success-color); margin-bottom: 8px;">文件系统静态资源访问成功</div>
<pre style="font-family: Monaco, Consolas, monospace; font-size: 12px; color: var(--text-primary); white-space: pre-wrap; margin: 0;">${text}</pre>
</div>
`;
@ -408,6 +416,30 @@
resultDiv.innerHTML = `<div class="error">请求失败: ${error.message}</div>`;
}
}
// 测试内存资源
async function testMemoryResource () {
const resultDiv = document.getElementById('static-result');
resultDiv.innerHTML = '<div class="loading">加载中</div>';
try {
// 内存资源不需要鉴权,直接请求
const response = await fetch(`${memBase}/dynamic/info.json`);
if (response.ok) {
const json = await response.json();
resultDiv.innerHTML = `
<div style="background: var(--bg-item); border: 1px solid var(--border-color); border-radius: 8px; padding: 12px;">
<div style="font-size: 11px; color: var(--success-color); margin-bottom: 8px;">内存生成资源访问成功</div>
<pre style="font-family: Monaco, Consolas, monospace; font-size: 12px; color: var(--text-primary); white-space: pre-wrap; margin: 0;">${JSON.stringify(json, null, 2)}</pre>
</div>
`;
} else {
resultDiv.innerHTML = `<div class="error">请求失败: ${response.status} ${response.statusText}</div>`;
}
} catch (error) {
resultDiv.innerHTML = `<div class="error">请求失败: ${error.message}</div>`;
}
}
</script>
</body>

View File

@ -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",

View File

@ -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' });
});
// 插件文件系统静态资源路由(不需要鉴权)

View File

@ -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