mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-10 07:19:02 +08:00
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
3e8a00f3a5
commit
315b6d8c74
@ -32,7 +32,20 @@ export async function restore() {
|
|||||||
const data = JSON.parse(content)
|
const data = JSON.parse(content)
|
||||||
|
|
||||||
if (data.version === 1) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import { SYSTEM_MODELS } from '@renderer/config/models'
|
import { SYSTEM_MODELS } from '@renderer/config/models'
|
||||||
import i18n from '@renderer/i18n'
|
import i18n from '@renderer/i18n'
|
||||||
import { Assistant } from '@renderer/types'
|
import { Assistant } from '@renderer/types'
|
||||||
import localforage from 'localforage'
|
import { isEmpty } from 'lodash'
|
||||||
import { isEmpty, pick } from 'lodash'
|
|
||||||
import { createMigrate } from 'redux-persist'
|
import { createMigrate } from 'redux-persist'
|
||||||
|
|
||||||
import { RootState } from '.'
|
import { RootState } from '.'
|
||||||
@ -375,12 +374,7 @@ const migrateConfig = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'24': async (state: RootState) => {
|
'24': (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'])))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
assistants: {
|
assistants: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user