making post images large
This commit is contained in:
parent
47caf810d4
commit
67b65b4555
27
bot.js
27
bot.js
@ -1,11 +1,28 @@
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
require("dotenv").config();
|
||||
}
|
||||
var fs = require("fs");
|
||||
const axios = require("axios");
|
||||
const urlMetadata = require("url-metadata");
|
||||
let Mastodon = require("mastodon-api");
|
||||
let Parser = require("rss-parser");
|
||||
let parser = new Parser();
|
||||
let maxPostPerScan = process.env.MAX_POST_PER_SCAN;
|
||||
|
||||
const download_image = (url, image_path) =>
|
||||
axios({
|
||||
url,
|
||||
responseType: "stream",
|
||||
}).then(
|
||||
(response) =>
|
||||
new Promise((resolve, reject) => {
|
||||
response.data
|
||||
.pipe(fs.createWriteStream(image_path))
|
||||
.on("finish", () => resolve())
|
||||
.on("error", (e) => reject(e));
|
||||
})
|
||||
);
|
||||
|
||||
(async () => {
|
||||
console.log("Starting Bot");
|
||||
await postFeed();
|
||||
@ -42,8 +59,18 @@ async function postFeed() {
|
||||
|
||||
if (count > maxPostPerScan) return false;
|
||||
|
||||
let metadata = await urlMetadata(item.link);
|
||||
|
||||
// Download feed item image
|
||||
await download_image(metadata.image, "post-image");
|
||||
|
||||
let mediaup = await M.post("media", {
|
||||
file: fs.createReadStream(item.guid),
|
||||
});
|
||||
|
||||
await M.post("statuses", {
|
||||
status: `${item.title}\n\n#NeoVibe #${process.env.POST_HASHTAG}\n\n${item.link}`,
|
||||
media_ids: [mediaup.data.id],
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
3348
package-lock.json
generated
3348
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -17,9 +17,11 @@
|
||||
},
|
||||
"homepage": "https://github.com/MikeHuntington/neovibe-bots#readme",
|
||||
"dependencies": {
|
||||
"axios": "^1.2.1",
|
||||
"dotenv": "^16.0.3",
|
||||
"mastodon-api": "^1.3.0",
|
||||
"rss-parser": "^3.12.0",
|
||||
"url-metadata": "^2.5.0",
|
||||
"yaml": "^2.1.3"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user