koishi-plugin-docker-control 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/control.js +13 -6
- package/lib/utils/render-modern.d.ts +26 -0
- package/lib/utils/render-modern.js +772 -0
- package/lib/utils/render.d.ts +4 -4
- package/lib/utils/render.js +1167 -322
- package/package.json +1 -1
package/lib/commands/control.js
CHANGED
|
@@ -10,13 +10,19 @@ const permission_check_1 = require("../utils/permission-check");
|
|
|
10
10
|
*/
|
|
11
11
|
function formatNet(bytes) {
|
|
12
12
|
const num = parseFloat(bytes);
|
|
13
|
-
if (isNaN(num))
|
|
14
|
-
|
|
13
|
+
if (isNaN(num)) {
|
|
14
|
+
// 如果无法解析为数字,可能已经包含单位,直接返回
|
|
15
|
+
return bytes;
|
|
16
|
+
}
|
|
17
|
+
if (num === 0)
|
|
18
|
+
return '0B';
|
|
15
19
|
if (num < 1024)
|
|
16
|
-
return
|
|
20
|
+
return num.toFixed(0) + 'B';
|
|
17
21
|
if (num < 1024 * 1024)
|
|
18
|
-
return (num / 1024).toFixed(
|
|
19
|
-
|
|
22
|
+
return (num / 1024).toFixed(2) + 'KB';
|
|
23
|
+
if (num < 1024 * 1024 * 1024)
|
|
24
|
+
return (num / 1024 / 1024).toFixed(2) + 'MB';
|
|
25
|
+
return (num / 1024 / 1024 / 1024).toFixed(2) + 'GB';
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
28
|
* 格式化容器搜索结果
|
|
@@ -271,7 +277,8 @@ function registerControlCommands(ctx, getService, config) {
|
|
|
271
277
|
lines.push('性能监控:');
|
|
272
278
|
lines.push(` CPU: ${stats.cpuPercent}`);
|
|
273
279
|
lines.push(` 内存: ${stats.memoryPercent} (${stats.memoryUsage} / ${stats.memoryLimit})`);
|
|
274
|
-
lines.push(`
|
|
280
|
+
lines.push(` 网络 ↓: ${formatNet(stats.networkIn)}`);
|
|
281
|
+
lines.push(` 网络 ↑: ${formatNet(stats.networkOut)}`);
|
|
275
282
|
lines.push(` 进程: ${stats.pids}`);
|
|
276
283
|
}
|
|
277
284
|
// 添加端口映射
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Context, h } from 'koishi';
|
|
2
|
+
import type { ContainerInfo } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* 渲染为图片(使用正确的 Koishi Puppeteer API)
|
|
5
|
+
*/
|
|
6
|
+
export declare function renderToImage(ctx: Context, html: string): Promise<h>;
|
|
7
|
+
/**
|
|
8
|
+
* 生成容器列表 HTML(现代化)
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateListHtml(data: Array<{
|
|
11
|
+
node: any;
|
|
12
|
+
containers: ContainerInfo[];
|
|
13
|
+
}>, title?: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* 生成节点列表 HTML(现代化)
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateNodesHtml(nodes: any[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* 生成容器日志 HTML(现代化)
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateLogsHtml(nodeName: string, containerName: string, logs: string, lineCount: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* 生成 Docker Compose 配置 HTML(现代化)
|
|
24
|
+
*/
|
|
25
|
+
export declare function generateComposeHtml(nodeName: string, containerName: string, projectName: string, filePath: string, serviceCount: number, composeContent: string): string;
|
|
26
|
+
export { generateInspectHtml, generateResultHtml, generateExecHtml, generateImagesHtml, generateNetworksHtml, generateVolumesHtml } from './render';
|