Fixed bugs related to URL file import and improved usability (#652)
# PR Checklist - After uploading the character file to GitHub, conducted tests in both the RisuAI web and Node environments. # Description - Fixed the bug where the character list was not updating in certain situations after importing a URL. - Removed the hash after import to prevent the same character from being imported again upon refresh. - Added exception handling for import file downloads.
This commit is contained in:
@@ -300,12 +300,19 @@ export async function characterURLImport() {
|
|||||||
|
|
||||||
const hash = location.hash
|
const hash = location.hash
|
||||||
if(hash.startsWith('#import=')){
|
if(hash.startsWith('#import=')){
|
||||||
|
location.hash = ''
|
||||||
const url = hash.replace('#import=', '')
|
const url = hash.replace('#import=', '')
|
||||||
const res = await fetch(url, {
|
try {
|
||||||
method: 'GET',
|
const res = await fetch(url, {
|
||||||
})
|
method: 'GET',
|
||||||
const data = new Uint8Array(await res.arrayBuffer())
|
})
|
||||||
importFile(getFileName(res), data)
|
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=')){
|
if(hash.startsWith('#import_module=')){
|
||||||
const data = hash.replace('#import_module=', '')
|
const data = hash.replace('#import_module=', '')
|
||||||
@@ -381,7 +388,7 @@ export async function characterURLImport() {
|
|||||||
for(const f of files){
|
for(const f of files){
|
||||||
const file = await f.getFile()
|
const file = await f.getFile()
|
||||||
const data = new Uint8Array(await file.arrayBuffer())
|
const data = new Uint8Array(await file.arrayBuffer())
|
||||||
importFile(f.name, data);
|
await importFile(f.name, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -399,7 +406,7 @@ export async function characterURLImport() {
|
|||||||
if(files){
|
if(files){
|
||||||
for(const file of files){
|
for(const file of files){
|
||||||
const data = await readFile(file)
|
const data = await readFile(file)
|
||||||
importFile(file, data)
|
await importFile(file, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,9 +458,9 @@ export async function characterURLImport() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getFileName(res : Response) : string {
|
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;
|
if (!contentDisposition) return null;
|
||||||
const pattern = /filename\*=UTF-8''([^"';\n]+)|filename[^;\n=]*=["']?([^"';\n]+)["']?/;
|
const pattern = /filename\*=UTF-8''([^"';\n]+)|filename[^;\n=]*=["']?([^"';\n]+)["']?/;
|
||||||
const matches = contentDisposition.match(pattern);
|
const matches = contentDisposition.match(pattern);
|
||||||
|
|||||||
Reference in New Issue
Block a user