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{
|
else{
|
||||||
const keys = await forageStorage.keys()
|
const keys = await forageStorage.keys()
|
||||||
let backups:number[] = []
|
|
||||||
for(const key of keys){
|
const backups = keys
|
||||||
if(key.startsWith("database/dbbackup-")){
|
.filter(key => key.startsWith('database/dbbackup-'))
|
||||||
let da = key.substring(18)
|
.map(key => parseInt(key.slice(18, -4)))
|
||||||
da = da.substring(0,da.length-4)
|
.sort((a, b) => b - a);
|
||||||
backups.push(parseInt(da))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(backups.length > 20){
|
while(backups.length > 20){
|
||||||
const last = backups.pop()
|
const last = backups.pop()
|
||||||
await forageStorage.removeItem(`database/dbbackup-${last}.bin`)
|
await forageStorage.removeItem(`database/dbbackup-${last}.bin`)
|
||||||
@@ -524,6 +522,7 @@ export async function loadData() {
|
|||||||
const backups = await getDbBackups()
|
const backups = await getDbBackups()
|
||||||
let backupLoaded = false
|
let backupLoaded = false
|
||||||
for(const backup of backups){
|
for(const backup of backups){
|
||||||
|
if (!backupLoaded) {
|
||||||
try {
|
try {
|
||||||
LoadingStatusState.text = `Reading Backup File ${backup}...`
|
LoadingStatusState.text = `Reading Backup File ${backup}...`
|
||||||
const backupData = await readFile(`database/dbbackup-${backup}.bin`, {baseDir: BaseDirectory.AppData})
|
const backupData = await readFile(`database/dbbackup-${backup}.bin`, {baseDir: BaseDirectory.AppData})
|
||||||
@@ -535,6 +534,7 @@ export async function loadData() {
|
|||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(!backupLoaded){
|
if(!backupLoaded){
|
||||||
throw "Your save file is corrupted"
|
throw "Your save file is corrupted"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user