diff --git a/src/utils/getCommentMediaInfo.js b/src/utils/getCommentMediaInfo.js index 27a33a5b..8415eebe 100644 --- a/src/utils/getCommentMediaInfo.js +++ b/src/utils/getCommentMediaInfo.js @@ -11,7 +11,15 @@ const getCommentMediaInfo = (comment) => { }; } if (comment?.link) { - const mime = extName(new URL(comment?.link).pathname.replace('/', ''))[0]?.mime + try { + new URL(comment.link); + } catch (error) { + console.error("Invalid URL:", comment.link); + return; + } + + const mime = extName(new URL(comment?.link).pathname.replace('/', ''))[0]?.mime; + if (mime?.startsWith('image')) { return { url: comment.link, @@ -35,4 +43,4 @@ const getCommentMediaInfo = (comment) => { } }; -export default getCommentMediaInfo; \ No newline at end of file +export default getCommentMediaInfo;