From 477b93638c035ae9772376736726dbdc51845f51 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Wed, 29 Nov 2023 23:10:57 +0100 Subject: Rename fileExists.js to fileExists.ts --- webAO/utils/fileExists.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 webAO/utils/fileExists.ts (limited to 'webAO/utils/fileExists.ts') diff --git a/webAO/utils/fileExists.ts b/webAO/utils/fileExists.ts new file mode 100644 index 0000000..5b60976 --- /dev/null +++ b/webAO/utils/fileExists.ts @@ -0,0 +1,18 @@ +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; -- cgit