From b5bcbff410a88178519050a83f1ded0c622c61a3 Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Thu, 1 Sep 2022 22:23:19 -0400 Subject: [PATCH] fix(plugins/tweets): handle non text/html attachments --- source/plugins/tweets/index.mjs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/source/plugins/tweets/index.mjs b/source/plugins/tweets/index.mjs index 3098c170..b9a6aa45 100644 --- a/source/plugins/tweets/index.mjs +++ b/source/plugins/tweets/index.mjs @@ -50,16 +50,21 @@ export default async function({login, imports, data, q, account}, {enabled = fal if (tweet.attachments) tweet.attachments = await Promise.all(tweet.attachments.media_keys.filter(key => medias.get(key)).map(key => medias.get(key)).map(async url => ({image: await imports.imgb64(url, {height: -1, width: 450})}))) if (linked) { - const {result: {ogImage, ogSiteName: website, ogTitle: title, ogDescription: description}} = await imports.opengraph({url: linked}) - const image = await imports.imgb64(ogImage?.url, {height: -1, width: 450, fallback: false}) - if (image) { - if (tweet.attachments) - tweet.attachments.unshift([{image, title, description, website}]) - else - tweet.attachments = [{image, title, description, website}] + try { + const {result: {ogImage, ogSiteName: website, ogTitle: title, ogDescription: description}} = await imports.opengraph({url: linked}) + const image = await imports.imgb64(ogImage?.url, {height: -1, width: 450, fallback: false}) + if (image) { + if (tweet.attachments) + tweet.attachments.unshift([{image, title, description, website}]) + else + tweet.attachments = [{image, title, description, website}] + } + else { + tweet.text = `${tweet.text}\n${linked}` + } } - else { - tweet.text = `${tweet.text}\n${linked}` + catch (error) { + console.debug(`metrics/compute/${login}/plugins > tweets > error while retrieving linked content: ${error.message}`) } } }