aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/fileExists.ts
blob: abb29284884234f80a83cbdc64062cde9037be8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export default async function fileExists(url: string): Promise<boolean> {
    return 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);
    });
}