Fixed bug on removed cover

This commit is contained in:
dbroqua 2020-05-01 09:10:13 +02:00
parent 9203335963
commit acc70e6a83

15
libs.js
View File

@ -249,19 +249,28 @@ const formatMessage = (values) => {
* @param {String} cover
*/
const publishMessage = (song, cover) => {
const status = formatMessage(song)
const catch = (err, res) => {
if ( err ) {
console.log(config.colors.FgRed, 'ERR on publishMessage:', err, config.colors.Reset)
}
}
if (cover) {
getMedia(cover, (err, dest) => {
if (err) {
M.post('statuses', { status: formatMessage(song) })
M.post('statuses', { status }, catch)
} else {
M.post('media', { file: fs.createReadStream(dest) }).then(resp => {
const id = resp.data.id
M.post('statuses', { status: formatMessage(song), media_ids: [id] })
M.post('statuses', { status, media_ids: [id] }, catch)
})
.catch( () => {
M.post('statuses', { status }, catch)
})
}
})
} else {
M.post('statuses', { status: formatMessage(song) })
M.post('statuses', { status }, catch)
}
}