import { NftMediaType } from 'components/core/enums' ; import { Nft } from 'types/Nft' ; const FALLBACK_URL = 'https://i.ibb.co/q7DP0Dz/no-image.png' ; export function getResizedNftImageUrlWithFallback ( nft , size = 288 ) { const { image_url , image_original_url , animation_original_url , asset_contract : { contract_image_url } , } = nft ; if ( animation_original_url ?. endsWith ( '.gif' ) ) { return animation_original_url ; } if ( image_url ?. includes ( 'googleusercontent' ) ) { return `${ image_url }=w${ size }` ; } return image_original_url || image_url || contract_image_url || FALLBACK_URL ; } export function getFileExtension ( url ) { const splitUrl = url . split ( '.' ) ; return splitUrl . length < 2 ? '' : splitUrl . pop ( ) ?? '' ; } export function getVideoUrl ( nft ) { const imageUrlFileExtension = getFileExtension ( nft . image_url ) ; return imageUrlFileExtension === 'mp4' ? nft . image_url : nft . animation_url ; } export function getMediaTypeForAssetUrl ( assetUrl ) { const fileExtension = getFileExtension ( assetUrl ) ; switch ( fileExtension ) { case 'html' : return NftMediaType . ANIMATION ; case 'mp4' : return NftMediaType . VIDEO ; case 'mp3' : return NftMediaType . AUDIO ; case 'glb' : return NftMediaType . MODEL ; case 'gif' : return NftMediaType . IMAGE ; default : return NftMediaType . ANIMATION ; } } export function getMediaType ( nft ) { const imageUrlType = getMediaTypeForAssetUrl ( nft . image_url ) ; if ( imageUrlType === NftMediaType . VIDEO ) { return NftMediaType . VIDEO ; } if ( ! nft . animation_url ) { return NftMediaType . IMAGE ; } return getMediaTypeForAssetUrl ( nft . animation_url ) ; }