This commit is contained in:
subodh committed 2026-03-13 10:55:15 +05:30
1 parent 6f0ebad75e
commit 789c8cebf4
1 file changed
+17 -8
+17 -8
View File
@@ -72,14 +72,19 @@ export default function Home() {
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
const data = JSON.parse(xhr.responseText) as { url: string };
const raw = data.url ?? "";
const absolute = raw.startsWith("http")
? raw
: `https://${raw.replace(/^\/\//, "")}`;
setResultUrl(absolute);
setProgress(100);
setStatus("done");
try {
const data = JSON.parse(xhr.responseText) as { url: string };
const raw = data.url ?? "";
const absolute = raw.startsWith("http")
? raw
: `https://${raw.replace(/^\/\//, "")}`;
setResultUrl(absolute);
setProgress(100);
setStatus("done");
} catch {
setErrorMessage("Unexpected response from server.");
setStatus(preUploadStatus.current);
}
} else {
let detail = "Upload failed.";
try {
@@ -98,6 +103,10 @@ export default function Home() {
setStatus(preUploadStatus.current);
};
// Explicitly set responseType to "text" so Firefox does not attempt to
// parse the JSON response body as XML (which would log a benign but
// confusing "XML Parsing Error" in the console).
xhr.responseType = "text";
xhr.open("POST", "/api/upload");
xhr.send(formData);
},