From ba6fe429b05c85cbbabb833ab01c69a91a649327 Mon Sep 17 00:00:00 2001 From: plebbitor Date: Wed, 12 Apr 2023 17:09:12 +0200 Subject: [PATCH] fix getCommentMediaInfo --- src/utils/getCommentMediaInfo.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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;