diff options
| author | David Skoland <davidskoland@gmail.com> | 2023-11-29 23:14:35 +0100 |
|---|---|---|
| committer | David Skoland <davidskoland@gmail.com> | 2023-11-29 23:16:53 +0100 |
| commit | 7661b6c7314327b6b8523976ba89755db4d281b9 (patch) | |
| tree | f90625a10fbeed943cba0a7067baf8e3443b84c6 /webAO/utils | |
| parent | 477b93638c035ae9772376736726dbdc51845f51 (diff) | |
Simplify and make fileExists proper typescript
Diffstat (limited to 'webAO/utils')
| -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; + }); +} |
