your personal website on atproto - mirror blento.app
26
fork

Configure Feed

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

cache latest updated blentos

Florian c158570b d7578d0d

+68 -44
+3
src/lib/EditableWebsite.svelte
··· 172 172 173 173 isSaving = false; 174 174 175 + fetch('/' + handle + '/api/refreshData'); 176 + console.log('refreshing data'); 177 + 175 178 toast('Saved', { 176 179 description: 'Your website has been saved!' 177 180 });
+2 -3
src/lib/Profile.svelte
··· 12 12 data, 13 13 showEditButton = false 14 14 }: { handle: string; did: string; data: any; showEditButton?: boolean } = $props(); 15 - $inspect(data); 16 15 17 16 // svelte-ignore state_referenced_locally 18 17 const profileData = data?.data?.['app.bsky.actor.profile']?.self?.value; ··· 41 40 {profileData?.displayName || handle} 42 41 </div> 43 42 44 - <div class="scrollbar flex-grow overflow-y-scroll px-4 -mx-4"> 43 + <div class="scrollbar -mx-4 flex-grow overflow-y-scroll px-4"> 45 44 <div 46 45 class="text-base-600 dark:text-base-400 prose dark:prose-invert prose-a:text-accent-500 prose-a:no-underline" 47 46 > ··· 86 85 </div> 87 86 {:else if client.isLoggedIn} 88 87 <div> 89 - <Button href={client.profile?.handle} class="mt-2"> 88 + <Button href={'/' + client.profile?.handle} class="mt-2"> 90 89 <svg 91 90 xmlns="http://www.w3.org/2000/svg" 92 91 fill="none"
+1 -1
src/lib/cards/BaseCard/BaseEditingCard.svelte
··· 38 38 } & WithElementRef<HTMLAttributes<HTMLDivElement>>; 39 39 40 40 let { 41 - item, 41 + item = $bindable(), 42 42 children, 43 43 ref = $bindable(null), 44 44 onsetsize,
-2
src/lib/cards/BlueskyPostCard/BlueskyPostCard.svelte
··· 8 8 const data = getAdditionalUserData(); 9 9 // svelte-ignore state_referenced_locally 10 10 const feed = (data[item.cardType] as any).feed; 11 - 12 - $inspect(feed); 13 11 </script> 14 12 15 13 <div class="flex h-full flex-col justify-center-safe overflow-y-scroll p-4">
-3
src/lib/cards/ImageCard/CreateImageCardModal.svelte
··· 47 47 } 48 48 } 49 49 50 - console.log('Width:', width); 51 - console.log('Height:', height); 52 - 53 50 // Create a canvas to draw the image 54 51 const canvas = document.createElement('canvas'); 55 52 canvas.width = width;
-1
src/lib/cards/ImageCard/index.ts
··· 13 13 alt: '', 14 14 href: '' 15 15 }; 16 - console.log('adding new card', card); 17 16 }, 18 17 creationModalComponent: CreateImageCardModal, 19 18 upload: async (item) => {
+2 -1
src/lib/cards/LivestreamCard/LivestreamCard.svelte
··· 38 38 if (!latestLivestream) { 39 39 latestLivestream = (await CardDefinitionsByType[item.cardType]?.loadData?.([], { 40 40 did, 41 - handle 41 + handle, 42 + platform: undefined 42 43 })) as 43 44 | { 44 45 createdAt: string;
-2
src/lib/cards/LivestreamCard/index.ts
··· 19 19 }, 20 20 loadData: async (items, { did }) => { 21 21 const records = await listRecords({ did, collection: 'place.stream.livestream', limit: 3 }); 22 - console.log(records); 23 22 24 23 let latestLivestream: 25 24 | { ··· 33 32 const values = Object.values(records); 34 33 if (values?.length > 0) { 35 34 const latest = JSON.parse(JSON.stringify(values[0])); 36 - console.log(latest); 37 35 38 36 latestLivestream = { 39 37 createdAt: latest.value.createdAt,
+35 -15
src/lib/cards/SpecialCards/UpdatedBlentos/index.ts
··· 6 6 export const UpdatedBlentosCardDefitition = { 7 7 type: 'updatedBlentos', 8 8 contentComponent: UpdatedBlentosCard, 9 - loadData: async () => { 10 - const response = await fetch( 11 - 'https://ufos-api.microcosm.blue/records?collection=app.blento.card' 12 - ); 13 - const recentRecords = await response.json(); 14 - const uniqueDids = new Set<string>(); 15 - for (const record of recentRecords as { did: string }[]) { 16 - uniqueDids.add(record.did); 17 - } 18 - const profiles: Promise<ProfileViewDetailed>[] = []; 9 + loadData: async (items, { platform }) => { 10 + try { 11 + const response = await fetch( 12 + 'https://ufos-api.microcosm.blue/records?collection=app.blento.card' 13 + ); 14 + const recentRecords = await response.json(); 15 + const existingUsers = await platform?.env?.USER_DATA_CACHE?.get('updatedBlentos'); 16 + const existingUsersArray: ProfileViewDetailed[] = existingUsers 17 + ? JSON.parse(existingUsers) 18 + : []; 19 19 20 - for (const did of Array.from(uniqueDids)) { 21 - const profile = getProfile({ did }); 22 - profiles.push(profile); 23 - if (profiles.length > 20) return; 20 + const existingUsersSet = new Set(existingUsersArray.map((v) => v.did)); 21 + 22 + const uniqueDids = new Set<string>(); 23 + for (const record of recentRecords as { did: string }[]) { 24 + if (!existingUsersSet.has(record.did)) uniqueDids.add(record.did); 25 + } 26 + 27 + const profiles: Promise<ProfileViewDetailed>[] = []; 28 + 29 + for (const did of Array.from(uniqueDids)) { 30 + const profile = getProfile({ did }); 31 + profiles.push(profile); 32 + if (profiles.length > 20) break; 33 + } 34 + 35 + const result = [...(await Promise.all(profiles)), ...existingUsersArray]; 36 + result.splice(20); 37 + 38 + if (platform?.env?.USER_DATA_CACHE) { 39 + await platform?.env?.USER_DATA_CACHE.put('updatedBlentos', JSON.stringify(result)); 40 + } 41 + return JSON.parse(JSON.stringify(result)); 42 + } catch (error) { 43 + console.error('error fetching updated blentos', error); 44 + return []; 24 45 } 25 - return JSON.parse(JSON.stringify(await Promise.all(profiles))); 26 46 } 27 47 } as CardDefinition & { type: 'updatedBlentos' };
+4 -1
src/lib/cards/types.ts
··· 37 37 sidebarComponent?: Component<SidebarComponentProps>; 38 38 sidebarButtonText?: string; 39 39 40 - loadData?: (items: Item[], { did, handle }: { did: string; handle: string }) => Promise<unknown>; 40 + loadData?: ( 41 + items: Item[], 42 + { did, handle, platform }: { did: string; handle: string; platform?: App.Platform } 43 + ) => Promise<unknown>; 41 44 dataKey?: string; 42 45 };
-2
src/lib/components/bluesky-post/index.ts
··· 3 3 import type { PostView } from '@atproto/api/dist/client/types/app/bsky/feed/defs'; 4 4 5 5 function blueskyEmbedTypeToEmbedType(type: string) { 6 - console.log(type); 7 6 switch (type) { 8 7 case 'app.bsky.embed.external#view': 9 8 case 'app.bsky.embed.external': ··· 23 22 data: PostView, 24 23 baseUrl: string = 'https://bsky.app' 25 24 ): PostData { 26 - console.log(data); 27 25 const post = data; 28 26 // const reason = data.reason; 29 27 // const reply = data.reply?.parent;
-10
src/lib/oauth/atproto.ts
··· 109 109 }) { 110 110 if (!client.profile || !client.rpc) throw new Error('No profile or rpc'); 111 111 112 - console.log('updating record', { 113 - data: { 114 - collection, 115 - repo: client.profile.did, 116 - rkey, 117 - record: { 118 - ...record 119 - } 120 - } 121 - }); 122 112 const response = await client.rpc.call('com.atproto.repo.putRecord', { 123 113 data: { 124 114 collection,
+12 -3
src/lib/website/load.ts
··· 24 24 const cachedResult = await platform?.env?.USER_DATA_CACHE?.get(handle); 25 25 26 26 if (cachedResult) { 27 - console.log('using cached result for handle', handle); 27 + const result = JSON.parse(cachedResult); 28 + const update = result.updatedAt; 29 + const timePassed = (Date.now() - update) / 1000; 30 + console.log( 31 + 'using cached result for handle', 32 + handle, 33 + 'last update', 34 + timePassed, 35 + 'seconds ago' 36 + ); 28 37 return JSON.parse(cachedResult); 29 38 } 30 39 } ··· 87 96 88 97 const additionDataPromises: Record<string, Promise<unknown>> = {}; 89 98 90 - const handleAndDid = { did, handle }; 99 + const loadOptions = { did, handle, platform }; 91 100 92 101 for (const cardType of cardTypesArray) { 93 102 const cardDef = CardDefinitionsByType[cardType]; ··· 97 106 Object.values(downloadedData['app.blento.card']) 98 107 .filter((v) => cardType == v.value.cardType) 99 108 .map((v) => v.value) as Item[], 100 - handleAndDid 109 + loadOptions 101 110 ); 102 111 } 103 112 }
src/routes/[handle]/+layout.server.ts src/routes/[handle]/+page.server.ts
+9
src/routes/[handle]/edit/+page.server.ts
··· 1 + import { loadData } from '$lib/website/load'; 2 + import { env } from '$env/dynamic/private'; 3 + import { error } from '@sveltejs/kit'; 4 + 5 + export async function load({ params }) { 6 + if (env.PUBLIC_IS_SELFHOSTED) error(404); 7 + const data = await loadData(params.handle); 8 + return { ...data, handle: params.handle }; 9 + }