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