Backend frontend midend whatever its done
This commit is contained in:
parent
4f98a911ce
commit
76d837320d
1 changed files with 43 additions and 17 deletions
50
main.ts
50
main.ts
|
@ -10,14 +10,19 @@ interface AccountMetadata {
|
||||||
avatarCid: string | null;
|
avatarCid: string | null;
|
||||||
}
|
}
|
||||||
class Post {
|
class Post {
|
||||||
|
authorDid: string;
|
||||||
text: string;
|
text: string;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
|
timenotstamp: string;
|
||||||
quotingDid: string | null;
|
quotingDid: string | null;
|
||||||
replyingDid: string | null;
|
replyingDid: string | null;
|
||||||
imagesLinksCid: string[] | null;
|
imagesLinksCid: string[] | null;
|
||||||
videosLinkCid: string | null;
|
videosLinkCid: string | null;
|
||||||
constructor(record : ComAtprotoRepoListRecords.Record) {
|
|
||||||
|
constructor(record: ComAtprotoRepoListRecords.Record, did: string) {
|
||||||
|
this.authorDid = did;
|
||||||
const post = record.value as AppBskyFeedPost.Record;
|
const post = record.value as AppBskyFeedPost.Record;
|
||||||
|
this.timenotstamp = post.createdAt;
|
||||||
this.text = post.text;
|
this.text = post.text;
|
||||||
this.timestamp = Date.parse(post.createdAt);
|
this.timestamp = Date.parse(post.createdAt);
|
||||||
if (post.reply) {
|
if (post.reply) {
|
||||||
|
@ -30,7 +35,9 @@ class Post {
|
||||||
this.videosLinkCid = null;
|
this.videosLinkCid = null;
|
||||||
switch (post.embed?.$type) {
|
switch (post.embed?.$type) {
|
||||||
case "app.bsky.embed.images":
|
case "app.bsky.embed.images":
|
||||||
this.imagesLinksCid = post.embed.images.map ((imageRecord) => imageRecord.image.ref.$link);
|
this.imagesLinksCid = post.embed.images.map((imageRecord) =>
|
||||||
|
imageRecord.image.ref.$link
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "app.bsky.embed.video":
|
case "app.bsky.embed.video":
|
||||||
this.videosLinkCid = post.embed.video.ref.$link;
|
this.videosLinkCid = post.embed.video.ref.$link;
|
||||||
|
@ -42,7 +49,9 @@ class Post {
|
||||||
this.quotingDid = didFromATuri(post.embed.record.record.uri).repo;
|
this.quotingDid = didFromATuri(post.embed.record.record.uri).repo;
|
||||||
switch (post.embed.media.$type) {
|
switch (post.embed.media.$type) {
|
||||||
case "app.bsky.embed.images":
|
case "app.bsky.embed.images":
|
||||||
this.imagesLinksCid = post.embed.media.images.map ((imageRecord) => imageRecord.image.ref.$link);
|
this.imagesLinksCid = post.embed.media.images.map((imageRecord) =>
|
||||||
|
imageRecord.image.ref.$link
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "app.bsky.embed.video":
|
case "app.bsky.embed.video":
|
||||||
this.videosLinkCid = post.embed.media.video.ref.$link;
|
this.videosLinkCid = post.embed.media.video.ref.$link;
|
||||||
|
@ -54,13 +63,13 @@ class Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
const didFromATuri = (aturi: string) => {
|
const didFromATuri = (aturi: string) => {
|
||||||
const parts = aturi.split('/');
|
const parts = aturi.split("/");
|
||||||
return {
|
return {
|
||||||
repo: parts[2],
|
repo: parts[2],
|
||||||
collection: parts[3],
|
collection: parts[3],
|
||||||
rkey: parts[4]
|
rkey: parts[4],
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const rpc = new XRPC({
|
const rpc = new XRPC({
|
||||||
handler: simpleFetchHandler({
|
handler: simpleFetchHandler({
|
||||||
|
@ -110,10 +119,27 @@ const fetchPosts = async (did: string) => {
|
||||||
params: {
|
params: {
|
||||||
repo: did,
|
repo: did,
|
||||||
collection: "app.bsky.feed.post",
|
collection: "app.bsky.feed.post",
|
||||||
limit: 5
|
limit: 5,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
return data.records as ComAtprotoRepoListRecords.Record[];
|
return {
|
||||||
}
|
records: data.records as ComAtprotoRepoListRecords.Record[],
|
||||||
// console.log((await fetchPosts("did:web:astrra.space")).map((record : any) => new Post(record)))
|
did: did,
|
||||||
console.log(await getAccountMetadata("did:web:astrra.space"));
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchAllPosts = async () => {
|
||||||
|
const users: AccountMetadata[] = await getAllMetadataFromPds();
|
||||||
|
const postRecords = await Promise.all(
|
||||||
|
users.map(async (metadata: AccountMetadata) =>
|
||||||
|
await fetchPosts(metadata.did)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const posts : Post[] = postRecords.flatMap((userFetch) =>
|
||||||
|
userFetch.records.map((record) => new Post(record, userFetch.did))
|
||||||
|
);
|
||||||
|
posts.sort((a, b) => b.timestamp - a.timestamp);
|
||||||
|
return posts;
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(await fetchAllPosts());
|
Loading…
Add table
Add a link
Reference in a new issue