fix: clear database and restore specific data from backup
- Updated restore function now clears database and restores specific data from backup. - Removed unused imports and refactored logic for item transformation in the '24' migration step.
This commit is contained in:
parent
fdb610736d
commit
be4bf5b510
@ -32,7 +32,20 @@ export async function restore() {
|
||||
const data = JSON.parse(content)
|
||||
|
||||
if (data.version === 1) {
|
||||
window.modal.confirm({ content: 'Please use a version less than v0.7.0 for recovery.' })
|
||||
await clearDatabase()
|
||||
|
||||
for (const { key, value } of data.indexedDB) {
|
||||
if (key.startsWith('topic:')) {
|
||||
await db.table('topics').add({ id: value.id, messages: value.messages })
|
||||
}
|
||||
if (key === 'image://avatar') {
|
||||
await db.table('settings').add({ id: key, value })
|
||||
}
|
||||
}
|
||||
|
||||
await localStorage.setItem('persist:cherry-studio', data.localStorage['persist:cherry-studio'])
|
||||
window.message.success({ content: i18n.t('message.restore.success'), key: 'restore' })
|
||||
setTimeout(() => window.api.reload(), 1000)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { SYSTEM_MODELS } from '@renderer/config/models'
|
||||
import i18n from '@renderer/i18n'
|
||||
import { Assistant } from '@renderer/types'
|
||||
import localforage from 'localforage'
|
||||
import { isEmpty, pick } from 'lodash'
|
||||
import { isEmpty } from 'lodash'
|
||||
import { createMigrate } from 'redux-persist'
|
||||
|
||||
import { RootState } from '.'
|
||||
@ -375,12 +374,7 @@ const migrateConfig = {
|
||||
}
|
||||
}
|
||||
},
|
||||
'24': async (state: RootState) => {
|
||||
for (const key of await localforage.keys()) {
|
||||
if (key.startsWith('topic:')) {
|
||||
localforage.getItem(key).then((topic) => localforage.setItem(key, pick(topic, ['id', 'messages'])))
|
||||
}
|
||||
}
|
||||
'24': (state: RootState) => {
|
||||
return {
|
||||
...state,
|
||||
assistants: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user