diff options
Diffstat (limited to 'webAO/utils/fileExists.js')
| -rw-r--r-- | webAO/utils/fileExists.js | 22 |
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; |
