fix: 兼容旧数据格式自动转换
- 检测旧 chat_history 数据 - 自动转换为新的 conversations 格式 - 清理旧数据避免重复
This commit is contained in:
@@ -29,6 +29,25 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
conversations = JSON.parse(saved);
|
||||
}
|
||||
|
||||
// 兼容旧数据格式(chat_history)
|
||||
const oldHistory = localStorage.getItem('chat_history');
|
||||
if (oldHistory && conversations.length === 0) {
|
||||
const oldMessages = JSON.parse(oldHistory);
|
||||
if (oldMessages.length > 0) {
|
||||
// 转换旧数据为新格式
|
||||
const convertedConv = {
|
||||
id: Date.now().toString(),
|
||||
title: oldMessages[0].content.slice(0, 30) + (oldMessages[0].content.length > 30 ? '...' : ''),
|
||||
messages: oldMessages,
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now()
|
||||
};
|
||||
conversations.push(convertedConv);
|
||||
saveConversations();
|
||||
localStorage.removeItem('chat_history'); // 清理旧数据
|
||||
}
|
||||
}
|
||||
|
||||
// 显示对话列表页面
|
||||
showConversationList();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user