[feat] multiple cards import
This commit is contained in:
@@ -54,7 +54,7 @@
|
||||
}
|
||||
async function createImport() {
|
||||
reseter();
|
||||
const cid = await importCharacter();
|
||||
await importCharacter();
|
||||
selectedCharID.set(-1);
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user