From 7a1fc5d3e843a534e79d417f32284dd5eb2d476e Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 29 Mar 2023 01:46:09 +0100 Subject: [PATCH] feat: check image src --- src/components/ui/Image.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/ui/Image.tsx b/src/components/ui/Image.tsx index cf8de4ec..aecec6c5 100644 --- a/src/components/ui/Image.tsx +++ b/src/components/ui/Image.tsx @@ -1,7 +1,6 @@ import React from "react" import { default as NextImage, ImageProps } from "next/image" import { toGateway, toIPFS } from "~/lib/ipfs-parser" -import { cn } from "~/lib/utils" export const Image: React.FC< { @@ -20,6 +19,12 @@ export const Image: React.FC< const autoSize = !width && !height && !fill const noOptimization = className?.includes("no-optimization") + try { + new URL(src) + } catch (error) { + return null + } + return noOptimization ? ( // eslint-disable-next-line @next/next/no-img-element