From 9e198fb32a33267a524a19b61343dff17f0421d3 Mon Sep 17 00:00:00 2001 From: "plebeius.eth" Date: Fri, 15 Sep 2023 14:18:01 +0200 Subject: [PATCH] add support for non-direct imgur links --- src/utils/getCommentMediaInfo.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/utils/getCommentMediaInfo.js b/src/utils/getCommentMediaInfo.js index ae263a34..3de39170 100644 --- a/src/utils/getCommentMediaInfo.js +++ b/src/utils/getCommentMediaInfo.js @@ -23,6 +23,31 @@ const getCommentMediaInfo = (comment) => { } else if (host.includes('streamable.com')) { const videoId = url.pathname.split('/')[1]; scrapedThumbnailUrl = `https://cdn-cf-east.streamable.com/image/${videoId}.jpg`; + + } else if (host.includes('imgur.com') && !host.startsWith('i.imgur')) { + const imgId = url.pathname.split('/')[1]; + const formats = ['jpeg', 'jpg', 'png', 'mp4']; + + for (const format of formats) { + const directUrl = `https://i.imgur.com/${imgId}.${format}`; + const imgurUrl = new URL(directUrl); + const mime = extName(imgurUrl.pathname.toLowerCase().replace('/', ''))[0]?.mime; + + if (mime?.startsWith('image')) { + return { + url: directUrl, + type: 'image', + }; + } + + if (mime?.startsWith('video')) { + return { + url: directUrl, + type: 'video', + thumbnail: comment.thumbnailUrl, + }; + } + } } if (canEmbed(url)) {