|
58 | 58 | <div class="section steps-section"> |
59 | 59 | <h2>聊天记录转移步骤</h2> |
60 | 60 | <ol> |
61 | | - <li>在ChatBox的<code>设置-其它-备份与恢复</code>中<strong>只勾选<code>聊天记录</code></strong>,然后导出</li> |
| 61 | + <li>在ChatBox的<code>设置</code> > <code>常规设置</code> > <code>数据备份</code>中,点击<code>导出勾选数据</code></li> |
62 | 62 | <li>点击本页面的<code>选择文件</code>按钮,选择刚刚从ChatBox导出的JSON文件 |
63 | 63 | <blockquote>本网页不会收集也无法收集您的个人数据,一切操作均在您的浏览器本地进行</blockquote> |
64 | 64 | </li> |
@@ -127,13 +127,28 @@ function handleFileUpload(event) { |
127 | 127 | reader.onload = (e) => { |
128 | 128 | try { |
129 | 129 | const data = JSON.parse(e.target.result); |
130 | | - const chatSessionList = data['chat-sessions-list'] |
131 | | - const chatSessions = chatSessionList.map((sessionMeta) => data[`session:${sessionMeta.id}`]) || data['chat-sessions'] || []; |
| 130 | + |
| 131 | + // 检查是否为新格式的ChatBox导出文件 |
| 132 | + if (!data.__exported_items || !data['chat-sessions-list']) { |
| 133 | + throw new Error('不是有效的ChatBox导出文件'); |
| 134 | + } |
| 135 | + |
| 136 | + // 只处理包含对话记录的导出 |
| 137 | + if (!data.__exported_items.includes('conversations')) { |
| 138 | + throw new Error('导出文件中不包含对话记录'); |
| 139 | + } |
| 140 | + |
| 141 | + const chatSessionList = data['chat-sessions-list']; |
| 142 | + const chatSessions = chatSessionList.map((sessionMeta) => data[`session:${sessionMeta.id}`]).filter(session => session); |
132 | 143 |
|
133 | 144 | chatSessions.forEach(conv => { |
134 | 145 | if (conv.messages && conv.messages.length > 0) { |
135 | 146 | const hasWarning = !isValidConversation(conv.messages); |
136 | | - const hasImages = conv.messages.some(msg => msg.pictures && msg.pictures.length > 0); |
| 147 | + // 检查是否包含图片(支持新格式的contentParts) |
| 148 | + const hasImages = conv.messages.some(msg => { |
| 149 | + if (msg.contentParts && msg.contentParts.some(part => part.type === 'image')) return true; |
| 150 | + return false; |
| 151 | + }); |
137 | 152 | conversations.value.push({ |
138 | 153 | id: uuidv4(), |
139 | 154 | title: conv.name || "未命名对话", |
@@ -182,11 +197,17 @@ function showWarningModal(errorConversations, imageConversations) { |
182 | 197 |
|
183 | 198 | if (errorConversations.length > 0) { |
184 | 199 | content += ` |
185 | | - <p><strong>以下对话包含不成对的消息(存在连续的User/Assistant消息),可能导致Open WebUI功能异常:</strong></p> |
| 200 | + <p><strong>以下对话存在问题,可能导致Open WebUI功能异常:</strong></p> |
186 | 201 | <ul> |
187 | 202 | ${errorConversations.map(title => `<li>${title}</li>`).join('')} |
188 | 203 | </ul> |
189 | | - <p>如果您确定要转换这些对话,建议先在ChatBox中手动删除不成对消息。</p> |
| 204 | + <p>问题可能包括:</p> |
| 205 | + <ul> |
| 206 | + <li>连续的相同角色消息(连续的User或Assistant消息)</li> |
| 207 | + <li>中间消息包含错误(Open WebUI只允许最后一条消息有错误)</li> |
| 208 | + <li>空内容消息</li> |
| 209 | + </ul> |
| 210 | + <p>建议在ChatBox中手动修复这些问题后再进行转换。</p> |
190 | 211 | <hr style="border-color: #ccc;"> <!-- 添加分割线 --> |
191 | 212 | `; |
192 | 213 | } |
|
0 commit comments