马一丁

Fix Forum Engine's Frontend Log Output

@@ -2594,21 +2594,29 @@ @@ -2594,21 +2594,29 @@
2594 fetch('/api/forum/log') 2594 fetch('/api/forum/log')
2595 .then(response => response.json()) 2595 .then(response => response.json())
2596 .then(data => { 2596 .then(data => {
2597 - if (data.success && data.log_lines.length > forumLogLineCount) {  
2598 - console.log(`Forum: 发现新消息,当前行数: ${data.log_lines.length}, 上次处理: ${forumLogLineCount}`);  
2599 -  
2600 - // 只处理新增的日志行  
2601 - const newLines = data.log_lines.slice(forumLogLineCount);  
2602 - newLines.forEach((line, index) => {  
2603 - console.log(`Forum: 处理新行 ${forumLogLineCount + index + 1}: ${line}`);  
2604 - const parsed = parseForumMessage(line);  
2605 - if (parsed) {  
2606 - console.log(`Forum: 解析成功,添加消息:`, parsed);  
2607 - addForumMessage(parsed); 2597 + if (!data.success) return;
  2598 +
  2599 + const logLines = data.log_lines || [];
  2600 + const parsedMessages = data.parsed_messages || [];
  2601 +
  2602 + if (logLines.length > forumLogLineCount) {
  2603 + const newLines = logLines.slice(forumLogLineCount);
  2604 + newLines.forEach(line => {
  2605 + appendConsoleTextLine('forum', line);
  2606 + });
2608 } 2607 }
  2608 +
  2609 + if (parsedMessages.length > 0) {
  2610 + const chatArea = document.getElementById('forumChatArea');
  2611 + if (chatArea) {
  2612 + chatArea.innerHTML = '';
  2613 + parsedMessages.forEach(message => {
  2614 + addForumMessage(message);
2609 }); 2615 });
2610 - forumLogLineCount = data.log_lines.length;  
2611 } 2616 }
  2617 + }
  2618 +
  2619 + forumLogLineCount = logLines.length;
2612 }) 2620 })
2613 .catch(error => { 2621 .catch(error => {
2614 console.error('刷新论坛消息失败:', error); 2622 console.error('刷新论坛消息失败:', error);
@@ -2626,51 +2634,28 @@ @@ -2626,51 +2634,28 @@
2626 fetch('/api/forum/log') 2634 fetch('/api/forum/log')
2627 .then(response => response.json()) 2635 .then(response => response.json())
2628 .then(data => { 2636 .then(data => {
2629 - if (data.success) {  
2630 - // 清空对话区  
2631 - const chatArea = document.getElementById('forumChatArea');  
2632 - chatArea.innerHTML += `  
2633 - <div class="forum-message system">  
2634 - <div class="forum-message-header">SYSTEM</div>  
2635 - <div class="forum-message-content">ForumEngine 论坛已启动,ID98fiaw4324dwadhsl21awhs908147</div>  
2636 - <div class="forum-timestamp">${new Date().toLocaleTimeString('zh-CN')}</div>  
2637 - </div>  
2638 - `; 2637 + if (!data.success) return;
2639 2638
2640 - // 加载控制台日志  
2641 - if (data.log_lines && data.log_lines.length > 0) {  
2642 - if (forumLogLineCount === 0) {  
2643 - clearConsoleLayer('forum', '[系统] Forum Engine 日志输出'); 2639 + const chatArea = document.getElementById('forumChatArea');
  2640 + if (chatArea) {
  2641 + chatArea.innerHTML = '';
2644 } 2642 }
2645 2643
2646 - const newLines = data.log_lines.slice(forumLogLineCount);  
2647 - const linesToProcess = forumLogLineCount === 0 ? data.log_lines : newLines;  
2648 -  
2649 - linesToProcess.forEach(line => {  
2650 - appendConsoleTextLine('forum', line); 2644 + const logLines = data.log_lines || [];
  2645 + const parsedMessages = data.parsed_messages || [];
2651 2646
2652 - // 解析并添加到对话区  
2653 - const parsed = parseForumMessage(line);  
2654 - //if (parsed) {  
2655 - //addForumMessage(parsed);  
2656 - //}  
2657 - });  
2658 -  
2659 - // 重置计数器以确保后续消息能正确显示  
2660 - forumLogLineCount = data.log_lines.length; 2647 + if (logLines.length > 0) {
  2648 + clearConsoleLayer('forum', '[系统] Forum Engine 日志输出');
  2649 + logLines.forEach(line => appendConsoleTextLine('forum', line));
2661 } else { 2650 } else {
2662 - // 如果没有日志,重置计数器  
2663 forumLogLineCount = 0; 2651 forumLogLineCount = 0;
2664 } 2652 }
2665 2653
2666 - // 如果有解析的消息,直接使用  
2667 - if (data.parsed_messages && data.parsed_messages.length > 0) {  
2668 - data.parsed_messages.forEach(message => {  
2669 - // addForumMessage(message);  
2670 - }); 2654 + if (parsedMessages.length > 0) {
  2655 + parsedMessages.forEach(message => addForumMessage(message));
2671 } 2656 }
2672 2657
2673 - } 2658 + forumLogLineCount = logLines.length;
2674 }) 2659 })
2675 .catch(error => { 2660 .catch(error => {
2676 console.error('加载论坛日志失败:', error); 2661 console.error('加载论坛日志失败:', error);
@@ -2682,27 +2667,37 @@ @@ -2682,27 +2667,37 @@
2682 fetch('/api/forum/log') 2667 fetch('/api/forum/log')
2683 .then(response => response.json()) 2668 .then(response => response.json())
2684 .then(data => { 2669 .then(data => {
2685 - if (data.success && data.log_lines.length > forumLogLineCount) {  
2686 - // 只添加新的行  
2687 - const newLines = data.log_lines.slice(forumLogLineCount);  
2688 - newLines.forEach(line => {  
2689 - appendConsoleTextLine('forum', line); 2670 + if (!data.success) return;
2690 2671
2691 - // 如果是论坛对话内容,也显示到左侧对话区  
2692 - const parsed = parseForumMessage(line);  
2693 - if (parsed) {  
2694 - addForumMessage(parsed); 2672 + const logLines = data.log_lines || [];
  2673 + const parsedMessages = data.parsed_messages || [];
  2674 +
  2675 + if (logLines.length > forumLogLineCount) {
  2676 + const newLines = logLines.slice(forumLogLineCount);
  2677 + newLines.forEach(line => appendConsoleTextLine('forum', line));
2695 } 2678 }
2696 - });  
2697 2679
2698 - forumLogLineCount = data.log_lines.length; 2680 + if (parsedMessages.length && parsedMessages.length !== getForumMessageCount()) {
  2681 + const chatArea = document.getElementById('forumChatArea');
  2682 + if (chatArea) {
  2683 + chatArea.innerHTML = '';
  2684 + parsedMessages.forEach(message => addForumMessage(message));
  2685 + }
2699 } 2686 }
  2687 +
  2688 + forumLogLineCount = logLines.length;
2700 }) 2689 })
2701 .catch(error => { 2690 .catch(error => {
2702 console.error('刷新论坛日志失败:', error); 2691 console.error('刷新论坛日志失败:', error);
2703 }); 2692 });
2704 } 2693 }
2705 2694
  2695 + function getForumMessageCount() {
  2696 + const chatArea = document.getElementById('forumChatArea');
  2697 + if (!chatArea) return 0;
  2698 + return chatArea.querySelectorAll('.forum-message').length;
  2699 + }
  2700 +
2706 // 刷新Report Engine日志 2701 // 刷新Report Engine日志
2707 // 检查Report Engine锁定状态并自动生成报告 2702 // 检查Report Engine锁定状态并自动生成报告
2708 let autoGenerateTriggered = false; // 防止重复触发 2703 let autoGenerateTriggered = false; // 防止重复触发