fix(avatars) refactor preloading
Use fetch(), which gives us better control over headers.
This commit is contained in:
parent
65a9de346f
commit
a3fb996ff0
|
@ -15,10 +15,16 @@ export function preloadImage(src: string | Object): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const image = document.createElement('img');
|
fetch(src, { referrer: '' })
|
||||||
|
.then(response => {
|
||||||
image.onload = () => resolve(src);
|
if (response.ok) {
|
||||||
image.onerror = reject;
|
resolve(src);
|
||||||
image.src = src;
|
} else {
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue