Fixed the bug where the character list was not updating in certain situations after importing a URL.

This commit is contained in:
ModMapper
2024-10-22 20:46:00 +09:00
parent c12ec62b34
commit e0edf74b46

View File

@@ -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);