Make XHR requests async
This commit is contained in:
parent
d5fa2593c0
commit
2f335cf57a
@ -33,6 +33,10 @@ export function meta() {
|
||||
{
|
||||
title: "Report an Exploiter - Car Crushers",
|
||||
},
|
||||
{
|
||||
name: "description",
|
||||
content: "Use this page to report a cheater",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@ -170,33 +174,37 @@ export default function () {
|
||||
};
|
||||
|
||||
for (let i = 0; i < upload_urls.length; i++) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
await new Promise((resolve) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open("PUT", upload_urls[i], false);
|
||||
xhr.setRequestHeader(
|
||||
"content-type",
|
||||
(files[i].name.split(".").at(-1) as string).toLowerCase() === "mov"
|
||||
? "video/mp4"
|
||||
: files[i].type ||
|
||||
fileTypes[files[i].name.split(".").at(-1) as string],
|
||||
);
|
||||
xhr.open("PUT", upload_urls[i], true);
|
||||
xhr.setRequestHeader(
|
||||
"content-type",
|
||||
(files[i].name.split(".").at(-1) as string).toLowerCase() === "mov"
|
||||
? "video/mp4"
|
||||
: files[i].type ||
|
||||
fileTypes[files[i].name.split(".").at(-1) as string],
|
||||
);
|
||||
|
||||
xhr.upload.addEventListener("progress", increaseProgress);
|
||||
xhr.upload.onabort = () => {
|
||||
shouldRecall = true;
|
||||
setUploading(false);
|
||||
setFileProgress(0);
|
||||
};
|
||||
xhr.upload.onerror = () => {
|
||||
shouldRecall = true;
|
||||
setUploading(false);
|
||||
setFileProgress(0);
|
||||
};
|
||||
xhr.upload.onloadend = () => {
|
||||
if (i === upload_urls.length - 1) setUploading(false);
|
||||
};
|
||||
xhr.upload.addEventListener("progress", increaseProgress);
|
||||
xhr.upload.onabort = () => {
|
||||
shouldRecall = true;
|
||||
setUploading(false);
|
||||
setFileProgress(0);
|
||||
};
|
||||
xhr.upload.onerror = () => {
|
||||
shouldRecall = true;
|
||||
setUploading(false);
|
||||
setFileProgress(0);
|
||||
};
|
||||
xhr.upload.onloadend = () => {
|
||||
if (i === upload_urls.length - 1) setUploading(false);
|
||||
|
||||
xhr.send(files[i]);
|
||||
resolve(null);
|
||||
};
|
||||
|
||||
xhr.send(files[i]);
|
||||
});
|
||||
}
|
||||
|
||||
if (shouldRecall) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user