Read-it-later social network
1// --- UTILITIES ---
2export function parseAtUri(uri: string) {
3 const regex = /at:\/\/(?<did>did.*)\/(?<lexi>.*)\/(?<rkey>.*)/;
4 const groups = regex.exec(uri)?.groups;
5 return {
6 did: groups?.did,
7 lexi: groups?.lexi,
8 rkey: groups?.rkey
9 }
10}
11
12export function createAtUri({ did, collection, rkey }: { did: string, collection: string, rkey: string }) {
13 if (did && collection && rkey) {
14 return `at://${did}/${collection}/${rkey}`;
15 }
16 return undefined;
17}
18
19export type MiniDoc = {
20 did: string;
21 handle: string;
22 pds: string;
23 signing_key: string;
24}
25
26export async function resolveHandle(handle: string) {
27 const result = await fetch(`https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc?identifier=${encodeURIComponent(handle)}`)
28 const info = await result.json();
29 return info as MiniDoc;
30}
31
32export type Node = {
33 uri: string;
34 cid: string;
35 did: string;
36 indexedAt: string;
37 actorHandle: string;
38}
39
40export type ATBlob = {
41 $type: string;
42 ref: string;
43 mimeType: string;
44 size: number;
45}
46
47export type StandardSiteThemeColorRGB = {
48 $type: "site.standard.theme.color#rgb",
49 b: number;
50 g: number;
51 r: number;
52}
53
54export type PublicationNode = Node & {
55 url: string;
56 name: string;
57 description: string;
58 icon?: ATBlob;
59 preferences?: {
60 showInDiscover?: boolean;
61 hideProfile?: boolean;
62 };
63 basicTheme?: {
64 $type: "site.standard.theme.basic",
65 background: StandardSiteThemeColorRGB;
66 foreground: StandardSiteThemeColorRGB;
67 accent: StandardSiteThemeColorRGB;
68 accentForeground: StandardSiteThemeColorRGB;
69 };
70}
71
72export type SubscriptionNode = Node & {
73 publication: string;
74}
75
76export type DocumentNode = Node & { value: {
77 title: string;
78 site: string;
79 publishedAt: string;
80 path?: string;
81 content?: string;
82 bskyPostRef?: string;
83 description?: string;
84 textContent?: string;
85 tags?: string[];
86 updatedAt?: string;
87}}
88
89export const defaultTheme = {
90 $type: "site.standard.theme.basic",
91 background: {
92 $type: "site.standard.theme.color#rgb",
93 b: 255,
94 g: 255,
95 r: 255
96 },
97 accentForeground: {
98 $type: "site.standard.theme.color#rgb",
99 b: 0,
100 g: 0,
101 r: 0,
102 },
103 foreground: {
104 $type: "site.standard.theme.color#rgb",
105 b: 0,
106 g: 0,
107 r: 0
108 },
109 accent: {
110 $type: "site.standard.theme.color#rgb",
111 b: 36,
112 g: 191,
113 r: 251
114 },
115}