Add internal backup load

This commit is contained in:
kwaroran
2024-07-10 18:18:43 +09:00
parent 6309317945
commit f7f3591609
3 changed files with 50 additions and 6 deletions

View File

@@ -669,4 +669,5 @@ export const languageEnglish = {
blockMode: "Block",
helpBlock: "Help",
hideChatIcon: "Hide Icon UI",
loadInternalBackup: "Load Internal Backup",
}

View File

@@ -5,7 +5,7 @@
import { DataBase } from "src/ts/storage/database";
import Check from "src/lib/UI/GUI/CheckInput.svelte";
import { alertConfirm, alertError, alertNormal } from "src/ts/alert";
import { forageStorage, isNodeServer, isTauri } from "src/ts/storage/globalApi";
import { forageStorage, isNodeServer, isTauri, loadInternalBackup } from "src/ts/storage/globalApi";
import { unMigrationAccount } from "src/ts/storage/accountStorage";
import { checkDriver } from "src/ts/drive/drive";
import { LoadLocalBackup, SaveLocalBackup } from "src/ts/drive/backuplocal";
@@ -61,16 +61,16 @@
{language.loadBackupLocal}
</Button>
<!-- {#if $DataBase.account}
{#if !$DataBase.account}
<Button
on:click={async () => {
if((await alertConfirm(language.backupLoadConfirm)) && (await alertConfirm(language.backupLoadConfirm2))){
loadRisuAccountBackup()
loadInternalBackup()
}
}} className="mt-2">
{language.loadAutoServerBackup}
{language.loadInternalBackup}
</Button>
{/if} -->
{/if}
<Button
on:click={async () => {

View File

@@ -12,7 +12,7 @@ import { checkRisuUpdate } from "../update";
import { botMakerMode, selectedCharID } from "../stores";
import { Body, ResponseType, fetch as TauriFetch } from "@tauri-apps/api/http";
import { loadPlugins } from "../plugins/plugins";
import { alertConfirm, alertError, alertNormal, alertNormalWait } from "../alert";
import { alertConfirm, alertError, alertNormal, alertNormalWait, alertSelect } from "../alert";
import { checkDriverInit, syncDrive } from "../drive/drive";
import { hasher } from "../parser";
import { characterURLImport, hubURL } from "../characterCards";
@@ -1607,3 +1607,46 @@ export class BlankWriter{
//do nothing, just to make compatible with other writer
}
}
export async function loadInternalBackup(){
const keys = isTauri ? (await readDir('database', {dir: BaseDirectory.AppData})).map((v) => {
return v.name
}) : (await forageStorage.keys())
let internalBackups:string[] = []
for(const key of keys){
if(key.startsWith('dbbackup-')){
internalBackups.push(key)
}
}
const selectOptions = [
'Cancel',
...(internalBackups.map((a) => {
return (new Date(parseInt(a.replace('database/dbbackup-', '').replace('dbbackup-','')) * 100)).toLocaleString()
}))
]
const alertResult = parseInt(
await alertSelect(selectOptions)
) - 1
if(alertResult === -1){
return
}
const selectedBackup = internalBackups[alertResult]
const data = isTauri ? (
await readBinaryFile('database/' + selectedBackup, {dir: BaseDirectory.AppData})
) : (await forageStorage.getItem(selectedBackup))
setDatabase(
decodeRisuSave(data)
)
await alertNormal('Loaded backup')
}