https://domlink.deployments.hotsocket.fyi/
1import { AppBskyFeedDefs } from "@atcute/bluesky";
2import { AtURI, DID } from "./atproto.ts";
3import * as Constellation from "./constellation.ts";
4import { getUriRecord } from "./slingshot.ts";
5import { DocProxy } from "./caching.ts";
6
7export type FeedResponse = {
8 feed: AppBskyFeedDefs.FeedViewPost[];
9 cursor: string;
10};
11
12// https://bsky.app/profile/essem.space/feed/non-bsky-pds
13const partMap: Map<string, string> = new Map([
14 ["feed", "app.bsky.feed.generator"],
15 ["post", "app.bsky.feed.post"],
16 ["lists", "app.bsky.graph.list"],
17]);
18/** Converts social-app links to {@link AtURI}s */
19export async function SocialAppToURI(link: string, resolve: boolean = false): Promise<AtURI> {
20 const url = new URL(link);
21 const parts = url.pathname.split("/").splice(1);
22 console.log(parts);
23 let id = parts[1];
24 if (resolve) {
25 id = (await DocProxy.get(id)).handle;
26 }
27 if (parts[0] == "profile" && parts.length >= 2) {
28 if (parts.length == 2) return new AtURI(id);
29 if (parts.length == 4) return new AtURI(id, partMap.get(parts[2])!, parts[3]);
30 }
31 if (parts[0] == "starter-pack" && parts.length == 3) return new AtURI(id, "app.bsky.graph.starterpack", parts[2]);
32 throw new Error("URL provided is not under /profile nor /starter-pack");
33}
34
35export type List = {
36 name: string;
37 purpose: string;
38 createdAt: Date;
39};
40export type ListItem = {
41 list: AtURI;
42 subject: DID;
43 createdAt: Date;
44};
45export async function GetListItems(list: AtURI) {
46 return (await Promise.all((await Constellation.getLinks(list.toString()!, "app.bsky.graph.listitem", ".list"))
47 .map(async x=>await getUriRecord<ListItem>(x))));
48}