aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/fileExists.js
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2022-03-13 16:53:42 +0100
committerGitHub <noreply@github.com>2022-03-13 16:53:42 +0100
commit0b77e08379d2d8a32020cf5b78b89ca3973ab204 (patch)
tree48425c2b0008607e41453ada8fe69cf7a9c66056 /webAO/utils/fileExists.js
parentc84825118e2c9f60d05e685ea33e7c3e27fa6e2c (diff)
parentd9a78c0f6ec11ced9748eaca2f62336a2201fbbc (diff)
Merge pull request #105 from caleb-mabry/async-fileexists
New Char_Icon Load Flow
Diffstat (limited to 'webAO/utils/fileExists.js')
-rw-r--r--webAO/utils/fileExists.js22
1 files changed, 16 insertions, 6 deletions
diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js
index 6d32a1e..7978cbc 100644
--- a/webAO/utils/fileExists.js
+++ b/webAO/utils/fileExists.js
@@ -1,8 +1,18 @@
-const fileExists = async (url) => {
+const fileExists = async (url) => new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
- xhr.open('HEAD', url, false);
- xhr.send();
-
- return xhr.status === 200;
-};
+ xhr.open('HEAD', url);
+ xhr.onload = function (e) {
+ if (xhr.readyState === 4) {
+ if (xhr.status === 200) {
+ resolve(true);
+ } else {
+ resolve(false);
+ }
+ }
+ };
+ xhr.onerror = function (e) {
+ resolve(false);
+ };
+ xhr.send(null);
+});
export default fileExists;