your personal website on atproto - mirror blento.app

Merge pull request #109 from flo-bit/updated-blentos

updated blentos

authored by Florian and committed by GitHub 3cdc9f4b 78a9cec6

+52 -19
+31
src/lib/atproto/methods.ts
··· 101 return response.data; 102 } 103 104 /** 105 * Creates an AT Protocol client for a user's PDS. 106 * @param did - The DID of the user ··· 370 }; 371 }; 372 }) { 373 did ??= user.did; 374 375 return `https://cdn.bsky.app/img/feed_thumbnail/plain/${did}/${blob.ref.$link}@webp`;
··· 101 return response.data; 102 } 103 104 + export async function getBlentoOrBskyProfile(data: { did: Did; client?: Client }): Promise< 105 + Awaited<ReturnType<typeof getDetailedProfile>> & { 106 + hasBlento: boolean; 107 + } 108 + > { 109 + let blentoProfile; 110 + try { 111 + // try getting blento profile first 112 + blentoProfile = await getRecord({ 113 + collection: 'site.standard.publication', 114 + did: data?.did, 115 + rkey: 'blento.self', 116 + client: data?.client 117 + }); 118 + } catch { 119 + console.error('error getting blento profile, falling back to bsky profile'); 120 + } 121 + 122 + const response = await getDetailedProfile(data); 123 + 124 + return { 125 + did: data.did, 126 + handle: response?.handle, 127 + displayName: blentoProfile?.value?.name || response?.displayName || response?.handle, 128 + avatar: (getCDNImageBlobUrl({ did: data?.did, blob: blentoProfile?.value?.icon }) || 129 + response?.avatar) as `${string}:${string}`, 130 + hasBlento: Boolean(blentoProfile.value) 131 + }; 132 + } 133 + 134 /** 135 * Creates an AT Protocol client for a user's PDS. 136 * @param did - The DID of the user ··· 400 }; 401 }; 402 }) { 403 + if (!blob || !did) return; 404 did ??= user.did; 405 406 return `https://cdn.bsky.app/img/feed_thumbnail/plain/${did}/${blob.ref.$link}@webp`;
+1 -1
src/lib/atproto/settings.ts
··· 20 'app.blento.settings', 21 'app.blento.comment', 22 'app.blento.guestbook.entry', 23 - 'app.bsky.feed.post', 24 'site.standard.publication', 25 'site.standard.document', 26 'xyz.statusphere.status'
··· 20 'app.blento.settings', 21 'app.blento.comment', 22 'app.blento.guestbook.entry', 23 + 'app.bsky.feed.post?action=create', 24 'site.standard.publication', 25 'site.standard.document', 26 'xyz.statusphere.status'
+20 -18
src/lib/cards/SpecialCards/UpdatedBlentos/index.ts
··· 1 - import { getDetailedProfile } from '$lib/atproto'; 2 import type { CardDefinition } from '../../types'; 3 import UpdatedBlentosCard from './UpdatedBlentosCard.svelte'; 4 import type { Did } from '@atcute/lexicons'; 5 - import type { AppBskyActorDefs } from '@atcute/bluesky'; 6 7 export const UpdatedBlentosCardDefitition = { 8 type: 'updatedBlentos', ··· 14 ); 15 const recentRecords = await response.json(); 16 const existingUsers = await cache?.get('updatedBlentos'); 17 - const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers 18 ? JSON.parse(existingUsers) 19 : []; 20 21 - const existingUsersSet = new Set(existingUsersArray.map((v) => v.did)); 22 23 - const uniqueDids = new Set<Did>(); 24 - for (const record of recentRecords as { did: string }[]) { 25 - if (!existingUsersSet.has(record.did as Did)) uniqueDids.add(record.did as Did); 26 - } 27 - 28 - const profiles: Promise<AppBskyActorDefs.ProfileViewDetailed | undefined>[] = []; 29 30 for (const did of Array.from(uniqueDids)) { 31 - const profile = getDetailedProfile({ did }); 32 - profiles.push(profile); 33 - if (profiles.length > 30) break; 34 } 35 36 for (let i = existingUsersArray.length - 1; i >= 0; i--) { 37 // if handle is handle.invalid, remove from existing users and add to profiles to refresh 38 - if (existingUsersArray[i].handle === 'handle.invalid') { 39 const removed = existingUsersArray.splice(i, 1)[0]; 40 - profiles.push(getDetailedProfile({ did: removed.did })); 41 } 42 } 43 44 - const result = [...(await Promise.all(profiles)), ...existingUsersArray].filter( 45 - (v) => v && v.handle !== 'handle.invalid' 46 - ); 47 48 if (cache) { 49 await cache?.put('updatedBlentos', JSON.stringify(result));
··· 1 import type { CardDefinition } from '../../types'; 2 import UpdatedBlentosCard from './UpdatedBlentosCard.svelte'; 3 import type { Did } from '@atcute/lexicons'; 4 + import { getBlentoOrBskyProfile } from '$lib/atproto/methods'; 5 + 6 + type ProfileWithBlentoFlag = Awaited<ReturnType<typeof getBlentoOrBskyProfile>>; 7 8 export const UpdatedBlentosCardDefitition = { 9 type: 'updatedBlentos', ··· 15 ); 16 const recentRecords = await response.json(); 17 const existingUsers = await cache?.get('updatedBlentos'); 18 + const existingUsersArray: ProfileWithBlentoFlag[] = existingUsers 19 ? JSON.parse(existingUsers) 20 : []; 21 22 + const uniqueDids = new Set<Did>(recentRecords.map((v: { did: string }) => v.did as Did)); 23 24 + const profiles: Promise<ProfileWithBlentoFlag | undefined>[] = []; 25 26 for (const did of Array.from(uniqueDids)) { 27 + profiles.push(getBlentoOrBskyProfile({ did })); 28 } 29 30 for (let i = existingUsersArray.length - 1; i >= 0; i--) { 31 // if handle is handle.invalid, remove from existing users and add to profiles to refresh 32 + if ( 33 + (existingUsersArray[i].handle === 'handle.invalid' || 34 + (!existingUsersArray[i].avatar && !existingUsersArray[i].hasBlento)) && 35 + !uniqueDids.has(existingUsersArray[i].did) 36 + ) { 37 const removed = existingUsersArray.splice(i, 1)[0]; 38 + profiles.push(getBlentoOrBskyProfile({ did: removed.did })); 39 + // if in unique dids, remove from older existing users and keep the newer one 40 + // so updated profiles go first 41 + } else if (uniqueDids.has(existingUsersArray[i].did)) { 42 + existingUsersArray.splice(i, 1); 43 } 44 } 45 46 + let result = [...(await Promise.all(profiles)), ...existingUsersArray]; 47 + 48 + result = result.filter((v) => v && v.handle !== 'handle.invalid'); 49 50 if (cache) { 51 await cache?.put('updatedBlentos', JSON.stringify(result));