Enable the explorer to render content from data URIs (#24235)

* Enable explorer to render images from data URIs

* Add regex to check for image mime type
This commit is contained in:
yung soosh 2022-04-12 01:17:26 -07:00 committed by GitHub
parent 077bc4f407
commit 865a8307e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -317,6 +317,8 @@ async function fetchAccountInfo(
});
}
const IMAGE_MIME_TYPE_REGEX = /data:image\/(svg\+xml|png|jpeg|gif)/g;
const getMetaDataJSON = async (
id: string,
metadata: programs.metadata.MetadataData
@ -331,9 +333,11 @@ const getMetaDataJSON = async (
}
if (extended?.image) {
extended.image = extended.image.startsWith("http")
? extended.image
: `${metadata.data.uri}/${extended.image}`;
extended.image =
extended.image.startsWith("http") ||
IMAGE_MIME_TYPE_REGEX.test(extended.image)
? extended.image
: `${metadata.data.uri}/${extended.image}`;
}
return extended;