(calendar) fix bluesky bot uploading an empty stream

This commit is contained in:
Andrea Vos 2025-01-19 15:34:54 +01:00
parent 18ffa6dedd
commit 423cc9fb83

View File

@ -31,6 +31,7 @@ const publishers = {
return tweetResponse.id_str;
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
},
@ -50,6 +51,7 @@ const publishers = {
console.log(mediaResponse);
mediaIds.push(mediaResponse.data.id);
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
}
@ -65,6 +67,7 @@ const publishers = {
console.log(tweetResponse.data);
return tweetResponse.data.id;
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
},
@ -82,6 +85,7 @@ const publishers = {
console.log(uploadResponse);
media.push(uploadResponse.data.blob);
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
}
@ -117,6 +121,7 @@ const publishers = {
cid: postResponse.cid,
};
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
},
@ -146,16 +151,18 @@ const lastPostId = {};
}
fs.writeFileSync(imageTmpPath, Buffer.from(await (await fetch(image)).arrayBuffer()), { encoding: 'binary' });
let imageStream = null;
try {
imageStream = fs.createReadStream(imageTmpPath);
} catch {}
for (const publisher of process.argv[3].split(',')) {
if (!publisher) {
continue;
}
console.log(`Publishing: ${publisher}`);
let imageStream = null;
try {
imageStream = fs.createReadStream(imageTmpPath);
} catch {}
const postId = await publishers[publisher](
message,
imageStream,
@ -170,6 +177,7 @@ const lastPostId = {};
lastPostId[publisher] = postId;
}
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
}