diff options
| -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); }); } |
