Skip to content

Commit

Permalink
feat: data migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiu8081 committed May 1, 2023
1 parent b66ef2c commit 210e9da
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/stores/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,37 @@ export const conversationMapSortList = computed(conversationMap, (map) => {
return Object.values(map).sort((a, b) => b.lastUseTime - a.lastUseTime)
})

const migrateConversationStoreIfNeeded = () => {
const rawData = conversationMap.get()
Object.values(rawData).forEach((conversation) => {
// @ts-expect-error migrate old data
if (conversation.providerId && conversation.conversationType) {
const typeDict = {
single: 'chat_single',
continuous: 'chat_continuous',
image: 'image_generation',
}
const newConversationData = {
id: conversation.id,
// @ts-expect-error migrate old data
bot: `${conversation.providerId}:${typeDict[conversation.conversationType] || 'chat_single'}`,
name: conversation.name,
icon: conversation.icon,
systemInfo: conversation.systemInfo,
mockMessages: conversation.mockMessages,
lastUseTime: conversation.lastUseTime,
}
conversationMap.setKey(conversation.id, newConversationData)
db.setItem(conversation.id, newConversationData)
}
})
}

export const rebuildConversationStore = async() => {
const data = await db.exportData() || {}
conversationMap.set(data)
// conversationMap.set(conversationMapData)
migrateConversationStoreIfNeeded()
}

export const addConversation = action(conversationMap, 'addConversation', (map, instance?: Partial<Conversation>) => {
Expand Down

0 comments on commit 210e9da

Please sign in to comment.