AIClient-2-API/src/ui-modules/plugin-api.js
hex2077 245583b96a feat(logging): 添加日志系统配置和下载功能
- 新增日志系统配置选项,支持日志级别、输出模式、文件大小等设置
- 添加当日日志文件下载功能,可通过Web界面直接下载
- 将console.log/error替换为结构化logger,提升日志可管理性
- 在日志页面添加自动滚动到底部功能
- 更新配置示例文件,包含完整的日志配置参数
2026-01-25 17:24:39 +08:00

77 lines
No EOL
2.3 KiB
JavaScript

import { getPluginManager } from '../core/plugin-manager.js';
import logger from '../utils/logger.js';
import { getRequestBody } from '../utils/common.js';
import { broadcastEvent } from './event-broadcast.js';
/**
* 获取插件列表
*/
export async function handleGetPlugins(req, res) {
try {
const pluginManager = getPluginManager();
const plugins = pluginManager.getPluginList();
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ plugins }));
return true;
} catch (error) {
logger.error('[UI API] Failed to get plugins:', error);
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: {
message: 'Failed to get plugins list: ' + error.message
}
}));
return true;
}
}
/**
* 切换插件状态
*/
export async function handleTogglePlugin(req, res, pluginName) {
try {
const body = await getRequestBody(req);
const { enabled } = body;
if (typeof enabled !== 'boolean') {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: {
message: 'Enabled status must be a boolean'
}
}));
return true;
}
const pluginManager = getPluginManager();
await pluginManager.setPluginEnabled(pluginName, enabled);
// 广播更新事件
broadcastEvent('plugin_update', {
action: 'toggle',
pluginName,
enabled,
timestamp: new Date().toISOString()
});
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
success: true,
message: `Plugin ${pluginName} ${enabled ? 'enabled' : 'disabled'} successfully`,
plugin: {
name: pluginName,
enabled
}
}));
return true;
} catch (error) {
logger.error('[UI API] Failed to toggle plugin:', error);
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: {
message: 'Failed to toggle plugin: ' + error.message
}
}));
return true;
}
}