diff --git a/server.js b/server.js index 506d47d..6b126b1 100644 --- a/server.js +++ b/server.js @@ -88,15 +88,15 @@ const connectedClients = new Map(); // 视频映射配置 const videoMapping = { // 'say-6s-m-e': '1-m.mp4', - 'default': '0-2.mp4', + 'default': 'bd-1.mp4', // 'say-5s-amplitude': '2.mp4', // 'say-5s-m-e': '4.mp4', - 'say-5s-m-sw': '5.mp4', + 'say-5s-m-sw': 'd-0.mp4', // 'say-3s-m-sw': '6.mp4', }; // 默认视频流配置 -const DEFAULT_VIDEO = '0-2.mp4'; +const DEFAULT_VIDEO = 'bd-1.mp4'; const INTERACTION_TIMEOUT = 10000; // 10秒后回到默认视频 // 获取视频列表 diff --git a/src/chat_with_audio.js b/src/chat_with_audio.js index c4dfa70..990de50 100644 --- a/src/chat_with_audio.js +++ b/src/chat_with_audio.js @@ -69,22 +69,30 @@ function updateHistoryMessage(userInput, assistantResponse) { } } +// 保存消息到服务端 // 保存消息到服务端 async function saveMessage(userInput, assistantResponse) { try { + // 验证参数是否有效 + if (!userInput || !userInput.trim() || !assistantResponse || !assistantResponse.trim()) { + console.warn('跳过保存消息:用户输入或助手回复为空'); + return; + } + const response = await fetch('/api/messages/save', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - userInput, - assistantResponse + userInput: userInput.trim(), + assistantResponse: assistantResponse.trim() }) }); if (!response.ok) { - throw new Error('保存消息失败'); + const errorData = await response.json().catch(() => ({})); + throw new Error(`保存消息失败: ${response.status} ${errorData.error || response.statusText}`); } console.log('消息已保存到服务端'); diff --git a/src/index.html b/src/index.html index bc582a3..66d5b59 100644 --- a/src/index.html +++ b/src/index.html @@ -2,69 +2,260 @@
- +