fixing published date check

This commit is contained in:
Michael (GP) 2022-12-12 20:25:59 -05:00
parent c79e1eb547
commit 35977508ac

34
bot.js
View File

@ -17,12 +17,12 @@ const download_image = async (url, image_path) => {
responseType: "stream", responseType: "stream",
}); });
return new Promise((resolve, reject) => { return new Promise((resolve, reject) =>
response.data response.data
.pipe(fs.createWriteStream(image_path)) .pipe(fs.createWriteStream(image_path))
.on("finish", () => resolve()) .on("finish", () => resolve(true))
.on("error", (e) => reject(e)); .on("error", (e) => reject(e))
}); );
}; };
(async () => { (async () => {
@ -36,8 +36,6 @@ const download_image = async (url, image_path) => {
async function postFeed() { async function postFeed() {
console.log("Running postFeed()"); console.log("Running postFeed()");
console.log("ACCESS KEY: ", process.env.MASTODON_ACCESS_KEY);
console.log("API URL: ", process.env.MASTODON_API_URL);
const M = new Mastodon({ const M = new Mastodon({
access_token: `${process.env.MASTODON_ACCESS_KEY}`, access_token: `${process.env.MASTODON_ACCESS_KEY}`,
timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests. timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests.
@ -69,18 +67,24 @@ async function postFeed() {
"images", "images",
`post-image-${currentCount}` `post-image-${currentCount}`
); );
await download_image(metadata.image, path); let isDownloaded = await download_image(metadata.image, path);
let mediaup = await M.post("media", { let rstream = fs.createReadStream(path);
file: fs.createReadStream(path), rstream.on("open", async (fd) => {
let mediaup = await M.post("media", {
file: rstream,
});
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;
}); });
rstream.on("error", (err) => {
await M.post("statuses", { // error on the stream
status: `${item.title}\n\n#NeoVibe #${process.env.POST_HASHTAG}\n\n${item.link}`,
media_ids: [mediaup.data.id],
}); });
return true;
} }
return true; return true;