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") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
}
|
}
|
||||||
|
var fs = require("fs");
|
||||||
|
const axios = require("axios");
|
||||||
|
const urlMetadata = require("url-metadata");
|
||||||
let Mastodon = require("mastodon-api");
|
let Mastodon = require("mastodon-api");
|
||||||
let Parser = require("rss-parser");
|
let Parser = require("rss-parser");
|
||||||
let parser = new Parser();
|
let parser = new Parser();
|
||||||
let maxPostPerScan = process.env.MAX_POST_PER_SCAN;
|
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 () => {
|
(async () => {
|
||||||
console.log("Starting Bot");
|
console.log("Starting Bot");
|
||||||
await postFeed();
|
await postFeed();
|
||||||
@ -42,8 +59,18 @@ async function postFeed() {
|
|||||||
|
|
||||||
if (count > maxPostPerScan) return false;
|
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", {
|
await M.post("statuses", {
|
||||||
status: `${item.title}\n\n#NeoVibe #${process.env.POST_HASHTAG}\n\n${item.link}`,
|
status: `${item.title}\n\n#NeoVibe #${process.env.POST_HASHTAG}\n\n${item.link}`,
|
||||||
|
media_ids: [mediaup.data.id],
|
||||||
});
|
});
|
||||||
return true;
|
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",
|
"homepage": "https://github.com/MikeHuntington/neovibe-bots#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^1.2.1",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"mastodon-api": "^1.3.0",
|
"mastodon-api": "^1.3.0",
|
||||||
"rss-parser": "^3.12.0",
|
"rss-parser": "^3.12.0",
|
||||||
|
"url-metadata": "^2.5.0",
|
||||||
"yaml": "^2.1.3"
|
"yaml": "^2.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user