Migrate all DataBase to DBState
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { get } from "svelte/store"
|
||||
import { hubURL } from "../characterCards"
|
||||
import { DataBase } from "../storage/database.svelte"
|
||||
import { getDatabase } from "../storage/database.svelte"
|
||||
import { alertError, alertSelect } from "../alert"
|
||||
|
||||
export async function risuLogin() {
|
||||
@@ -14,7 +13,7 @@ export async function risuLogin() {
|
||||
}
|
||||
|
||||
export async function saveRisuAccountData() {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(!db.account){
|
||||
alertError("Not logged in error")
|
||||
return
|
||||
@@ -33,7 +32,7 @@ export async function saveRisuAccountData() {
|
||||
}
|
||||
|
||||
export async function loadRisuAccountData() {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(!db.account){
|
||||
alertError("Not logged in error")
|
||||
return
|
||||
@@ -52,7 +51,7 @@ export async function loadRisuAccountData() {
|
||||
}
|
||||
|
||||
export async function loadRisuAccountBackup() {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(!db.account){
|
||||
alertError("Not logged in error")
|
||||
return
|
||||
|
||||
@@ -2,9 +2,7 @@ import { BaseDirectory, readFile, readDir, writeFile } from "@tauri-apps/plugin-
|
||||
import { alertError, alertNormal, alertStore, alertWait } from "../alert";
|
||||
import { LocalWriter, forageStorage, isTauri } from "../storage/globalApi";
|
||||
import { decodeRisuSave, encodeRisuSave } from "../storage/risuSave";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "../storage/database.svelte";
|
||||
import { save } from "@tauri-apps/plugin-dialog";
|
||||
import { getDatabase, setDatabaseLite } from "../storage/database.svelte";
|
||||
import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { sleep } from "../util";
|
||||
import { hubURL } from "../characterCards";
|
||||
@@ -32,7 +30,7 @@ export async function SaveLocalBackup(){
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(get(DataBase)),
|
||||
body: JSON.stringify(getDatabase()),
|
||||
})
|
||||
if(corrupted.status === 400){
|
||||
alertError('Failed, Backup data is corrupted')
|
||||
@@ -70,7 +68,7 @@ export async function SaveLocalBackup(){
|
||||
}
|
||||
}
|
||||
|
||||
const dbData = encodeRisuSave(get(DataBase), 'compression')
|
||||
const dbData = encodeRisuSave(getDatabase(), 'compression')
|
||||
|
||||
alertWait(`Saving local Backup... (Saving database)`)
|
||||
|
||||
@@ -113,7 +111,7 @@ export async function LoadLocalBackup(){
|
||||
if(name === 'database.risudat'){
|
||||
const db = new Uint8Array(data)
|
||||
const dbData = await decodeRisuSave(db)
|
||||
DataBase.set(dbData)
|
||||
setDatabaseLite(dbData)
|
||||
if(isTauri){
|
||||
await writeFile('database/database.bin', db, {baseDir: BaseDirectory.AppData})
|
||||
relaunch()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { get } from "svelte/store";
|
||||
import { alertError, alertInput, alertNormal, alertSelect, alertStore } from "../alert";
|
||||
import { DataBase, type Database } from "../storage/database.svelte";
|
||||
import { getDatabase, type Database } from "../storage/database.svelte";
|
||||
import { forageStorage, getUnpargeables, isTauri, openURL } from "../storage/globalApi";
|
||||
import { BaseDirectory, exists, readFile, readDir, writeFile } from "@tauri-apps/plugin-fs";
|
||||
import { language } from "../../lang";
|
||||
@@ -109,7 +108,7 @@ let BackupDb:Database = null
|
||||
|
||||
|
||||
export async function syncDrive() {
|
||||
BackupDb = structuredClone(get(DataBase))
|
||||
BackupDb = structuredClone(getDatabase())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(get(DataBase)),
|
||||
body: JSON.stringify(getDatabase()),
|
||||
})
|
||||
if(corrupted.status === 400){
|
||||
alertError('Failed, Backup data is corrupted')
|
||||
@@ -177,7 +176,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
|
||||
}
|
||||
}
|
||||
|
||||
const dbData = encodeRisuSave(get(DataBase), 'compression')
|
||||
const dbData = encodeRisuSave(getDatabase(), 'compression')
|
||||
|
||||
alertStore.set({
|
||||
type: "wait",
|
||||
@@ -206,7 +205,7 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<voi
|
||||
const files:DriveFile[] = await getFilesInFolder(ACCESS_TOKEN)
|
||||
let foragekeys:string[] = []
|
||||
let loadedForageKeys = false
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
|
||||
async function checkImageExists(images:string) {
|
||||
if(db?.account?.useSync){
|
||||
|
||||
Reference in New Issue
Block a user