Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ipfs links to use our own ipfs gateway (clean branch) #776

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/antelope/stores/utils/nft-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,25 @@ export async function extractNftMetadata(
// We need to look at the metadata
// we iterate over the metadata properties
for (const property in metadata) {
const value = metadata[property];
if (!value) {
const _value = metadata[property];

if (typeof _value !== 'string') {
continue;
}

const value = _value.replace('ipfs://', IPFS_GATEWAY) as string;

// if the value is a string and contains a valid url of a known media format, use it.
// image formats: .gif, .avif, .apng, .jpeg, .jpg, .jfif, .pjpeg, .pjp, .png, .svg, .webp
if (
!image && // if we already have a preview, we don't need to keep looking
typeof value === 'string' &&
urlIsPicture(value)
) {
image = value;
}
// audio formats: .mp3, .wav, .aac, .webm
if (
!mediaSource && // if we already have a source, we don't need to keep looking
typeof value === 'string' &&
await urlIsAudio(value)
) {
mediaType = NFTSourceTypes.AUDIO;
Expand All @@ -72,7 +74,6 @@ export async function extractNftMetadata(
// video formats: .mp4, .webm, .ogg
if (
!mediaSource && // if we already have a source, we don't need to keep looking
typeof value === 'string' &&
await urlIsVideo(value)
) {
mediaType = NFTSourceTypes.VIDEO;
Expand All @@ -81,7 +82,7 @@ export async function extractNftMetadata(

const regex = /^data:(image|audio|video)\/\w+;base64,[\w+/=]+$/;

const match = typeof value === 'string' && value.match(regex);
const match = value.match(regex);

if (match) {
const contentType = match[1];
Expand Down
Loading