this repo has no description

Backend frontend midend whatever its done

ari.express 76d83732 4f98a911

verified
Changed files
+43 -17
+43 -17
main.ts
··· 10 10 avatarCid: string | null; 11 11 } 12 12 class Post { 13 + authorDid: string; 13 14 text: string; 14 15 timestamp: number; 16 + timenotstamp: string; 15 17 quotingDid: string | null; 16 18 replyingDid: string | null; 17 19 imagesLinksCid: string[] | null; 18 20 videosLinkCid: string | null; 19 - constructor(record : ComAtprotoRepoListRecords.Record) { 21 + 22 + constructor(record: ComAtprotoRepoListRecords.Record, did: string) { 23 + this.authorDid = did; 20 24 const post = record.value as AppBskyFeedPost.Record; 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 - this.imagesLinksCid = post.embed.images.map ((imageRecord) => imageRecord.image.ref.$link); 38 + this.imagesLinksCid = post.embed.images.map((imageRecord) => 39 + imageRecord.image.ref.$link 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 - this.imagesLinksCid = post.embed.media.images.map ((imageRecord) => imageRecord.image.ref.$link); 52 + this.imagesLinksCid = post.embed.media.images.map((imageRecord) => 53 + imageRecord.image.ref.$link 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 - 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 - } 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 + }; 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 - limit: 5 114 - } 122 + limit: 5, 123 + }, 115 124 }); 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")); 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());