mirror of
https://github.com/fish2018/pansou.git
synced 2025-11-25 03:14:59 +08:00
style: 移除输出中的emoji以保持简洁
This commit is contained in:
@@ -297,7 +297,7 @@ class PanSouMCPServer {
|
||||
private setupProcessHandlers(): void {
|
||||
// 处理优雅关闭
|
||||
const gracefulShutdown = async (signal: string) => {
|
||||
console.error(`\n📡 收到 ${signal} 信号,正在优雅关闭...`);
|
||||
console.error(`\n收到 ${signal} 信号,正在优雅关闭...`);
|
||||
|
||||
if (this.config.autoStartBackend) {
|
||||
// 延迟关闭后端服务
|
||||
@@ -325,20 +325,20 @@ class PanSouMCPServer {
|
||||
public async start(): Promise<void> {
|
||||
// 如果启用了自动启动后端服务
|
||||
if (this.config.autoStartBackend) {
|
||||
console.error('🔍 检查后端服务状态...');
|
||||
console.error('检查后端服务状态...');
|
||||
|
||||
// 在启动阶段启用静默模式,避免输出网络错误信息
|
||||
this.httpClient.setSilentMode(true);
|
||||
|
||||
const isRunning = await this.backendManager.isBackendRunning();
|
||||
if (!isRunning) {
|
||||
console.error('🚀 自动启动后端服务...');
|
||||
console.error('自动启动后端服务...');
|
||||
const started = await this.backendManager.startBackend();
|
||||
if (!started) {
|
||||
console.error('❌ 后端服务启动失败,MCP服务器将继续运行但功能可能受限');
|
||||
console.error('后端服务启动失败,MCP服务器将继续运行但功能可能受限');
|
||||
}
|
||||
} else {
|
||||
console.error('✅ 后端服务已在运行');
|
||||
console.error('后端服务已在运行');
|
||||
}
|
||||
|
||||
// 启动完成后关闭静默模式
|
||||
@@ -349,11 +349,11 @@ class PanSouMCPServer {
|
||||
await this.server.connect(transport);
|
||||
|
||||
// 输出启动信息到stderr,避免干扰MCP通信
|
||||
console.error('🚀 PanSou MCP服务器已启动');
|
||||
console.error(`📡 服务地址: ${this.config.serverUrl}`);
|
||||
console.error(`⏱️ 请求超时: ${this.config.requestTimeout}ms`);
|
||||
console.error(`📊 最大结果数: ${this.config.maxResults}`);
|
||||
console.error(`🔧 自动启动后端: ${this.config.autoStartBackend ? '启用' : '禁用'}`);
|
||||
console.error('PanSou MCP服务器已启动');
|
||||
console.error(`服务地址: ${this.config.serverUrl}`);
|
||||
console.error(`请求超时: ${this.config.requestTimeout}ms`);
|
||||
console.error(`最大结果数: ${this.config.maxResults}`);
|
||||
console.error(`自动启动后端: ${this.config.autoStartBackend ? '启用' : '禁用'}`);
|
||||
// 空闲监控信息已在BackendManager构造函数中显示
|
||||
}
|
||||
}
|
||||
@@ -366,19 +366,19 @@ async function main(): Promise<void> {
|
||||
const server = new PanSouMCPServer();
|
||||
await server.start();
|
||||
} catch (error) {
|
||||
console.error('❌ 服务器启动失败:', error);
|
||||
console.error('服务器启动失败:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理未捕获的异常
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('❌ 未捕获的异常:', error);
|
||||
console.error('未捕获的异常:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('❌ 未处理的Promise拒绝:', reason);
|
||||
console.error('未处理的Promise拒绝:', reason);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -38,33 +38,33 @@ export async function executeHealthTool(args: unknown, httpClient: HttpClient):
|
||||
* 格式化健康检查结果
|
||||
*/
|
||||
function formatHealthResult(healthData: any, serverUrl: string): string {
|
||||
let output = `🏥 **PanSou服务健康检查**\n\n`;
|
||||
let output = `**PanSou服务健康检查**\n\n`;
|
||||
|
||||
// 服务基本信息
|
||||
output += `🌐 **服务地址**: ${serverUrl}\n`;
|
||||
output += `✅ **服务状态**: ${healthData.status === 'ok' ? '正常' : '异常'}\n\n`;
|
||||
output += `**服务地址**: ${serverUrl}\n`;
|
||||
output += `**服务状态**: ${healthData.status === 'ok' ? '正常' : '异常'}\n\n`;
|
||||
|
||||
// 频道信息
|
||||
output += `📺 **TG频道信息**\n`;
|
||||
output += ` 📊 频道数量: ${healthData.channels_count || 0}\n`;
|
||||
output += `**TG频道信息**\n`;
|
||||
output += ` 频道数量: ${healthData.channels_count || 0}\n`;
|
||||
if (healthData.channels && healthData.channels.length > 0) {
|
||||
output += ` 📋 可用频道:\n`;
|
||||
output += ` 可用频道:\n`;
|
||||
healthData.channels.forEach((channel: string, index: number) => {
|
||||
output += ` ${index + 1}. ${channel}\n`;
|
||||
});
|
||||
} else {
|
||||
output += ` ⚠️ 未配置频道\n`;
|
||||
output += ` 未配置频道\n`;
|
||||
}
|
||||
output += '\n';
|
||||
|
||||
// 插件信息
|
||||
output += `🔌 **插件信息**\n`;
|
||||
output += ` 🔧 插件功能: ${healthData.plugins_enabled ? '已启用' : '已禁用'}\n`;
|
||||
output += `**插件信息**\n`;
|
||||
output += ` 插件功能: ${healthData.plugins_enabled ? '已启用' : '已禁用'}\n`;
|
||||
|
||||
if (healthData.plugins_enabled) {
|
||||
output += ` 📊 插件数量: ${healthData.plugin_count || 0}\n`;
|
||||
output += ` 插件数量: ${healthData.plugin_count || 0}\n`;
|
||||
if (healthData.plugins && healthData.plugins.length > 0) {
|
||||
output += ` 📋 可用插件:\n`;
|
||||
output += ` 可用插件:\n`;
|
||||
|
||||
// 将插件按行显示,每行最多4个
|
||||
const plugins = healthData.plugins;
|
||||
@@ -73,21 +73,21 @@ function formatHealthResult(healthData: any, serverUrl: string): string {
|
||||
output += ` ${row.map((plugin: string, idx: number) => `${i + idx + 1}. ${plugin}`).join(' ')}\n`;
|
||||
}
|
||||
} else {
|
||||
output += ` ⚠️ 未发现可用插件\n`;
|
||||
output += ` 未发现可用插件\n`;
|
||||
}
|
||||
} else {
|
||||
output += ` ℹ️ 插件功能已禁用\n`;
|
||||
output += ` 插件功能已禁用\n`;
|
||||
}
|
||||
|
||||
output += '\n';
|
||||
|
||||
// 功能说明
|
||||
output += `💡 **功能说明**\n`;
|
||||
output += ` 🔍 支持搜索多种网盘资源\n`;
|
||||
output += ` 📱 支持TG频道和插件双重搜索\n`;
|
||||
output += ` 🚀 支持并发搜索,提升搜索速度\n`;
|
||||
output += ` 💾 支持缓存机制,避免重复请求\n`;
|
||||
output += ` 🎯 支持按网盘类型过滤结果\n`;
|
||||
output += `**功能说明**\n`;
|
||||
output += ` 支持搜索多种网盘资源\n`;
|
||||
output += ` 支持TG频道和插件双重搜索\n`;
|
||||
output += ` 支持并发搜索,提升搜索速度\n`;
|
||||
output += ` 支持缓存机制,避免重复请求\n`;
|
||||
output += ` 支持按网盘类型过滤结果\n`;
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -96,18 +96,18 @@ function formatHealthResult(healthData: any, serverUrl: string): string {
|
||||
* 格式化错误结果
|
||||
*/
|
||||
function formatErrorResult(errorMessage: string, serverUrl: string): string {
|
||||
let output = `❌ **PanSou服务健康检查失败**\n\n`;
|
||||
let output = `**PanSou服务健康检查失败**\n\n`;
|
||||
|
||||
output += `🌐 **服务地址**: ${serverUrl}\n`;
|
||||
output += `💥 **错误信息**: ${errorMessage}\n\n`;
|
||||
output += `**服务地址**: ${serverUrl}\n`;
|
||||
output += `**错误信息**: ${errorMessage}\n\n`;
|
||||
|
||||
output += `🔧 **可能的解决方案**:\n`;
|
||||
output += `**可能的解决方案**:\n`;
|
||||
output += ` 1. 检查PanSou服务是否正在运行\n`;
|
||||
output += ` 2. 确认服务地址配置是否正确\n`;
|
||||
output += ` 3. 检查网络连接是否正常\n`;
|
||||
output += ` 4. 查看服务日志获取更多信息\n\n`;
|
||||
|
||||
output += `📖 **配置说明**:\n`;
|
||||
output += `**配置说明**:\n`;
|
||||
output += ` 可通过环境变量 PANSOU_SERVER_URL 配置服务地址\n`;
|
||||
output += ` 默认地址: http://localhost:8888\n`;
|
||||
|
||||
|
||||
@@ -153,8 +153,8 @@ export async function executeSearchTool(args: unknown, httpClient: HttpClient):
|
||||
function formatSearchResult(result: any, keyword: string, resultType: string): string {
|
||||
const { total, results, merged_by_type } = result;
|
||||
|
||||
let output = `🔍 搜索关键词: "${keyword}"\n`;
|
||||
output += `📊 找到 ${total} 个结果\n\n`;
|
||||
let output = `搜索关键词: "${keyword}"\n`;
|
||||
output += `找到 ${total} 个结果\n\n`;
|
||||
|
||||
if (resultType === 'merge' && merged_by_type) {
|
||||
// 按网盘类型分组显示
|
||||
@@ -165,11 +165,11 @@ function formatSearchResult(result: any, keyword: string, resultType: string): s
|
||||
} else if (resultType === 'all') {
|
||||
// 显示所有信息
|
||||
if (merged_by_type) {
|
||||
output += "## 📁 按网盘类型分组\n";
|
||||
output += "## 按网盘类型分组\n";
|
||||
output += formatMergedResults(merged_by_type);
|
||||
}
|
||||
if (results && results.length > 0) {
|
||||
output += "\n## 📋 详细结果\n";
|
||||
output += "\n## 详细结果\n";
|
||||
output += formatDetailedResults(results.slice(0, 10)); // 限制显示前10个详细结果
|
||||
}
|
||||
}
|
||||
@@ -184,36 +184,36 @@ function formatMergedResults(mergedByType: Record<string, any[]>): string {
|
||||
let output = '';
|
||||
|
||||
const typeNames: Record<string, string> = {
|
||||
'baidu': '🔵 百度网盘',
|
||||
'aliyun': '🟠 阿里云盘',
|
||||
'quark': '🟣 夸克网盘',
|
||||
'tianyi': '🔴 天翼云盘',
|
||||
'uc': '🟡 UC网盘',
|
||||
'mobile': '🟢 移动云盘',
|
||||
'115': '⚫ 115网盘',
|
||||
'pikpak': '🟤 PikPak',
|
||||
'xunlei': '🔶 迅雷网盘',
|
||||
'123': '🟦 123网盘',
|
||||
'magnet': '🧲 磁力链接',
|
||||
'ed2k': '🔗 电驴链接',
|
||||
'others': '📦 其他'
|
||||
'baidu': '百度网盘',
|
||||
'aliyun': '阿里云盘',
|
||||
'quark': '夸克网盘',
|
||||
'tianyi': '天翼云盘',
|
||||
'uc': 'UC网盘',
|
||||
'mobile': '移动云盘',
|
||||
'115': '115网盘',
|
||||
'pikpak': 'PikPak',
|
||||
'xunlei': '迅雷网盘',
|
||||
'123': '123网盘',
|
||||
'magnet': '磁力链接',
|
||||
'ed2k': '电驴链接',
|
||||
'others': '其他'
|
||||
};
|
||||
|
||||
for (const [type, links] of Object.entries(mergedByType)) {
|
||||
if (links && links.length > 0) {
|
||||
const typeName = typeNames[type] || `📁 ${type}`;
|
||||
const typeName = typeNames[type] || `${type}`;
|
||||
output += `### ${typeName} (${links.length}个)\n`;
|
||||
|
||||
links.slice(0, 5).forEach((link: any, index: number) => {
|
||||
output += `${index + 1}. **${link.note || '未知标题'}**\n`;
|
||||
output += ` 🔗 链接: ${link.url}\n`;
|
||||
output += ` 链接: ${link.url}\n`;
|
||||
if (link.password) {
|
||||
output += ` 🔑 密码: ${link.password}\n`;
|
||||
output += ` 密码: ${link.password}\n`;
|
||||
}
|
||||
if (link.source) {
|
||||
output += ` 📍 来源: ${link.source}\n`;
|
||||
output += ` 来源: ${link.source}\n`;
|
||||
}
|
||||
output += ` 📅 时间: ${new Date(link.datetime).toLocaleString('zh-CN')}\n\n`;
|
||||
output += ` 时间: ${new Date(link.datetime).toLocaleString('zh-CN')}\n\n`;
|
||||
});
|
||||
|
||||
if (links.length > 5) {
|
||||
@@ -233,20 +233,20 @@ function formatDetailedResults(results: any[]): string {
|
||||
|
||||
results.forEach((result: any, index: number) => {
|
||||
output += `### ${index + 1}. ${result.title || '未知标题'}\n`;
|
||||
output += `📺 频道: ${result.channel}\n`;
|
||||
output += `📅 时间: ${new Date(result.datetime).toLocaleString('zh-CN')}\n`;
|
||||
output += `频道: ${result.channel}\n`;
|
||||
output += `时间: ${new Date(result.datetime).toLocaleString('zh-CN')}\n`;
|
||||
|
||||
if (result.content && result.content !== result.title) {
|
||||
const content = result.content.length > 200 ? result.content.substring(0, 200) + '...' : result.content;
|
||||
output += `📝 内容: ${content}\n`;
|
||||
output += `内容: ${content}\n`;
|
||||
}
|
||||
|
||||
if (result.tags && result.tags.length > 0) {
|
||||
output += `🏷️ 标签: ${result.tags.join(', ')}\n`;
|
||||
output += `标签: ${result.tags.join(', ')}\n`;
|
||||
}
|
||||
|
||||
if (result.links && result.links.length > 0) {
|
||||
output += `🔗 网盘链接:\n`;
|
||||
output += `网盘链接:\n`;
|
||||
result.links.forEach((link: any, linkIndex: number) => {
|
||||
output += ` ${linkIndex + 1}. [${link.type.toUpperCase()}] ${link.url}`;
|
||||
if (link.password) {
|
||||
@@ -257,7 +257,7 @@ function formatDetailedResults(results: any[]): string {
|
||||
}
|
||||
|
||||
if (result.images && result.images.length > 0) {
|
||||
output += `🖼️ 图片: ${result.images.length}张\n`;
|
||||
output += `图片: ${result.images.length}张\n`;
|
||||
}
|
||||
|
||||
output += '\n';
|
||||
|
||||
@@ -42,7 +42,7 @@ export async function executeStartBackendTool(
|
||||
const params = args as StartBackendArgs;
|
||||
const forceRestart = params?.force_restart || false;
|
||||
|
||||
console.log('🚀 启动后端服务工具被调用');
|
||||
console.log('启动后端服务工具被调用');
|
||||
|
||||
// 如果没有提供依赖项,则创建默认实例
|
||||
if (!config) {
|
||||
@@ -73,10 +73,10 @@ export async function executeStartBackendTool(
|
||||
}
|
||||
|
||||
if (isHealthy && forceRestart) {
|
||||
console.log('🔄 强制重启后端服务...');
|
||||
console.log('强制重启后端服务...');
|
||||
}
|
||||
|
||||
console.log('🚀 正在启动后端服务...');
|
||||
console.log('正在启动后端服务...');
|
||||
const started = await backendManager.startBackend();
|
||||
|
||||
if (!started) {
|
||||
@@ -89,7 +89,7 @@ export async function executeStartBackendTool(
|
||||
}
|
||||
|
||||
// 等待服务完全启动并进行健康检查
|
||||
console.log('⏳ 等待服务完全启动...');
|
||||
console.log('等待服务完全启动...');
|
||||
const maxRetries = 10;
|
||||
let retries = 0;
|
||||
|
||||
@@ -98,7 +98,7 @@ export async function executeStartBackendTool(
|
||||
const healthy = await httpClient.testConnection();
|
||||
|
||||
if (healthy) {
|
||||
console.log('✅ 后端服务启动成功并通过健康检查');
|
||||
console.log('后端服务启动成功并通过健康检查');
|
||||
return JSON.stringify({
|
||||
success: true,
|
||||
message: '后端服务启动成功',
|
||||
@@ -109,7 +109,7 @@ export async function executeStartBackendTool(
|
||||
}
|
||||
|
||||
retries++;
|
||||
console.log(`🔍 健康检查重试 ${retries}/${maxRetries}...`);
|
||||
console.log(`健康检查重试 ${retries}/${maxRetries}...`);
|
||||
}
|
||||
|
||||
return JSON.stringify({
|
||||
|
||||
@@ -37,12 +37,12 @@ export class BackendManager {
|
||||
|
||||
// 设置空闲监控回调
|
||||
this.activityMonitor.setOnIdleCallback(async () => {
|
||||
console.error('⏰ 检测到空闲超时,自动关闭后端服务');
|
||||
console.error('检测到空闲超时,自动关闭后端服务');
|
||||
await this.stopBackend();
|
||||
// 退出整个进程
|
||||
process.exit(0);
|
||||
});
|
||||
console.error(`⏱️ 空闲监控已启用,超时时间: ${this.config.idleTimeout / 1000} 秒`);
|
||||
console.error(`空闲监控已启用,超时时间: ${this.config.idleTimeout / 1000} 秒`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export class BackendManager {
|
||||
const runningContainers = stdout.trim().split('\n').filter(name => name.includes('pansou'));
|
||||
|
||||
if (runningContainers.length > 0) {
|
||||
console.error(`🐳 检测到运行中的Docker容器: ${runningContainers.join(', ')}`);
|
||||
console.error(`检测到运行中的Docker容器: ${runningContainers.join(', ')}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ export class BackendManager {
|
||||
this.httpClient.setSilentMode(false);
|
||||
|
||||
if (isRunning) {
|
||||
console.error('✅ 检测到后端服务已在运行(可能是手动启动)');
|
||||
console.error('检测到后端服务已在运行(可能是手动启动)');
|
||||
return 'source'; // 假设是源码模式
|
||||
}
|
||||
|
||||
@@ -138,24 +138,24 @@ export class BackendManager {
|
||||
);
|
||||
}
|
||||
|
||||
console.error('🔍 查找后端可执行文件...');
|
||||
console.error('查找后端可执行文件...');
|
||||
if (configProjectRoot) {
|
||||
console.error(`📂 使用配置的项目根目录: ${configProjectRoot}`);
|
||||
console.error(`使用配置的项目根目录: ${configProjectRoot}`);
|
||||
} else {
|
||||
console.error(`📂 当前工作目录: ${process.cwd()}`);
|
||||
console.error(`当前工作目录: ${process.cwd()}`);
|
||||
}
|
||||
|
||||
for (const execPath of possiblePaths) {
|
||||
try {
|
||||
await fs.access(execPath);
|
||||
console.error(`✅ 找到可执行文件: ${execPath}`);
|
||||
console.error(`找到可执行文件: ${execPath}`);
|
||||
return execPath;
|
||||
} catch {
|
||||
// 静默跳过未找到的路径
|
||||
}
|
||||
}
|
||||
|
||||
console.error('❌ 未找到可执行文件');
|
||||
console.error('未找到可执行文件');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ export class BackendManager {
|
||||
*/
|
||||
async startBackend(): Promise<boolean> {
|
||||
if (this.process) {
|
||||
console.error('⚠️ 后端服务已在运行中');
|
||||
console.error('后端服务已在运行中');
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -172,30 +172,30 @@ export class BackendManager {
|
||||
let effectiveDockerMode = this.config.dockerMode;
|
||||
|
||||
if (!effectiveDockerMode) {
|
||||
console.error('🔍 正在智能检测部署模式...');
|
||||
console.error('正在智能检测部署模式...');
|
||||
const detectedMode = await this.detectDeploymentMode();
|
||||
|
||||
switch (detectedMode) {
|
||||
case 'docker':
|
||||
console.error('🐳 智能检测:使用Docker部署模式');
|
||||
console.error('智能检测:使用Docker部署模式');
|
||||
effectiveDockerMode = true;
|
||||
break;
|
||||
case 'source':
|
||||
console.error('📦 智能检测:使用源码部署模式');
|
||||
console.error('智能检测:使用源码部署模式');
|
||||
effectiveDockerMode = false;
|
||||
break;
|
||||
case 'unknown':
|
||||
console.error('❓ 无法检测部署模式,使用默认源码模式');
|
||||
console.error('无法检测部署模式,使用默认源码模式');
|
||||
effectiveDockerMode = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
console.error(`⚙️ 使用配置指定的模式: ${effectiveDockerMode ? 'Docker' : '源码'}`);
|
||||
console.error(`使用配置指定的模式: ${effectiveDockerMode ? 'Docker' : '源码'}`);
|
||||
}
|
||||
|
||||
// Docker模式处理
|
||||
if (effectiveDockerMode) {
|
||||
console.error('🐳 Docker模式已启用,正在检查后端服务连接...');
|
||||
console.error('Docker模式已启用,正在检查后端服务连接...');
|
||||
|
||||
// Docker模式下进行重试检查,因为容器可能需要时间启动
|
||||
const maxRetries = 3;
|
||||
@@ -207,18 +207,18 @@ export class BackendManager {
|
||||
const isRunning = await this.isBackendRunning();
|
||||
if (isRunning) {
|
||||
this.httpClient.setSilentMode(false);
|
||||
console.error('✅ Docker模式下后端服务连接成功');
|
||||
console.error('Docker模式下后端服务连接成功');
|
||||
return true;
|
||||
}
|
||||
|
||||
if (i < maxRetries - 1) {
|
||||
console.error(`🔄 连接尝试 ${i + 1}/${maxRetries} 失败,${retryDelay/1000}秒后重试...`);
|
||||
console.error(`连接尝试 ${i + 1}/${maxRetries} 失败,${retryDelay/1000}秒后重试...`);
|
||||
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
||||
}
|
||||
}
|
||||
|
||||
this.httpClient.setSilentMode(false);
|
||||
console.error('❌ Docker模式下后端服务连接失败');
|
||||
console.error('Docker模式下后端服务连接失败');
|
||||
console.error('请确保Docker容器正在运行:');
|
||||
console.error(' docker-compose up -d');
|
||||
console.error('或检查Docker容器状态:');
|
||||
@@ -232,14 +232,14 @@ export class BackendManager {
|
||||
this.httpClient.setSilentMode(false);
|
||||
|
||||
if (isRunning) {
|
||||
console.error('✅ 检测到后端服务已在运行');
|
||||
console.error('检测到后端服务已在运行');
|
||||
return true;
|
||||
}
|
||||
|
||||
// 查找Go可执行文件
|
||||
const execPath = await this.findGoExecutable();
|
||||
if (!execPath) {
|
||||
console.error('❌ 未找到PanSou后端可执行文件');
|
||||
console.error('未找到PanSou后端可执行文件');
|
||||
console.error('如果您使用Docker部署,请在MCP配置中设置 DOCKER_MODE=true');
|
||||
console.error('如果您使用源码部署,请确保在项目根目录下存在以下文件之一:');
|
||||
console.error(' - pansou.exe / pansou');
|
||||
@@ -247,7 +247,7 @@ export class BackendManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
console.error(`🚀 启动后端服务: ${execPath}`);
|
||||
console.error(`启动后端服务: ${execPath}`);
|
||||
|
||||
try {
|
||||
// 启动Go服务
|
||||
@@ -260,22 +260,22 @@ export class BackendManager {
|
||||
|
||||
// 监听进程事件
|
||||
this.process.on('error', (error) => {
|
||||
console.error('❌ 后端服务启动失败:', error.message);
|
||||
console.error('后端服务启动失败:', error.message);
|
||||
console.error('错误详情:', error);
|
||||
this.process = null;
|
||||
});
|
||||
|
||||
this.process.on('exit', (code, signal) => {
|
||||
if (!this.isShuttingDown) {
|
||||
console.error(`⚠️ 后端服务意外退出 (code: ${code}, signal: ${signal})`);
|
||||
console.error(`后端服务意外退出 (code: ${code}, signal: ${signal})`);
|
||||
}
|
||||
this.process = null;
|
||||
});
|
||||
|
||||
// 添加进程启动确认
|
||||
console.error(`📋 进程PID: ${this.process.pid}`);
|
||||
console.error(`📂 工作目录: ${path.dirname(execPath)}`);
|
||||
console.error(`⚙️ 启动参数: ${execPath}`);
|
||||
console.error(`进程PID: ${this.process.pid}`);
|
||||
console.error(`工作目录: ${path.dirname(execPath)}`);
|
||||
console.error(`启动参数: ${execPath}`);
|
||||
|
||||
// 给进程一点时间启动
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
@@ -297,7 +297,7 @@ export class BackendManager {
|
||||
// 区分错误和正常日志
|
||||
if (output.includes('error') || output.includes('Error') || output.includes('ERROR') ||
|
||||
output.includes('panic') || output.includes('fatal') || output.includes('failed')) {
|
||||
console.error('❌ Backend错误:', output);
|
||||
console.error('Backend错误:', output);
|
||||
} else {
|
||||
console.error('Backend stderr:', output);
|
||||
}
|
||||
@@ -308,18 +308,18 @@ export class BackendManager {
|
||||
// 等待服务启动
|
||||
const started = await this.waitForBackendReady();
|
||||
if (started) {
|
||||
console.error('✅ 后端服务启动成功');
|
||||
console.error('后端服务启动成功');
|
||||
|
||||
// 空闲监控已在构造函数中设置
|
||||
|
||||
return true;
|
||||
} else {
|
||||
console.error('❌ 后端服务启动超时');
|
||||
console.error('后端服务启动超时');
|
||||
await this.stopBackend();
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ 启动后端服务时发生错误:', error);
|
||||
console.error('启动后端服务时发生错误:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -364,7 +364,7 @@ export class BackendManager {
|
||||
return;
|
||||
}
|
||||
|
||||
console.error('🛑 正在停止后端服务...');
|
||||
console.error('正在停止后端服务...');
|
||||
this.isShuttingDown = true;
|
||||
|
||||
try {
|
||||
@@ -381,7 +381,7 @@ export class BackendManager {
|
||||
const timeout = setTimeout(() => {
|
||||
// 强制杀死进程
|
||||
if (this.process && !this.process.killed) {
|
||||
console.error('⚠️ 强制终止后端服务');
|
||||
console.error('强制终止后端服务');
|
||||
this.process.kill('SIGKILL');
|
||||
}
|
||||
resolve();
|
||||
@@ -393,9 +393,9 @@ export class BackendManager {
|
||||
});
|
||||
});
|
||||
|
||||
console.error('✅ 后端服务已停止');
|
||||
console.error('后端服务已停止');
|
||||
} catch (error) {
|
||||
console.error('❌ 停止后端服务时发生错误:', error);
|
||||
console.error('停止后端服务时发生错误:', error);
|
||||
} finally {
|
||||
this.process = null;
|
||||
this.isShuttingDown = false;
|
||||
@@ -410,7 +410,7 @@ export class BackendManager {
|
||||
clearTimeout(this.shutdownTimeout);
|
||||
}
|
||||
|
||||
console.error(`⏰ 将在 ${this.SHUTDOWN_DELAY / 1000} 秒后关闭后端服务`);
|
||||
console.error(`将在 ${this.SHUTDOWN_DELAY / 1000} 秒后关闭后端服务`);
|
||||
|
||||
this.shutdownTimeout = setTimeout(async () => {
|
||||
await this.stopBackend();
|
||||
|
||||
Reference in New Issue
Block a user