update
This commit is contained in:
1 parent
6f0ebad75e
commit
789c8cebf4
1 file changed
+17
-8
@@ -72,14 +72,19 @@ export default function Home() {
|
|||||||
|
|
||||||
xhr.onload = () => {
|
xhr.onload = () => {
|
||||||
if (xhr.status >= 200 && xhr.status < 300) {
|
if (xhr.status >= 200 && xhr.status < 300) {
|
||||||
const data = JSON.parse(xhr.responseText) as { url: string };
|
try {
|
||||||
const raw = data.url ?? "";
|
const data = JSON.parse(xhr.responseText) as { url: string };
|
||||||
const absolute = raw.startsWith("http")
|
const raw = data.url ?? "";
|
||||||
? raw
|
const absolute = raw.startsWith("http")
|
||||||
: `https://${raw.replace(/^\/\//, "")}`;
|
? raw
|
||||||
setResultUrl(absolute);
|
: `https://${raw.replace(/^\/\//, "")}`;
|
||||||
setProgress(100);
|
setResultUrl(absolute);
|
||||||
setStatus("done");
|
setProgress(100);
|
||||||
|
setStatus("done");
|
||||||
|
} catch {
|
||||||
|
setErrorMessage("Unexpected response from server.");
|
||||||
|
setStatus(preUploadStatus.current);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let detail = "Upload failed.";
|
let detail = "Upload failed.";
|
||||||
try {
|
try {
|
||||||
@@ -98,6 +103,10 @@ export default function Home() {
|
|||||||
setStatus(preUploadStatus.current);
|
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.open("POST", "/api/upload");
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user