data endpoint for entity 90008 (aka. a website)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

use correct client with correct pds for fetching user posts

dawn 86593fda d3c91026

+24 -14
+16 -10
eunomia/src/lib/bluesky.ts
··· 11 11 const constellationClient = new Client({ 12 12 handler: simpleFetchHandler({ service: 'https://constellation.microcosm.blue' }) 13 13 }); 14 - const bskyClient = writable<null | Client>(null); 14 + const userClient = new Client({ 15 + handler: simpleFetchHandler({ service: 'https://zwsp.xyz' }) 16 + }); 17 + const guestbookClient = writable<null | Client>(null); 15 18 16 19 export type Post = { 17 20 record: AppBskyFeedPost.Main; 18 21 uri: CanonicalResourceUri; 19 22 }; 20 23 21 - export const getBskyClient = async () => { 24 + export const getGuestbookClient = async () => { 22 25 try { 23 - let client = get(bskyClient); 26 + let client = get(guestbookClient); 24 27 if (client === null) { 25 28 client = await loginToBsky(); 26 - bskyClient.set(client); 29 + guestbookClient.set(client); 27 30 } 28 31 return client; 29 32 } catch (e) { ··· 42 45 return rpc; 43 46 }; 44 47 45 - export const getUserPosts = async (repo: Did, count: number = 10, cursor?: string) => { 46 - const client = await getBskyClient(); 48 + export const getUserPosts = async ( 49 + client: Client, 50 + repo: Did, 51 + count: number = 10, 52 + cursor?: string 53 + ) => { 47 54 const posts: Post[] = []; 48 55 // fetch requested amount of posts 49 56 while (posts.length < count - 1) { 50 57 const fetched = ok( 51 58 await client.get('com.atproto.repo.listRecords', { 52 - params: { repo, collection: 'app.bsky.feed.post', cursor } 59 + params: { repo, collection: 'app.bsky.feed.post', cursor, limit: count } 53 60 }) 54 61 ); 55 62 for (const record of fetched.records) { ··· 72 79 73 80 export const updateLastPosts = async () => { 74 81 try { 75 - const { posts } = await getUserPosts('did:plc:dfl62fgb7wtjj3fcbb72naae', 10); 82 + const { posts } = await getUserPosts(userClient, 'did:plc:dfl62fgb7wtjj3fcbb72naae', 10); 76 83 lastPosts.set(posts); 77 84 } catch (err) { 78 85 console.log(`can't update last posts ${err}`); ··· 83 90 return get(lastPosts); 84 91 }; 85 92 86 - export const getReplies = async (postUri: CanonicalResourceUri, forDid?: Did) => { 87 - const client = await getBskyClient(); 93 + export const getReplies = async (client: Client, postUri: CanonicalResourceUri, forDid?: Did) => { 88 94 // todo: do cursor stuff here later if it matters 89 95 const backlinks = ok( 90 96 await constellationClient.get('blue.microcosm.links.getBacklinks', {
+8 -4
eunomia/src/routes/(site)/guestbook/+page.server.ts
··· 2 2 import { scopeCookies as _scopeCookies, fancyText } from '$lib'; 3 3 import { RetryAfterRateLimiter } from 'sveltekit-rate-limiter/server'; 4 4 import { PUBLIC_BASE_URL } from '$env/static/public'; 5 - import { getBskyClient, getReplies, getUserPosts, IDENTIFIER } from '$lib/bluesky.js'; 5 + import { getGuestbookClient, getReplies, getUserPosts, IDENTIFIER } from '$lib/bluesky.js'; 6 6 import { getVisitorId } from '$lib/visits'; 7 7 import { nanoid } from 'nanoid'; 8 8 import { noteFromBskyPost, type NoteData } from '$components/note.svelte'; ··· 31 31 32 32 export const _fetchEntries = async () => { 33 33 const newEntries: NoteData[] = []; 34 - const { posts } = await getUserPosts(IDENTIFIER, 14); 34 + const { posts } = await getUserPosts(await getGuestbookClient(), IDENTIFIER, 14); 35 35 const fetchPostReplies = async (post: Post) => { 36 - const replies = await getReplies(post.uri, 'did:plc:dfl62fgb7wtjj3fcbb72naae'); 36 + const replies = await getReplies( 37 + await getGuestbookClient(), 38 + post.uri, 39 + 'did:plc:dfl62fgb7wtjj3fcbb72naae' 40 + ); 37 41 return { post, replies }; 38 42 }; 39 43 const postsWithReplies = await Promise.all(posts.map(fetchPostReplies)); ··· 122 126 redirect(303, callbackUrl); 123 127 } 124 128 // post to guestbook account 125 - const client = await getBskyClient(); 129 + const client = await getGuestbookClient(); 126 130 const post: AppBskyFeedPost.Main = { 127 131 $type: 'app.bsky.feed.post', 128 132 createdAt: new Date().toUTCString(),