diff options
Diffstat (limited to 'webAO')
| -rw-r--r-- | webAO/utils/fileExists.ts | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/webAO/utils/fileExists.ts b/webAO/utils/fileExists.ts index 5b60976..06621e4 100644 --- a/webAO/utils/fileExists.ts +++ b/webAO/utils/fileExists.ts @@ -1,18 +1,7 @@ -const fileExists = async (url) => 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); -}); -export default fileExists; +export default async function fileExists(url: string): Promise<boolean> { + return fetch(url, { + method: 'HEAD', + }).then((response) => { + return response.ok; + }); +} |
