Created
June 15, 2021 04:09
-
-
Save fragosti/5c1b9bdfdd01e7fa6ed6815f4b094b55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getMediaFromProperties = ( | |
properties: CollectibleProperties, | |
animationUrl: string, | |
): CollectibleMedia | undefined => { | |
// OpenSea standard https://docs.opensea.io/docs/metadata-standards | |
if (animationUrl) { | |
const fileExt = getLast(animationUrl.split(".")); | |
const queryExt = new URLSearchParams(getLast(animationUrl.split("?"))).get("ext"); | |
if ( | |
fileExt === FileExtension.GLB || | |
fileExt === FileExtension.glTF || | |
queryExt === FileExtension.GLB || | |
queryExt === FileExtension.glTF | |
) { | |
return { | |
type: "3d", | |
fileUri: animationUrl, | |
}; | |
} | |
} | |
const { files, category } = properties || {}; | |
if (!files || !files.length || !category) { | |
return; | |
} | |
const [firstFile] = files; | |
// Metaplex | |
if (isObject(firstFile)) { | |
for (const file of files) { | |
const { type, uri } = file as any; | |
if (type === FileExtension.GLB || type === FileExtension.glTF) { | |
return { | |
type: "3d", | |
fileUri: uri, | |
}; | |
} | |
} | |
} | |
// Legacy Metaplex | |
if (isString(firstFile)) { | |
if (category === "vr") { | |
const [fileUri] = files; | |
return { | |
type: "3d", | |
fileUri, | |
}; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment