[feat] backup selection

This commit is contained in:
kwaroran
2023-05-07 22:32:06 +09:00
parent 2d1fb23fc8
commit 60fa3558c4
3 changed files with 29 additions and 11 deletions

View File

@@ -199,6 +199,8 @@ export const languageEnglish = {
type: "Type",
editInput: "Modfiy Input",
editOutput: "Modfiy Output",
editProcess: "Modfiy Request Data"
editProcess: "Modfiy Request Data",
loadLatest: "Load Latest Backup",
loadOthers: "Load Other Backups"
}

View File

@@ -199,5 +199,7 @@ export const languageKorean = {
type: "타입",
editInput: "입력문 수정",
editOutput: "출력문 수정",
editProcess: "리퀘스트 데이터 수정"
editProcess: "리퀘스트 데이터 수정",
loadLatest: "가장 최근 백업 불러오기",
loadOthers: "다른 백업 불러오기"
}

View File

@@ -1,5 +1,5 @@
import { get } from "svelte/store";
import { alertError, alertInput, alertNormal, alertStore } from "../alert";
import { alertError, alertInput, alertNormal, alertSelect, alertStore } from "../alert";
import { DataBase, setDatabase, type Database } from "../database";
import { forageStorage, getUnpargeables, isTauri } from "../globalApi";
import pako from "pako";
@@ -177,8 +177,8 @@ async function loadDrive(ACCESS_TOKEN:string) {
return d.name
})
let latestDb:DriveFile = null
let latestDbDate = 0
let dbs:[DriveFile,number][] = []
for(const f of files){
if(f.name.endsWith("-database.risudat")){
@@ -187,15 +187,26 @@ async function loadDrive(ACCESS_TOKEN:string) {
continue
}
else{
if(tm > latestDbDate){
latestDb = f
latestDbDate = tm
}
dbs.push([f,tm])
}
}
}
if(latestDbDate !== 0){
const db:Database = JSON.parse(Buffer.from(pako.inflate(await getFileData(ACCESS_TOKEN, latestDb.id))).toString('utf-8'))
dbs.sort((a,b) => {
return b[1] - a[1]
})
if(dbs.length !== 0){
let selectables:string[] = []
for(let i=0;i<dbs.length;i++){
selectables.push(`Backup saved in ${(new Date(dbs[i][1] * 1000)).toLocaleString()}`)
if(selectables.length > 7){
break
}
}
const selectedIndex = (await alertSelect([language.loadLatest, language.loadOthers]) === '0') ? 0 : parseInt(await alertSelect(selectables))
const selectedDb = dbs[selectedIndex][0]
const db:Database = JSON.parse(Buffer.from(pako.inflate(await getFileData(ACCESS_TOKEN, selectedDb.id))).toString('utf-8'))
const requiredImages = (getUnpargeables(db))
let ind = 0;
for(const images of requiredImages){
@@ -253,6 +264,9 @@ async function loadDrive(ACCESS_TOKEN:string) {
})
}
}
else{
location.search = ''
}
}
function checkImageExist(image:string){