Skip to content

Commit

Permalink
feat: link replacements for bluesky (#147)
Browse files Browse the repository at this point in the history
* utilizes VixBluesky

* supports normal URLS + did:pic urls (see AT URI scheme)

* closes #142
  • Loading branch information
RalphORama authored Oct 29, 2024
1 parent 02f4ec4 commit 6012f14
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ alternatives that support rich media embeds.

LinkFix currently supports:
- Twitter/X (Tweet embeds via [fxtwitter](https://github.com/FixTweet/FixTweet))
- BlueSky/bsky via [vixbluesky](https://github.com/Rapougnac/VixBluesky)
- TikTok (video embeds via [vxtiktok](https://github.com/dylanpdx/vxtiktok))
- Instagram (image, video, and reel embeds via [ddinstagram](https://github.com/Wikidepia/InstaFix))
- Reddit (text, image, and video embeds via [vxreddit](https://github.com/dylanpdx/vxReddit))
Expand Down
1 change: 1 addition & 0 deletions docker-compose.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ services:
- TIKTOK_FIX_URL=vxtiktok.com
- TWITTER_FIX_URL=fxtwitter.com
- YOUTUBE_FIX_URL=youtu.be
- BSKY_FIX_URL=bskyx.app
15 changes: 15 additions & 0 deletions src/replacements/BskyReplacement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import BaseReplacement from "./BaseReplacement";

export default class BskyReplacement extends BaseReplacement {
constructor(newDomain: string) {
super(
newDomain,
// plc is 24 chars
// https://github.com/did-method-plc/did-method-plc?tab=readme-ov-file#identifier-syntax
// TID length is always 13 ASCII characters
// https://atproto.com/specs/record-key#record-key-type-tid
/https?:\/\/bsky\.app\/profile\/((\w|\.|-)+|(did:plc:[234567a-z]{24}))\/post\/[234567a-z]{13}(?!\/)/g,
/bsky\.app\//,
);
}
}
10 changes: 10 additions & 0 deletions src/replacements/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BskyReplacement from "./BskyReplacement";
import InstagramReplacement from "./InstagramReplacement";
import PixivReplacement from "./PixivReplacement";
import RedditMediaReplacement from "./RedditMediaReplacement";
Expand All @@ -6,6 +7,9 @@ import TikTokReplacement from "./TikTokReplacement";
import TwitterReplacement from "./TwitterReplacement";
import YouTubeReplacement from "./YouTubeReplacement";

const bskyReplacer = process.env.BSKY_FIX_URL
? new BskyReplacement(process.env.BSKY_FIX_URL)
: undefined;
const instagramReplacer = process.env.INSTAGRAM_FIX_URL
? new InstagramReplacement(process.env.INSTAGRAM_FIX_URL)
: undefined;
Expand Down Expand Up @@ -64,4 +68,10 @@ export const replacements: {
(messageContent) => {
return pixivReplacer ? pixivReplacer.replaceURLs(messageContent) : null;
},
// TID length is always 13 ASCII characters
// https://atproto.com/specs/record-key#record-key-type-tid
"\\/\\/bsky\\.app\\/profile\\/((\\w|\\.|-)+|(did:plc:[234567a-z]{24}))\\/post\\/[234567a-z]{13}(?!\\/)":
(messageContent) => {
return bskyReplacer ? bskyReplacer.replaceURLs(messageContent) : null;
},
};

0 comments on commit 6012f14

Please sign in to comment.