feat: support URL obj for toGateway

This commit is contained in:
DIYgod 2023-05-09 01:04:01 +01:00
parent 5d3df2d150
commit cc818a9f6b
No known key found for this signature in database
2 changed files with 8 additions and 3 deletions

View File

@ -25,7 +25,7 @@ export const Avatar: React.FC<
const image = useMemo(() => {
for (const image of images) {
if (image) return toGateway((image as any)?.url || image)
if (image) return toGateway(image)
}
}, [images])

View File

@ -7,8 +7,13 @@ export type ToGatewayConfig = {
forceFallback?: boolean
}
export const toGateway = (url: string) => {
const ipfsUrl = toIPFS(url)
export const toGateway = (url: string | URL) => {
let ipfsUrl
if (typeof url === "string") {
ipfsUrl = toIPFS(url)
} else {
ipfsUrl = toIPFS(url.toString())
}
return ipfsUrl?.replaceAll(IPFS_PREFIX, IPFS_GATEWAY)
}