diff options
| author | David Skoland <davidskoland@gmail.com> | 2023-11-30 00:35:08 +0100 |
|---|---|---|
| committer | David Skoland <davidskoland@gmail.com> | 2023-11-30 00:35:08 +0100 |
| commit | 90ed4b74cac7e8e410175cc3445d7140671e221f (patch) | |
| tree | 3c4f6927ae2c515dca1585430aca6cd7f1bf8874 /webAO | |
| parent | 4766a801382e6373b982a2731cdc7ea24f0c70b3 (diff) | |
Revert fileExists
Diffstat (limited to 'webAO')
| -rw-r--r-- | webAO/utils/fileExists.ts | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/webAO/utils/fileExists.ts b/webAO/utils/fileExists.ts index f1a9924..abb2928 100644 --- a/webAO/utils/fileExists.ts +++ b/webAO/utils/fileExists.ts @@ -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); }); } |
