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",
|
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++) {
|
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.open("PUT", upload_urls[i], true);
|
||||||
xhr.setRequestHeader(
|
xhr.setRequestHeader(
|
||||||
"content-type",
|
"content-type",
|
||||||
(files[i].name.split(".").at(-1) as string).toLowerCase() === "mov"
|
(files[i].name.split(".").at(-1) as string).toLowerCase() === "mov"
|
||||||
? "video/mp4"
|
? "video/mp4"
|
||||||
: files[i].type ||
|
: files[i].type ||
|
||||||
fileTypes[files[i].name.split(".").at(-1) as string],
|
fileTypes[files[i].name.split(".").at(-1) as string],
|
||||||
);
|
);
|
||||||
|
|
||||||
xhr.upload.addEventListener("progress", increaseProgress);
|
xhr.upload.addEventListener("progress", increaseProgress);
|
||||||
xhr.upload.onabort = () => {
|
xhr.upload.onabort = () => {
|
||||||
shouldRecall = true;
|
shouldRecall = true;
|
||||||
setUploading(false);
|
setUploading(false);
|
||||||
setFileProgress(0);
|
setFileProgress(0);
|
||||||
};
|
};
|
||||||
xhr.upload.onerror = () => {
|
xhr.upload.onerror = () => {
|
||||||
shouldRecall = true;
|
shouldRecall = true;
|
||||||
setUploading(false);
|
setUploading(false);
|
||||||
setFileProgress(0);
|
setFileProgress(0);
|
||||||
};
|
};
|
||||||
xhr.upload.onloadend = () => {
|
xhr.upload.onloadend = () => {
|
||||||
if (i === upload_urls.length - 1) setUploading(false);
|
if (i === upload_urls.length - 1) setUploading(false);
|
||||||
};
|
|
||||||
|
|
||||||
xhr.send(files[i]);
|
resolve(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send(files[i]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRecall) {
|
if (shouldRecall) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user