Compare commits
No commits in common. "d9201697cfdee5be34e88e6a1bc4610dbc061d8a" and "338f7fe79c57284b4dd6a401517c7558dcb81f4b" have entirely different histories.
d9201697cf
...
338f7fe79c
@ -12,7 +12,3 @@ Don't forget to install dependencies with `npm i` and adjust the config by copyi
|
|||||||
Get the mastodon credentials from going to user preferences > development > and creating a new application.
|
Get the mastodon credentials from going to user preferences > development > and creating a new application.
|
||||||
For bluesky credentials you have to make a new app password under settings > privacy and security > app passwords.
|
For bluesky credentials you have to make a new app password under settings > privacy and security > app passwords.
|
||||||
This should ideally be run from a cron job (specifically `run.sh`), but can be run with just `node index.js`.
|
This should ideally be run from a cron job (specifically `run.sh`), but can be run with just `node index.js`.
|
||||||
|
|
||||||
## ToDo List
|
|
||||||
|
|
||||||
* Cleanup code
|
|
||||||
|
20
index.mjs
20
index.mjs
@ -90,12 +90,16 @@ if (existsSync(historyFile)){
|
|||||||
history += readFileSync(historyFile, 'UTF-8').split('\n');
|
history += readFileSync(historyFile, 'UTF-8').split('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
const bskyPost = async (text, postUrl, media = []) => {
|
const bskyPost = async (text, media = []) => {
|
||||||
let uploadedMedia = [];
|
let uploadedMedia = [];
|
||||||
for (let m of media){
|
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 fileBuffer = Buffer.from(readFileSync(m.data));
|
||||||
const { ext, mimeT } = await fileTypeFromBuffer(fileBuffer);
|
const { ext, mimeT } = await fileTypeFromBuffer(fileBuffer);
|
||||||
let uploadResult = await bsky.uploadBlob(fileBuffer, {
|
let uploadResult = await bsky.uploadBlob(fileBuffer, {
|
||||||
|
// encoding: `image/${mime}`
|
||||||
encoding: mimeT
|
encoding: mimeT
|
||||||
});
|
});
|
||||||
if (uploadResult.success){
|
if (uploadResult.success){
|
||||||
@ -122,16 +126,6 @@ const bskyPost = async (text, postUrl, media = []) => {
|
|||||||
"$type": "app.bsky.embed.images",
|
"$type": "app.bsky.embed.images",
|
||||||
images: uploadedMedia
|
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));
|
console.log(JSON.stringify(post));
|
||||||
let bskyPostData = await bsky.post(post);
|
let bskyPostData = await bsky.post(post);
|
||||||
@ -195,7 +189,7 @@ client.get(`/accounts/${process.env.MASTODON_ID}/statuses`, {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bskyPost(text, status.url, medias);
|
bskyPost(text, medias);
|
||||||
appendFileSync(historyFile, `\n${status.id}`);
|
appendFileSync(historyFile, `\n${status.id}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`ERROR: ${status.url} is too long and unable to be reposted`);
|
console.log(`ERROR: ${status.url} is too long and unable to be reposted`);
|
||||||
@ -203,7 +197,7 @@ client.get(`/accounts/${process.env.MASTODON_ID}/statuses`, {
|
|||||||
}else{
|
}else{
|
||||||
// is boosted post
|
// is boosted post
|
||||||
let text = status.reblog.url;
|
let text = status.reblog.url;
|
||||||
bskyPost(text, status.url, []);
|
bskyPost(text, []);
|
||||||
appendFileSync(historyFile, `\n${status.id}`);
|
appendFileSync(historyFile, `\n${status.id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user