From e0edf74b465a080c4723bfc949bb125e89e10d74 Mon Sep 17 00:00:00 2001 From: ModMapper Date: Tue, 22 Oct 2024 20:46:00 +0900 Subject: [PATCH] Fixed the bug where the character list was not updating in certain situations after importing a URL. --- src/ts/characterCards.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ts/characterCards.ts b/src/ts/characterCards.ts index 80d64e0c..fb2672af 100644 --- a/src/ts/characterCards.ts +++ b/src/ts/characterCards.ts @@ -301,11 +301,17 @@ export async function characterURLImport() { const hash = location.hash if(hash.startsWith('#import=')){ const url = hash.replace('#import=', '') - const res = await fetch(url, { - method: 'GET', - }) - const data = new Uint8Array(await res.arrayBuffer()) - importFile(getFileName(res), data) + try { + const res = await fetch(url, { + method: 'GET', + }) + const data = new Uint8Array(await res.arrayBuffer()) + await importFile(getFileName(res), data) + checkCharOrder() + } catch (error) { + alertError(language.errors.noData) + return null + } } if(hash.startsWith('#import_module=')){ const data = hash.replace('#import_module=', '') @@ -381,7 +387,7 @@ export async function characterURLImport() { for(const f of files){ const file = await f.getFile() const data = new Uint8Array(await file.arrayBuffer()) - importFile(f.name, data); + await importFile(f.name, data); } } //@ts-ignore @@ -399,7 +405,7 @@ export async function characterURLImport() { if(files){ for(const file of files){ const data = await readFile(file) - importFile(file, data) + await importFile(file, data) } } } @@ -451,9 +457,9 @@ export async function characterURLImport() { } function getFileName(res : Response) : string { - return getFormContent(res.headers.get('content-disposition')) || getFromURL(res.url); + return getFromContent(res.headers.get('content-disposition')) || getFromURL(res.url); - function getFormContent(contentDisposition : string) { + function getFromContent(contentDisposition : string) { if (!contentDisposition) return null; const pattern = /filename\*=UTF-8''([^"';\n]+)|filename[^;\n=]*=["']?([^"';\n]+)["']?/; const matches = contentDisposition.match(pattern);