From 60fa3558c4b4c12571c8340fdbd328ab9618e7f2 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Sun, 7 May 2023 22:32:06 +0900 Subject: [PATCH] [feat] backup selection --- src/lang/en.ts | 4 +++- src/lang/ko.ts | 4 +++- src/ts/drive/drive.ts | 32 +++++++++++++++++++++++--------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/lang/en.ts b/src/lang/en.ts index b9bcbc08..452e3258 100644 --- a/src/lang/en.ts +++ b/src/lang/en.ts @@ -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" } diff --git a/src/lang/ko.ts b/src/lang/ko.ts index d930b596..25e00f5c 100644 --- a/src/lang/ko.ts +++ b/src/lang/ko.ts @@ -199,5 +199,7 @@ export const languageKorean = { type: "타입", editInput: "입력문 수정", editOutput: "출력문 수정", - editProcess: "리퀘스트 데이터 수정" + editProcess: "리퀘스트 데이터 수정", + loadLatest: "가장 최근 백업 불러오기", + loadOthers: "다른 백업 불러오기" } \ No newline at end of file diff --git a/src/ts/drive/drive.ts b/src/ts/drive/drive.ts index b22645aa..8d1ebf99 100644 --- a/src/ts/drive/drive.ts +++ b/src/ts/drive/drive.ts @@ -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 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){