aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/fileExists.js
blob: 306511265696cd90a74923d0da2a7ea66a5b26de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const fileExists = async (url) => {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest();
    xhr.open('HEAD', url);
    xhr.onload = function (e) {
      if (xhr.readyState === 4) {
        if (xhr.status === 200) {
          resolve(true)
        } else {
          reject(false)
        }
      }
    };
    xhr.onerror = function (e) {
      resolve(false)
    };
    xhr.send(null);
  })
  
  
};
export default fileExists;