tangled
alpha
login
or
join now
baileytownsend.dev
/
pds-dash-fork
16
fork
atom
A fork of pds-dash for selfhosted.social
16
fork
atom
overview
issues
pulls
pipelines
Backend frontend midend whatever its done
ari.express
11 months ago
76d83732
4f98a911
verified
This commit was signed with the committer's
known signature
.
ari.express
SSH Key Fingerprint:
SHA256:j4xpQafvRcIH4rwZqM5aREIogWsCjyYohia7vH0+uZY=
+43
-17
1 changed file
expand all
collapse all
unified
split
main.ts
+43
-17
main.ts
···
10
avatarCid: string | null;
11
}
12
class Post {
0
13
text: string;
14
timestamp: number;
0
15
quotingDid: string | null;
16
replyingDid: string | null;
17
imagesLinksCid: string[] | null;
18
videosLinkCid: string | null;
19
-
constructor(record : ComAtprotoRepoListRecords.Record) {
0
0
20
const post = record.value as AppBskyFeedPost.Record;
0
21
this.text = post.text;
22
this.timestamp = Date.parse(post.createdAt);
23
if (post.reply) {
···
30
this.videosLinkCid = null;
31
switch (post.embed?.$type) {
32
case "app.bsky.embed.images":
33
-
this.imagesLinksCid = post.embed.images.map ((imageRecord) => imageRecord.image.ref.$link);
0
0
34
break;
35
case "app.bsky.embed.video":
36
this.videosLinkCid = post.embed.video.ref.$link;
···
42
this.quotingDid = didFromATuri(post.embed.record.record.uri).repo;
43
switch (post.embed.media.$type) {
44
case "app.bsky.embed.images":
45
-
this.imagesLinksCid = post.embed.media.images.map ((imageRecord) => imageRecord.image.ref.$link);
0
0
46
break;
47
case "app.bsky.embed.video":
48
this.videosLinkCid = post.embed.media.video.ref.$link;
···
53
}
54
}
55
56
-
const didFromATuri = (aturi : string) => {
57
-
const parts = aturi.split('/');
58
-
return {
59
-
repo: parts[2],
60
-
collection: parts[3],
61
-
rkey: parts[4]
62
-
};
63
-
}
64
65
const rpc = new XRPC({
66
handler: simpleFetchHandler({
···
110
params: {
111
repo: did,
112
collection: "app.bsky.feed.post",
113
-
limit: 5
114
-
}
115
});
116
-
return data.records as ComAtprotoRepoListRecords.Record[];
117
-
}
118
-
// console.log((await fetchPosts("did:web:astrra.space")).map((record : any) => new Post(record)))
119
-
console.log(await getAccountMetadata("did:web:astrra.space"));
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
···
10
avatarCid: string | null;
11
}
12
class Post {
13
+
authorDid: string;
14
text: string;
15
timestamp: number;
16
+
timenotstamp: string;
17
quotingDid: string | null;
18
replyingDid: string | null;
19
imagesLinksCid: string[] | null;
20
videosLinkCid: string | null;
21
+
22
+
constructor(record: ComAtprotoRepoListRecords.Record, did: string) {
23
+
this.authorDid = did;
24
const post = record.value as AppBskyFeedPost.Record;
25
+
this.timenotstamp = post.createdAt;
26
this.text = post.text;
27
this.timestamp = Date.parse(post.createdAt);
28
if (post.reply) {
···
35
this.videosLinkCid = null;
36
switch (post.embed?.$type) {
37
case "app.bsky.embed.images":
38
+
this.imagesLinksCid = post.embed.images.map((imageRecord) =>
39
+
imageRecord.image.ref.$link
40
+
);
41
break;
42
case "app.bsky.embed.video":
43
this.videosLinkCid = post.embed.video.ref.$link;
···
49
this.quotingDid = didFromATuri(post.embed.record.record.uri).repo;
50
switch (post.embed.media.$type) {
51
case "app.bsky.embed.images":
52
+
this.imagesLinksCid = post.embed.media.images.map((imageRecord) =>
53
+
imageRecord.image.ref.$link
54
+
);
55
break;
56
case "app.bsky.embed.video":
57
this.videosLinkCid = post.embed.media.video.ref.$link;
···
62
}
63
}
64
65
+
const didFromATuri = (aturi: string) => {
66
+
const parts = aturi.split("/");
67
+
return {
68
+
repo: parts[2],
69
+
collection: parts[3],
70
+
rkey: parts[4],
71
+
};
72
+
};
73
74
const rpc = new XRPC({
75
handler: simpleFetchHandler({
···
119
params: {
120
repo: did,
121
collection: "app.bsky.feed.post",
122
+
limit: 5,
123
+
},
124
});
125
+
return {
126
+
records: data.records as ComAtprotoRepoListRecords.Record[],
127
+
did: did,
128
+
};
129
+
};
130
+
131
+
const fetchAllPosts = async () => {
132
+
const users: AccountMetadata[] = await getAllMetadataFromPds();
133
+
const postRecords = await Promise.all(
134
+
users.map(async (metadata: AccountMetadata) =>
135
+
await fetchPosts(metadata.did)
136
+
),
137
+
);
138
+
const posts : Post[] = postRecords.flatMap((userFetch) =>
139
+
userFetch.records.map((record) => new Post(record, userFetch.did))
140
+
);
141
+
posts.sort((a, b) => b.timestamp - a.timestamp);
142
+
return posts;
143
+
};
144
+
145
+
console.log(await fetchAllPosts());