import { AppBskyFeedDefs } from "@atcute/bluesky"; import { AtURI, DID } from "./atproto.ts"; import * as Constellation from "./constellation.ts"; import { getUriRecord } from "./slingshot.ts"; import { DocProxy } from "./caching.ts"; export type FeedResponse = { feed: AppBskyFeedDefs.FeedViewPost[]; cursor: string; }; // https://bsky.app/profile/essem.space/feed/non-bsky-pds const partMap: Map = new Map([ ["feed", "app.bsky.feed.generator"], ["post", "app.bsky.feed.post"], ["lists", "app.bsky.graph.list"], ]); /** Converts social-app links to {@link AtURI}s */ export async function SocialAppToURI(link: string, resolve: boolean = false): Promise { const url = new URL(link); const parts = url.pathname.split("/").splice(1); console.log(parts); let id = parts[1]; if (resolve) { id = (await DocProxy.get(id)).handle; } if (parts[0] == "profile" && parts.length >= 2) { if (parts.length == 2) return new AtURI(id); if (parts.length == 4) return new AtURI(id, partMap.get(parts[2])!, parts[3]); } if (parts[0] == "starter-pack" && parts.length == 3) return new AtURI(id, "app.bsky.graph.starterpack", parts[2]); throw new Error("URL provided is not under /profile nor /starter-pack"); } export type List = { name: string; purpose: string; createdAt: Date; }; export type ListItem = { list: AtURI; subject: DID; createdAt: Date; }; export async function GetListItems(list: AtURI) { return (await Promise.all((await Constellation.getLinks(list.toString()!, "app.bsky.graph.listitem", ".list")) .map(async x=>await getUriRecord(x)))); }