fix(plugins/tweets): handle non text/html attachments

This commit is contained in:
lowlighter
2022-09-01 22:23:19 -04:00
parent 407bbd599b
commit b5bcbff410

View File

@@ -50,16 +50,21 @@ export default async function({login, imports, data, q, account}, {enabled = fal
if (tweet.attachments) 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})}))) 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) { if (linked) {
const {result: {ogImage, ogSiteName: website, ogTitle: title, ogDescription: description}} = await imports.opengraph({url: linked}) try {
const image = await imports.imgb64(ogImage?.url, {height: -1, width: 450, fallback: false}) const {result: {ogImage, ogSiteName: website, ogTitle: title, ogDescription: description}} = await imports.opengraph({url: linked})
if (image) { const image = await imports.imgb64(ogImage?.url, {height: -1, width: 450, fallback: false})
if (tweet.attachments) if (image) {
tweet.attachments.unshift([{image, title, description, website}]) if (tweet.attachments)
else tweet.attachments.unshift([{image, title, description, website}])
tweet.attachments = [{image, title, description, website}] else
tweet.attachments = [{image, title, description, website}]
}
else {
tweet.text = `${tweet.text}\n${linked}`
}
} }
else { catch (error) {
tweet.text = `${tweet.text}\n${linked}` console.debug(`metrics/compute/${login}/plugins > tweets > error while retrieving linked content: ${error.message}`)
} }
} }
} }