Commit 9ea3658e authored by tom's avatar tom

rewrite to fetch

parent 350147a4
...@@ -18,19 +18,14 @@ const NftMedia = ({ imageUrl, animationUrl, className }: Props) => { ...@@ -18,19 +18,14 @@ const NftMedia = ({ imageUrl, animationUrl, className }: Props) => {
return; return;
} }
const xhr = new XMLHttpRequest(); // media could be either gif or video
xhr.open('HEAD', animationUrl, true); // so we pre-fetch the resources in order to get its content type
fetch(animationUrl, { method: 'HEAD' })
.then((response) => {
const contentType = response.headers.get('content-type');
setType(contentType?.startsWith('video') ? 'video' : 'image');
});
xhr.onload = function() {
const contentType = xhr.getResponseHeader('Content-Type');
setType(contentType?.startsWith('video') ? 'video' : 'image');
};
xhr.send();
return () => {
xhr.abort();
};
}, [ animationUrl ]); }, [ animationUrl ]);
if (!type) { if (!type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment