FIX[webapp]: Allow downloading workbooks with unicode charaters
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
8a9ae00cad
commit
df0012a1c4
@@ -1,3 +1,24 @@
|
|||||||
|
function sanitizeFileName(name: string): string {
|
||||||
|
const normalized = name.normalize("NFKC");
|
||||||
|
|
||||||
|
const safe = [...normalized]
|
||||||
|
.map((char) => {
|
||||||
|
const code = char.charCodeAt(0);
|
||||||
|
// Remove control chars and filesystem-unsafe chars
|
||||||
|
if (
|
||||||
|
code <= 0x1f || // ASCII control
|
||||||
|
code === 0x7f || // DEL
|
||||||
|
["<", ">", ":", '"', "/", "\\", "|", "?", "*"].includes(char)
|
||||||
|
) {
|
||||||
|
return "_";
|
||||||
|
}
|
||||||
|
return char;
|
||||||
|
})
|
||||||
|
.join("");
|
||||||
|
|
||||||
|
return safe.slice(0, 100).trim();
|
||||||
|
}
|
||||||
|
|
||||||
export async function uploadFile(
|
export async function uploadFile(
|
||||||
arrayBuffer: ArrayBuffer,
|
arrayBuffer: ArrayBuffer,
|
||||||
fileName: string,
|
fileName: string,
|
||||||
@@ -30,11 +51,11 @@ export async function get_documentation_model(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadModel(bytes: Uint8Array, fileName: string) {
|
export async function downloadModel(bytes: Uint8Array, fileName: string) {
|
||||||
|
const sanitizedFileName = sanitizeFileName(fileName);
|
||||||
const response = await fetch("/api/download", {
|
const response = await fetch("/api/download", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
"Content-Disposition": `attachment; filename="${fileName}"`,
|
|
||||||
},
|
},
|
||||||
body: bytes,
|
body: bytes,
|
||||||
});
|
});
|
||||||
@@ -49,8 +70,7 @@ export async function downloadModel(bytes: Uint8Array, fileName: string) {
|
|||||||
a.style.display = "none";
|
a.style.display = "none";
|
||||||
a.href = url;
|
a.href = url;
|
||||||
|
|
||||||
// Use the same filename or change as needed
|
a.download = `${sanitizedFileName}.xlsx`;
|
||||||
a.download = `${fileName}.xlsx`;
|
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user