import { getIpfsIoUrl , getPinataFxhashGateway , getPinataUrlFromCid , getPinataFxhashGatewaySafe } from "../utils/ipfs" ; const ipfsRegex = new RegExp ( "^ipfs:\/\/" ) ; export function ipfsUrlToID ( url ) { if ( ! ipfsRegex . test ( url ) ) return null ; return url . slice ( 7 ) ; } param resource export function ipfsCidFromUriOrCid ( resource ) { if ( ! ipfsRegex . test ( resource ) ) return resource ; return resource . slice ( 7 ) ; } export function ipfsDisplayUrl ( ipfsUrl ) { if ( ! ipfsUrl || ipfsUrl . length < 15 ) return "" ; const cid = ipfsUrlToID ( ipfsUrl ) ; if ( ! cid ) return "" ; return `https://ipfs.io/ipfs/${ cid }` ; } param resource param gateway export function ipfsGatewayUrl ( resource , gateway = "pinata-fxhash" ) { if ( ! resource ) return "" ; const cid = ipfsCidFromUriOrCid ( resource ) ; switch ( gateway ) { case "pinata-fxhash" : return getPinataFxhashGateway ( cid ) ; case "pinata-fxhash-safe" : return getPinataFxhashGatewaySafe ( cid ) ; case "pinata" : return getPinataUrlFromCid ( cid ) ; case "ipfsio" : default : return getIpfsIoUrl ( cid ) ; } }