Skip to content

Commit

Permalink
Revert fileExists
Browse files Browse the repository at this point in the history
  • Loading branch information
OmniTroid committed Nov 29, 2023
1 parent 4766a80 commit 90ed4b7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions webAO/utils/fileExists.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
export default async function fileExists(url: string): Promise<boolean> {
return fetch(url, {
method: 'HEAD',
}).then((response) => {
return response.ok;
}).catch(() => {
return false;
return new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.open('HEAD', url);
xhr.onload = function checkLoad() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve(true);
} else {
resolve(false);
}
}
};
xhr.onerror = function checkError() {
resolve(false);
};
xhr.send(null);
});
}

0 comments on commit 90ed4b7

Please sign in to comment.