fix backup in non-tauri environment (#713)
# PR Checklist - [ ] Have you checked if it works normally in all models? *Ignore this if it doesn't use models.* - [ ] Have you checked if it works normally in all web, local, and node hosted versions? If it doesn't, have you blocked it in those versions? - [ ] Have you added type definitions? # Description EN fix non-tauri environment backup issue. (e.g. backwards reset issue) fix applying duplicate backup file. KR Tauri 환경(로컬리스)가 아닌 상황에서 과거 20개의 백업본 이외에 나머지 백업본을 저장하지 않던 문제를 수정합니다. (뒤로가기 이슈) 백업본 적용 시 모든 백업본을 적용해보던 로직을 개선합니다.
This commit is contained in:
@@ -471,14 +471,12 @@ async function getDbBackups() {
|
||||
}
|
||||
else{
|
||||
const keys = await forageStorage.keys()
|
||||
let backups:number[] = []
|
||||
for(const key of keys){
|
||||
if(key.startsWith("database/dbbackup-")){
|
||||
let da = key.substring(18)
|
||||
da = da.substring(0,da.length-4)
|
||||
backups.push(parseInt(da))
|
||||
}
|
||||
}
|
||||
|
||||
const backups = keys
|
||||
.filter(key => key.startsWith('database/dbbackup-'))
|
||||
.map(key => parseInt(key.slice(18, -4)))
|
||||
.sort((a, b) => b - a);
|
||||
|
||||
while(backups.length > 20){
|
||||
const last = backups.pop()
|
||||
await forageStorage.removeItem(`database/dbbackup-${last}.bin`)
|
||||
@@ -524,15 +522,17 @@ export async function loadData() {
|
||||
const backups = await getDbBackups()
|
||||
let backupLoaded = false
|
||||
for(const backup of backups){
|
||||
try {
|
||||
LoadingStatusState.text = `Reading Backup File ${backup}...`
|
||||
const backupData = await readFile(`database/dbbackup-${backup}.bin`,{baseDir: BaseDirectory.AppData})
|
||||
setDatabase(
|
||||
await decodeRisuSave(backupData)
|
||||
)
|
||||
backupLoaded = true
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
if (!backupLoaded) {
|
||||
try {
|
||||
LoadingStatusState.text = `Reading Backup File ${backup}...`
|
||||
const backupData = await readFile(`database/dbbackup-${backup}.bin`, {baseDir: BaseDirectory.AppData})
|
||||
setDatabase(
|
||||
await decodeRisuSave(backupData)
|
||||
)
|
||||
backupLoaded = true
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!backupLoaded){
|
||||
|
||||
Reference in New Issue
Block a user