From 7661b6c7314327b6b8523976ba89755db4d281b9 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Wed, 29 Nov 2023 23:14:35 +0100 Subject: Simplify and make fileExists proper typescript --- webAO/utils/fileExists.ts | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'webAO/utils/fileExists.ts') 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 { + return fetch(url, { + method: 'HEAD', + }).then((response) => { + return response.ok; + }); +} -- cgit