[feat] multiple cards import
This commit is contained in:
@@ -54,7 +54,7 @@
|
|||||||
}
|
}
|
||||||
async function createImport() {
|
async function createImport() {
|
||||||
reseter();
|
reseter();
|
||||||
const cid = await importCharacter();
|
await importCharacter();
|
||||||
selectedCharID.set(-1);
|
selectedCharID.set(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore } from "./alert"
|
import { alertConfirm, alertError, alertNormal, alertSelect, alertStore } from "./alert"
|
||||||
import { DataBase, defaultSdDataFunc, type character, setDatabase, type customscript, type loreSettings, type loreBook } from "./database"
|
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 { language } from "src/lang"
|
||||||
import { encode as encodeMsgpack, decode as decodeMsgpack } from "@msgpack/msgpack";
|
import { encode as encodeMsgpack, decode as decodeMsgpack } from "@msgpack/msgpack";
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
@@ -14,10 +14,24 @@ import { cloneDeep } from "lodash"
|
|||||||
|
|
||||||
export async function importCharacter() {
|
export async function importCharacter() {
|
||||||
try {
|
try {
|
||||||
const f = await selectSingleFile(['png', 'json'])
|
const files = await selectMultipleFile(['png', 'json'])
|
||||||
if(!f){
|
if(!files){
|
||||||
return
|
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')){
|
if(f.name.endsWith('json')){
|
||||||
const da = JSON.parse(Buffer.from(f.data).toString('utf-8'))
|
const da = JSON.parse(Buffer.from(f.data).toString('utf-8'))
|
||||||
if(await importSpecv2(da)){
|
if(await importSpecv2(da)){
|
||||||
@@ -105,10 +119,6 @@ export async function importCharacter() {
|
|||||||
alertError(language.errors.noData)
|
alertError(language.errors.noData)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
alertError(`${error}`)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function characterHubImport() {
|
export async function characterHubImport() {
|
||||||
|
|||||||
Reference in New Issue
Block a user