[feat] multiple cards import

This commit is contained in:
kwaroran
2023-05-21 02:38:44 +09:00
parent 7658090e4a
commit 40d8b17795
2 changed files with 99 additions and 89 deletions

View File

@@ -54,7 +54,7 @@
}
async function createImport() {
reseter();
const cid = await importCharacter();
await importCharacter();
selectedCharID.set(-1);
}

View File

@@ -1,7 +1,7 @@
import { get } from "svelte/store"
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore } from "./alert"
import { DataBase, defaultSdDataFunc, type character, setDatabase, type customscript, type loreSettings, type loreBook } from "./database"
import { checkNullish, selectSingleFile, sleep } from "./util"
import { checkNullish, selectMultipleFile, selectSingleFile, sleep } from "./util"
import { language } from "src/lang"
import { encode as encodeMsgpack, decode as decodeMsgpack } from "@msgpack/msgpack";
import { v4 as uuidv4 } from 'uuid';
@@ -14,10 +14,24 @@ import { cloneDeep } from "lodash"
export async function importCharacter() {
try {
const f = await selectSingleFile(['png', 'json'])
if(!f){
const files = await selectMultipleFile(['png', 'json'])
if(!files){
return
}
for(const f of files){
await importCharacterProcess(f)
}
} catch (error) {
alertError(`${error}`)
return null
}
}
async function importCharacterProcess(f:{
name: string;
data: Uint8Array;
}) {
if(f.name.endsWith('json')){
const da = JSON.parse(Buffer.from(f.data).toString('utf-8'))
if(await importSpecv2(da)){
@@ -105,10 +119,6 @@ export async function importCharacter() {
alertError(language.errors.noData)
return null
}
} catch (error) {
alertError(`${error}`)
return null
}
}
export async function characterHubImport() {