Migrate all DataBase to DBState

This commit is contained in:
kwaroran
2024-10-24 01:59:57 +09:00
parent 4e9190f1b5
commit b3fddb814e
65 changed files with 331 additions and 434 deletions

View File

@@ -1,7 +1,7 @@
import { get } from "svelte/store";
import { exportCharacterCard } from "./characterCards";
import { VirtualWriter, isTauri, openURL } from "./storage/globalApi";
import { DataBase, getCurrentCharacter, type character } from "./storage/database.svelte";
import { getCurrentCharacter, getDatabase, type character } from "./storage/database.svelte";
import { alertStore } from "./alert";
let pong = false;
@@ -15,7 +15,7 @@ window.addEventListener("message", (event) => {
});
export async function shareRealmCardData():Promise<{ name: ArrayBuffer; data: ArrayBuffer; }> {
const char = structuredClone(getCurrentCharacter()) as character
const char = structuredClone(getCurrentCharacter({snapshot:true})) as character
const trimedName = char.name.replace(/[^a-zA-Z0-9]/g, '') || 'character';
const writer = new VirtualWriter()
const namebuf = new TextEncoder().encode(trimedName + '.png')
@@ -31,8 +31,8 @@ export async function shareRealmCardData():Promise<{ name: ArrayBuffer; data: Ar
}
export async function openRealm(name:string,data:ArrayBuffer) {
const tk = get(DataBase)?.account?.token;
const id = get(DataBase)?.account?.id
const tk = getDatabase()?.account?.token;
const id = getDatabase()?.account?.id
const trimedName = name.replace(/[^a-zA-Z0-9]/g, '') || 'character';
const filedata = encodeURIComponent(Buffer.from(data).toString('base64')) + `&${trimedName}.png`;
const url = `https://realm.risuai.net/upload?token=${tk}&token_id=${id}#filedata=${filedata}`