mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-04 06:31:13 +00:00
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:
parent
94f07ab98b
commit
d9297c1e10
@ -7,7 +7,7 @@
|
|||||||
"description": "NapCat 内置插件",
|
"description": "NapCat 内置插件",
|
||||||
"author": "NapNeko",
|
"author": "NapNeko",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"napcat-types": "0.0.14"
|
"napcat-types": "0.0.15"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.0.1"
|
"@types/node": "^22.0.1"
|
||||||
|
|||||||
@ -259,11 +259,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="static-content">
|
<div id="static-content">
|
||||||
<p style="color: var(--text-secondary); font-size: 13px; margin-bottom: 12px;">
|
<p style="color: var(--text-secondary); font-size: 13px; margin-bottom: 12px;">
|
||||||
测试插件静态资源服务是否正常工作
|
测试插件静态资源服务是否正常工作(不需要鉴权)
|
||||||
</p>
|
</p>
|
||||||
<div class="actions" style="margin-top: 0;">
|
<div class="actions" style="margin-top: 0;">
|
||||||
<button class="btn btn-primary" onclick="testStaticResource()">
|
<button class="btn btn-primary" onclick="testStaticResource()">
|
||||||
获取 test.txt
|
获取 test.txt(文件系统)
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-primary" onclick="testMemoryResource()">
|
||||||
|
获取 info.json(内存生成)
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="static-result" style="margin-top: 12px;"></div>
|
<div id="static-result" style="margin-top: 12px;"></div>
|
||||||
@ -280,8 +283,12 @@
|
|||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const webuiToken = urlParams.get('webui_token') || '';
|
const webuiToken = urlParams.get('webui_token') || '';
|
||||||
|
|
||||||
// 插件自行管理 API 调用
|
// 插件 API 基础路径(需要鉴权)
|
||||||
const apiBase = '/api/Plugin/ext/napcat-plugin-builtin';
|
const apiBase = '/api/Plugin/ext/napcat-plugin-builtin';
|
||||||
|
// 插件静态资源基础路径(不需要鉴权)
|
||||||
|
const staticBase = '/plugin/napcat-plugin-builtin/files';
|
||||||
|
// 插件内存资源基础路径(不需要鉴权)
|
||||||
|
const memBase = '/plugin/napcat-plugin-builtin/mem';
|
||||||
|
|
||||||
// 封装 fetch,自动携带认证
|
// 封装 fetch,自动携带认证
|
||||||
async function authFetch (url, options = {}) {
|
async function authFetch (url, options = {}) {
|
||||||
@ -392,12 +399,13 @@
|
|||||||
resultDiv.innerHTML = '<div class="loading">加载中</div>';
|
resultDiv.innerHTML = '<div class="loading">加载中</div>';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await authFetch(`${apiBase}/static/test.txt`);
|
// 静态资源不需要鉴权,直接请求
|
||||||
|
const response = await fetch(`${staticBase}/static/test.txt`);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
resultDiv.innerHTML = `
|
resultDiv.innerHTML = `
|
||||||
<div style="background: var(--bg-item); border: 1px solid var(--border-color); border-radius: 8px; padding: 12px;">
|
<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>
|
<pre style="font-family: Monaco, Consolas, monospace; font-size: 12px; color: var(--text-primary); white-space: pre-wrap; margin: 0;">${text}</pre>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -408,6 +416,30 @@
|
|||||||
resultDiv.innerHTML = `<div class="error">请求失败: ${error.message}</div>`;
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "napcat-types",
|
"name": "napcat-types",
|
||||||
"version": "0.0.14",
|
"version": "0.0.15",
|
||||||
"private": false,
|
"private": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "./napcat-types/index.d.ts",
|
"types": "./napcat-types/index.d.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' });
|
||||||
});
|
});
|
||||||
|
|
||||||
// 插件文件系统静态资源路由(不需要鉴权)
|
// 插件文件系统静态资源路由(不需要鉴权)
|
||||||
|
|||||||
@ -232,8 +232,8 @@ importers:
|
|||||||
packages/napcat-plugin-builtin:
|
packages/napcat-plugin-builtin:
|
||||||
dependencies:
|
dependencies:
|
||||||
napcat-types:
|
napcat-types:
|
||||||
specifier: 0.0.14
|
specifier: 0.0.15
|
||||||
version: 0.0.14
|
version: 0.0.15
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^22.0.1
|
specifier: ^22.0.1
|
||||||
@ -5448,8 +5448,8 @@ packages:
|
|||||||
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
napcat-types@0.0.14:
|
napcat-types@0.0.15:
|
||||||
resolution: {integrity: sha512-q5ke+vzzXeZkYPsr9jmj94NxgH63/xv5yS/lPEU++A3x2mOM8SYJqdFEMbHG1QIFciyH1u3qnnNiJ0mBxOBFbA==}
|
resolution: {integrity: sha512-uOkaQPO3SVgkO/Rt0cQ+02wCI9C9jzdYVViHByHrr9sA+2ZjT1HV5nVSgNNQXUaZ9q405LUu45xQ4lysNyLpBA==}
|
||||||
|
|
||||||
napcat.protobuf@1.1.4:
|
napcat.protobuf@1.1.4:
|
||||||
resolution: {integrity: sha512-z7XtLSBJ/PxmYb0VD/w+eYr/X3LyGz+SZ2QejFTOczwt6zWNxy2yV1mTMTvJoc3BWkI3ESVFRxkuT6+pj1tb1Q==}
|
resolution: {integrity: sha512-z7XtLSBJ/PxmYb0VD/w+eYr/X3LyGz+SZ2QejFTOczwt6zWNxy2yV1mTMTvJoc3BWkI3ESVFRxkuT6+pj1tb1Q==}
|
||||||
@ -12774,7 +12774,7 @@ snapshots:
|
|||||||
|
|
||||||
nanoid@3.3.11: {}
|
nanoid@3.3.11: {}
|
||||||
|
|
||||||
napcat-types@0.0.14:
|
napcat-types@0.0.15:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@sinclair/typebox': 0.34.41
|
'@sinclair/typebox': 0.34.41
|
||||||
'@types/node': 22.19.1
|
'@types/node': 22.19.1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user