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
10
avatarCid: string | null;
11
11
}
12
12
class Post {
13
13
+
authorDid: string;
13
14
text: string;
14
15
timestamp: number;
16
16
+
timenotstamp: string;
15
17
quotingDid: string | null;
16
18
replyingDid: string | null;
17
19
imagesLinksCid: string[] | null;
18
20
videosLinkCid: string | null;
19
19
-
constructor(record : ComAtprotoRepoListRecords.Record) {
21
21
+
22
22
+
constructor(record: ComAtprotoRepoListRecords.Record, did: string) {
23
23
+
this.authorDid = did;
20
24
const post = record.value as AppBskyFeedPost.Record;
25
25
+
this.timenotstamp = post.createdAt;
21
26
this.text = post.text;
22
27
this.timestamp = Date.parse(post.createdAt);
23
28
if (post.reply) {
···
30
35
this.videosLinkCid = null;
31
36
switch (post.embed?.$type) {
32
37
case "app.bsky.embed.images":
33
33
-
this.imagesLinksCid = post.embed.images.map ((imageRecord) => imageRecord.image.ref.$link);
38
38
+
this.imagesLinksCid = post.embed.images.map((imageRecord) =>
39
39
+
imageRecord.image.ref.$link
40
40
+
);
34
41
break;
35
42
case "app.bsky.embed.video":
36
43
this.videosLinkCid = post.embed.video.ref.$link;
···
42
49
this.quotingDid = didFromATuri(post.embed.record.record.uri).repo;
43
50
switch (post.embed.media.$type) {
44
51
case "app.bsky.embed.images":
45
45
-
this.imagesLinksCid = post.embed.media.images.map ((imageRecord) => imageRecord.image.ref.$link);
52
52
+
this.imagesLinksCid = post.embed.media.images.map((imageRecord) =>
53
53
+
imageRecord.image.ref.$link
54
54
+
);
46
55
break;
47
56
case "app.bsky.embed.video":
48
57
this.videosLinkCid = post.embed.media.video.ref.$link;
···
53
62
}
54
63
}
55
64
56
56
-
const didFromATuri = (aturi : string) => {
57
57
-
const parts = aturi.split('/');
58
58
-
return {
59
59
-
repo: parts[2],
60
60
-
collection: parts[3],
61
61
-
rkey: parts[4]
62
62
-
};
63
63
-
}
65
65
+
const didFromATuri = (aturi: string) => {
66
66
+
const parts = aturi.split("/");
67
67
+
return {
68
68
+
repo: parts[2],
69
69
+
collection: parts[3],
70
70
+
rkey: parts[4],
71
71
+
};
72
72
+
};
64
73
65
74
const rpc = new XRPC({
66
75
handler: simpleFetchHandler({
···
110
119
params: {
111
120
repo: did,
112
121
collection: "app.bsky.feed.post",
113
113
-
limit: 5
114
114
-
}
122
122
+
limit: 5,
123
123
+
},
115
124
});
116
116
-
return data.records as ComAtprotoRepoListRecords.Record[];
117
117
-
}
118
118
-
// console.log((await fetchPosts("did:web:astrra.space")).map((record : any) => new Post(record)))
119
119
-
console.log(await getAccountMetadata("did:web:astrra.space"));
125
125
+
return {
126
126
+
records: data.records as ComAtprotoRepoListRecords.Record[],
127
127
+
did: did,
128
128
+
};
129
129
+
};
130
130
+
131
131
+
const fetchAllPosts = async () => {
132
132
+
const users: AccountMetadata[] = await getAllMetadataFromPds();
133
133
+
const postRecords = await Promise.all(
134
134
+
users.map(async (metadata: AccountMetadata) =>
135
135
+
await fetchPosts(metadata.did)
136
136
+
),
137
137
+
);
138
138
+
const posts : Post[] = postRecords.flatMap((userFetch) =>
139
139
+
userFetch.records.map((record) => new Post(record, userFetch.did))
140
140
+
);
141
141
+
posts.sort((a, b) => b.timestamp - a.timestamp);
142
142
+
return posts;
143
143
+
};
144
144
+
145
145
+
console.log(await fetchAllPosts());