diff --git a/ref/classes/tweets.js b/ref/classes/tweets.js index 5b8d370..ed5346c 100644 --- a/ref/classes/tweets.js +++ b/ref/classes/tweets.js @@ -59,6 +59,7 @@ class Tweets { this.hasMultiImage = false; this.hasImages = false; this.imgArray = []; + this.imgAltArray = []; this.imgCount = 0; this.imgUrl = ""; this.iterateExists = false; @@ -212,6 +213,9 @@ class Tweets { if (this.hasSingleImage) { debuglog(`${this.orig} Tweet #${this.no} contains a single image.`, 2) this.imgCount = 1; + var imgAltText = await elements.getAttribute(driver,this.x.singleImage,"alt") + this.imgAltArray.push(imgAltText); + debuglog(this.imgAltArray,2); var origImageURL = await elements.getAttribute(driver,this.x.singleImage,"src") const reg = /&name=\w+/ this.imgUrl = origImageURL.replace(reg, "&name=large"); @@ -229,6 +233,9 @@ class Tweets { this.iterateExists = await elements.doesExist(driver,this.x.multiImages(x,y)); if (this.iterateExists) { debuglog(`${x},${y} Exists!`); + var imgAltText = await elements.getAttribute(driver,this.x.multiImages(x,y),"alt") + this.imgAltArray.push(imgAltText); + debuglog(this.imgAltArray,2); var origImageURL = await elements.getAttribute(driver,this.x.multiImages(x,y),'src') const reg = /&name=\w+/ this.imgUrl = origImageURL.replace(reg, "&name=large"); @@ -253,7 +260,8 @@ class Tweets { for (var f = 1; f < (this.imgCount+1); f++) { var jpgPath = `${imgSavePath}${this.orig == 'home' ? '' : 'r'}${this.no}.${f}.jpg` debuglog(`uploading image to mastodon: ${jpgPath}`); - var imgid = await mastodon.postMedia(jpgPath) + debuglog(this.imgAltArray); + var imgid = await mastodon.postMedia(jpgPath,this.imgAltArray[f-1]); debuglog(`mastodon image id: ${imgid}`); this.imgArray.push(imgid); } diff --git a/ref/functions/mastodon.js b/ref/functions/mastodon.js index 7aa3926..13829bc 100644 --- a/ref/functions/mastodon.js +++ b/ref/functions/mastodon.js @@ -19,11 +19,16 @@ function setupMastodon(){ return M; } -async function postMedia(path){ +async function postMedia(path,alt){ id = 0; + if (alt == null) { + alt = "Image"; + } if (args.enablePosts){ var M = setupMastodon(); - await M.post('media', { file: fs.createReadStream(path) }).then(resp => { + params = { file: fs.createReadStream(path) } + Object.assign(params, { description: alt }); + await M.post('media', params).then(resp => { id = resp.data.id; }, function(err) { if (err) {