aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/fileExists.ts
diff options
context:
space:
mode:
authorDavid Skoland <davidskoland@gmail.com>2023-11-29 23:10:57 +0100
committerDavid Skoland <davidskoland@gmail.com>2023-11-29 23:10:57 +0100
commit477b93638c035ae9772376736726dbdc51845f51 (patch)
treedd56e42034304f2bd9291ed548cc51b7b5be8fca /webAO/utils/fileExists.ts
parent4d2e26939647281e5a814f7089c8b7cd54f63171 (diff)
Rename fileExists.js to fileExists.ts
Diffstat (limited to 'webAO/utils/fileExists.ts')
-rw-r--r--webAO/utils/fileExists.ts18
1 files changed, 18 insertions, 0 deletions
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;