Multicolumn Bluesky client powered by Angular
at master 44 lines 1.6 kB view raw
1import {ExternalEmbed, RecordEmbed, RecordEmbedType} from "@models/embed"; 2import {URL_REGEX} from "@atproto/api"; 3 4export const BSKY_PROFILE_URL_RE = /\/profile\/([^\/]+)$/; 5export const BSKY_POST_URL_RE = /\/profile\/([^\/]+)\/post\/([^\/]+)$/; 6export const BSKY_FEED_URL_RE = /\/profile\/([^\/]+)\/feed\/([^\/]+)$/; 7export const BSKY_LIST_URL_RE = /\/profile\/([^\/]+)\/lists\/([^\/]+)$/; 8export const BSKY_STARTER_PACK_URL_RE = /\/starter-pack\/([^\/]+)\/([^\/]+)$/; 9 10export class EmbedUtils { 11 public static findEmbedSuggestions(text: string): Array<ExternalEmbed | RecordEmbed> { 12 const embeds: Array<ExternalEmbed | RecordEmbed> = []; 13 const matches = text.match(URL_REGEX) ?? []; 14 let split: RegExpExecArray | null; 15 16 matches.forEach(match => { 17 if (match.includes('bsky.app')) { 18 if ((split = BSKY_POST_URL_RE.exec(match))) { 19 embeds.push(new RecordEmbed(RecordEmbedType.POST, split[1], split[2])); 20 return; 21 } 22 if ((split = BSKY_FEED_URL_RE.exec(match))) { 23 embeds.push(new RecordEmbed(RecordEmbedType.FEED, split[1], split[2])); 24 return; 25 } 26 if ((split = BSKY_LIST_URL_RE.exec(match))) { 27 embeds.push(new RecordEmbed(RecordEmbedType.LIST, split[1], split[2])); 28 return; 29 } 30 if ((split = BSKY_STARTER_PACK_URL_RE.exec(match))) { 31 embeds.push(new RecordEmbed(RecordEmbedType.STARTER_PACK, split[1], split[2])); 32 return; 33 } 34 35 embeds.push(new ExternalEmbed(match)); 36 return; 37 } 38 39 embeds.push(new ExternalEmbed(match)); 40 }); 41 42 return embeds; 43 } 44}