Skip to content

Instantly share code, notes, and snippets.

@fragosti
Created June 15, 2021 04:09
Show Gist options
  • Save fragosti/5c1b9bdfdd01e7fa6ed6815f4b094b55 to your computer and use it in GitHub Desktop.
Save fragosti/5c1b9bdfdd01e7fa6ed6815f4b094b55 to your computer and use it in GitHub Desktop.
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