diff --git a/main.js b/main.js index 728dcb1..8ef7406 100644 --- a/main.js +++ b/main.js @@ -1,8 +1,9 @@ require("dotenv").config(); const fs = require("fs"); const path = require("path"); -const { RichText, BskyAgent } = require("@atproto/api"); +const { RichText, AtpAgent } = require("@atproto/api"); const axios = require("axios"); +const he = require('he'); // Mastodon credentials const mastodonInstance = process.env.MASTODON_INSTANCE; @@ -10,7 +11,7 @@ const mastodonUser = process.env.MASTODON_USER; async function main() { // Bluesky agent - const agent = new BskyAgent({ service: process.env.BLUESKY_ENDPOINT }); + const agent = new AtpAgent({ service: process.env.BLUESKY_ENDPOINT }); const loginResponse = await agent.login({ identifier: process.env.BLUESKY_HANDLE, password: process.env.BLUESKY_PASSWORD, @@ -57,7 +58,8 @@ async function main() { } async function postToBluesky(textParts) { - const rootMessageResponse = await agent.post(await createBlueskyMessage(textParts[0])); + const blueskyMessage = await createBlueskyMessage(textParts[0]); + const rootMessageResponse = await agent.post(blueskyMessage); if (textParts.length === 1) return; @@ -73,8 +75,11 @@ async function main() { } } - function removeHtmlTags(input) { - return input.replace(/<[^>]*>/g, ""); + function sanitizeHtml(input) { + const withoutHtml = input.replace(/<[^>]*>/g, ""); + const decodeQuotes = he.decode(withoutHtml); + const addSpace = decodeQuotes.replace(/(https?:\/\/)/g, ' $1'); + return addSpace; } function splitText(text, maxLength) { @@ -127,7 +132,7 @@ async function main() { if (currentTimestampId > lastProcessedPostId && lastProcessedPostId != 0) { try { console.log('📧 posting to BlueSky', currentTimestampId) - const textParts = splitText(removeHtmlTags(item.object.content), 300); + const textParts = splitText(sanitizeHtml(item.object.content), 300); postToBluesky(textParts); } catch (error) { console.error('🔥 can\'t post to Bluesky', currentTimestampId, error) diff --git a/package-lock.json b/package-lock.json index 4e67a5f..0787077 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@semantic-release/git": "^10.0.1", "axios": "^1.7.7", "dotenv": "^16.4.5", + "he": "^1.2.0", "mastodon-api": "^1.3.0" } }, @@ -3097,6 +3098,14 @@ "node": ">= 0.4" } }, + "node_modules/he": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "bin": { + "he": "bin/he" + } + }, "node_modules/highlight.js": { "version": "10.7.3", "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz", diff --git a/package.json b/package.json index 67ef985..562d890 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@semantic-release/git": "^10.0.1", "axios": "^1.7.7", "dotenv": "^16.4.5", + "he": "^1.2.0", "mastodon-api": "^1.3.0" } }