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)
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}`)
}
}
}