|
|
|
@@ -12,8 +12,6 @@
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
// TODO: IMPORTANT... links aren't showing previews on Bsky
|
|
|
|
|
|
|
|
|
|
import "dotenv/config";
|
|
|
|
|
import { appendFileSync, existsSync, readFileSync, unlinkSync, writeFileSync, createWriteStream } from 'fs';
|
|
|
|
|
import { finished } from 'stream/promises';
|
|
|
|
@@ -90,16 +88,12 @@ if (existsSync(historyFile)){
|
|
|
|
|
history += readFileSync(historyFile, 'UTF-8').split('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bskyPost = async (text, media = []) => {
|
|
|
|
|
const bskyPost = async (text, postUrl, media = []) => {
|
|
|
|
|
let uploadedMedia = [];
|
|
|
|
|
for (let m of media){
|
|
|
|
|
// let mime = `${m.url}`.split('.').pop();
|
|
|
|
|
// mime = mime.toLowerCase();
|
|
|
|
|
// mime = mime === 'jpg'?'jpeg':mime;
|
|
|
|
|
const fileBuffer = Buffer.from(readFileSync(m.data));
|
|
|
|
|
const { ext, mimeT } = await fileTypeFromBuffer(fileBuffer);
|
|
|
|
|
let uploadResult = await bsky.uploadBlob(fileBuffer, {
|
|
|
|
|
// encoding: `image/${mime}`
|
|
|
|
|
encoding: mimeT
|
|
|
|
|
});
|
|
|
|
|
if (uploadResult.success){
|
|
|
|
@@ -126,6 +120,16 @@ const bskyPost = async (text, media = []) => {
|
|
|
|
|
"$type": "app.bsky.embed.images",
|
|
|
|
|
images: uploadedMedia
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// set embed to mastodon post
|
|
|
|
|
post.embed = {
|
|
|
|
|
"$type": "app.bsky.embed.external",
|
|
|
|
|
external: {
|
|
|
|
|
uri: postUrl,
|
|
|
|
|
title: `Post from @${process.env.MASTODON_USER}@${process.env.MASTODON_INSTANCE.substring(8)}`,
|
|
|
|
|
description: text
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log(JSON.stringify(post));
|
|
|
|
|
let bskyPostData = await bsky.post(post);
|
|
|
|
@@ -167,7 +171,7 @@ client.get(`/accounts/${process.env.MASTODON_ID}/statuses`, {
|
|
|
|
|
});
|
|
|
|
|
if (status.mentions > 0 && status.in_reply_to_id !== null){
|
|
|
|
|
// Post is a reply
|
|
|
|
|
// TODO: This isn't working yet
|
|
|
|
|
// TODO: This isn't working yet
|
|
|
|
|
const replyTo = [...status.mentions].filter((mention) => mention.id === status.in_reply_to_account_id);
|
|
|
|
|
if (replyTo.length > 0){
|
|
|
|
|
text = `Reply to: ${replyTo[0].url}/@${replyTo[0].acct}/${status.in_reply_to_id}\n${text}`;
|
|
|
|
@@ -189,7 +193,7 @@ client.get(`/accounts/${process.env.MASTODON_ID}/statuses`, {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bskyPost(text, medias);
|
|
|
|
|
bskyPost(text, status.url, medias);
|
|
|
|
|
appendFileSync(historyFile, `\n${status.id}`);
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`ERROR: ${status.url} is too long and unable to be reposted`);
|
|
|
|
@@ -197,7 +201,7 @@ client.get(`/accounts/${process.env.MASTODON_ID}/statuses`, {
|
|
|
|
|
}else{
|
|
|
|
|
// is boosted post
|
|
|
|
|
let text = status.reblog.url;
|
|
|
|
|
bskyPost(text, []);
|
|
|
|
|
bskyPost(text, status.url, []);
|
|
|
|
|
appendFileSync(historyFile, `\n${status.id}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|