your personal website on atproto - mirror blento.app

refactor pt2

Florian 5792abcd b78fba20

+60 -38
+4
src/app.d.ts
··· 16 16 } 17 17 } 18 18 19 + import type {} from '@atcute/atproto'; 20 + import type {} from '@atcute/bluesky'; 21 + 22 + 19 23 export {};
+1 -1
src/lib/atproto/methods.ts
··· 18 18 return { did, collection, rkey } as { 19 19 collection: `${string}.${string}.${string}`; 20 20 rkey: string; 21 - did: string; 21 + did: Did; 22 22 }; 23 23 } 24 24
+6 -6
src/lib/cards/SpecialCards/UpdatedBlentos/index.ts
··· 1 1 import { getDetailedProfile } from '$lib/atproto'; 2 - import type { ProfileViewDetailed } from '@atproto/api/dist/client/types/app/bsky/actor/defs'; 3 2 import type { CardDefinition } from '../../types'; 4 3 import UpdatedBlentosCard from './UpdatedBlentosCard.svelte'; 5 - import { AppBskyActorDefs } from '@atcute/bluesky'; 4 + import type { Did } from '@atcute/lexicons'; 5 + import type { AppBskyActorDefs } from '@atcute/bluesky'; 6 6 7 7 export const UpdatedBlentosCardDefitition = { 8 8 type: 'updatedBlentos', ··· 14 14 ); 15 15 const recentRecords = await response.json(); 16 16 const existingUsers = await cache?.get('updatedBlentos'); 17 - const existingUsersArray: ProfileViewDetailed[] = existingUsers 17 + const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers 18 18 ? JSON.parse(existingUsers) 19 19 : []; 20 20 21 21 const existingUsersSet = new Set(existingUsersArray.map((v) => v.did)); 22 22 23 - const uniqueDids = new Set<string>(); 23 + const uniqueDids = new Set<Did>(); 24 24 for (const record of recentRecords as { did: string }[]) { 25 - if (!existingUsersSet.has(record.did)) uniqueDids.add(record.did); 25 + if (!existingUsersSet.has(record.did as Did)) uniqueDids.add(record.did as Did); 26 26 } 27 27 28 - const profiles: Promise<AppBskyActorDefs.ProfileViewDetailed>[] = []; 28 + const profiles: Promise<AppBskyActorDefs.ProfileViewDetailed | undefined>[] = []; 29 29 30 30 for (const did of Array.from(uniqueDids)) { 31 31 const profile = getDetailedProfile({ did });
+2 -1
src/lib/cards/types.ts
··· 1 1 import type { Component } from 'svelte'; 2 2 import type { Item, UserCache } from '$lib/types'; 3 + import type { Did } from '@atcute/lexicons'; 3 4 4 5 export type CreationModalComponentProps = { 5 6 item: Item; ··· 42 43 loadData?: ( 43 44 // all cards of that type 44 45 items: Item[], 45 - { did, handle, cache }: { did: string; handle: string; cache?: UserCache } 46 + { did, handle, cache }: { did: Did; handle: string; cache?: UserCache } 46 47 ) => Promise<unknown>; 47 48 48 49 // show color selection popup
+1 -3
src/lib/helper.ts
··· 446 446 const item = currentItems.find((i) => i.id === originalItem.id); 447 447 if (!item) { 448 448 console.log('deleting item', originalItem); 449 - promises.push( 450 - deleteRecord({ collection: 'app.blento.card', rkey: originalItem.id, did: data.did }) 451 - ); 449 + promises.push(deleteRecord({ collection: 'app.blento.card', rkey: originalItem.id })); 452 450 } 453 451 } 454 452
+2 -1
src/lib/website/Account.svelte
··· 1 1 <script lang="ts"> 2 2 import { user, login, logout } from '$lib/atproto'; 3 3 import type { WebsiteData } from '$lib/types'; 4 + import type { ActorIdentifier } from '@atcute/lexicons'; 4 5 import { Button, Popover } from '@foxui/core'; 5 6 6 7 let { ··· 32 33 33 34 <Button 34 35 onclick={async () => { 35 - await login(data.handle); 36 + await login(data.handle as ActorIdentifier); 36 37 }}>Login</Button 37 38 > 38 39 </div>
+3 -2
src/lib/website/Context.svelte
··· 4 4 import { setAdditionalUserData, setCanEdit, setDidContext, setHandleContext } from './context'; 5 5 import { dev } from '$app/environment'; 6 6 import { user } from '$lib/atproto'; 7 + import type { Did, Handle } from '@atcute/lexicons'; 7 8 8 9 let { 9 10 data, ··· 19 20 setCanEdit(() => dev || (user.isLoggedIn && user.profile?.did === data.did)); 20 21 21 22 // svelte-ignore state_referenced_locally 22 - setDidContext(data.did); 23 + setDidContext(data.did as Did); 23 24 // svelte-ignore state_referenced_locally 24 - setHandleContext(data.handle); 25 + setHandleContext(data.handle as Handle); 25 26 </script> 26 27 27 28 {@render children()}
+5 -4
src/lib/website/Profile.svelte
··· 7 7 import type { WebsiteData } from '$lib/types'; 8 8 import { getDescription, getName } from '$lib/helper'; 9 9 import { page } from '$app/state'; 10 + import type { ActorIdentifier } from '@atcute/lexicons'; 10 11 11 12 let { 12 13 data, ··· 40 41 {getName(data)} 41 42 </div> 42 43 43 - <div class="scrollbar -mx-4 flex-grow overflow-x-hidden overflow-y-scroll px-4"> 44 + <div class="scrollbar -mx-4 grow overflow-x-hidden overflow-y-scroll px-4"> 44 45 <div 45 46 class="text-base-600 dark:text-base-400 prose dark:prose-invert prose-a:text-accent-500 prose-a:no-underline" 46 47 > ··· 70 71 Edit Your Website</Button 71 72 > 72 73 </div> 73 - {:else} 74 - <div class="h-[42px] w-1 @5xl/wrapper:hidden"></div> 74 + {:else} 75 + <div class="h-10.5 w-1 @5xl/wrapper:hidden"></div> 75 76 {/if} 76 77 77 78 {#if !env.PUBLIC_IS_SELFHOSTED && data.handle === 'blento.app' && user.profile?.handle !== data.handle} ··· 82 83 </div> 83 84 <BlueskyLogin 84 85 login={async (handle) => { 85 - await login(handle); 86 + await login(handle as ActorIdentifier); 86 87 return true; 87 88 }} 88 89 />
+3 -2
src/lib/website/Website.svelte
··· 8 8 import type { WebsiteData } from '$lib/types'; 9 9 import Context from './Context.svelte'; 10 10 import Head from './Head.svelte'; 11 + import type { Did, Handle } from '@atcute/lexicons'; 11 12 12 13 let { data }: { data: WebsiteData } = $props(); 13 14 ··· 15 16 setIsMobile(() => isMobile); 16 17 17 18 // svelte-ignore state_referenced_locally 18 - setDidContext(data.did); 19 + setDidContext(data.did as Did); 19 20 // svelte-ignore state_referenced_locally 20 - setHandleContext(data.handle); 21 + setHandleContext(data.handle as Handle); 21 22 22 23 let maxHeight = $derived( 23 24 data.cards.reduce(
+3 -2
src/lib/website/context.ts
··· 1 + import type { Did, Handle } from '@atcute/lexicons'; 1 2 import { createContext } from 'svelte'; 2 3 3 - export const [getDidContext, setDidContext] = createContext<string>(); 4 - export const [getHandleContext, setHandleContext] = createContext<string>(); 4 + export const [getDidContext, setDidContext] = createContext<Did>(); 5 + export const [getHandleContext, setHandleContext] = createContext<Handle>(); 5 6 export const [getIsMobile, setIsMobile] = createContext<() => boolean>(); 6 7 export const [getCanEdit, setCanEdit] = createContext<() => boolean>(); 7 8 export const [getAdditionalUserData, setAdditionalUserData] =
+2 -1
src/lib/website/load.ts
··· 4 4 import type { Item, UserCache, WebsiteData } from '$lib/types'; 5 5 import { compactItems, fixAllCollisions } from '$lib/helper'; 6 6 import { error } from '@sveltejs/kit'; 7 + import type { Handle } from '@atcute/lexicons'; 7 8 8 9 const CURRENT_CACHE_VERSION = 1; 9 10 ··· 44 45 } 45 46 46 47 export async function loadData( 47 - handle: string, 48 + handle: Handle, 48 49 cache: UserCache | undefined, 49 50 forceUpdate: boolean = false, 50 51 page: string = 'self'
+5
src/params/handle.ts
··· 1 + import type { ParamMatcher } from '@sveltejs/kit'; 2 + 3 + export const match = ((param: string) => { 4 + return param.includes('.'); 5 + }) satisfies ParamMatcher;
+2 -1
src/routes/+page.server.ts
··· 1 1 import { loadData } from '$lib/website/load'; 2 2 import { env } from '$env/dynamic/public'; 3 3 import type { UserCache } from '$lib/types'; 4 + import type { Handle } from '@atcute/lexicons'; 4 5 5 6 export async function load({ platform, url }) { 6 7 const hostname = url.hostname; ··· 11 12 } 12 13 const cache = platform?.env?.USER_DATA_CACHE as unknown; 13 14 14 - return await loadData(handle, cache as UserCache); 15 + return await loadData(handle as Handle, cache as UserCache); 15 16 }
src/routes/[handle]/.well-known/site.standard.publication/+server.ts src/routes/[handle=handle]/.well-known/site.standard.publication/+server.ts
+2 -1
src/routes/[handle]/[[page]]/+layout.server.ts src/routes/[handle=handle]/[[page]]/+layout.server.ts
··· 2 2 import { env } from '$env/dynamic/private'; 3 3 import { error } from '@sveltejs/kit'; 4 4 import type { UserCache } from '$lib/types'; 5 + import type { Handle } from '@atcute/lexicons'; 5 6 6 7 export async function load({ params, platform }) { 7 8 if (env.PUBLIC_IS_SELFHOSTED) error(404); ··· 10 11 11 12 console.log(params.page); 12 13 13 - return await loadData(params.handle, cache as UserCache, false, params.page); 14 + return await loadData(params.handle as Handle, cache as UserCache, false, params.page); 14 15 }
src/routes/[handle]/[[page]]/+page.svelte src/routes/[handle=handle]/[[page]]/+page.svelte
src/routes/[handle]/[[page]]/edit/+page.svelte src/routes/[handle=handle]/[[page]]/edit/+page.svelte
+2 -1
src/routes/[handle]/api/refreshData/+server.ts src/routes/[handle=handle]/api/refreshData/+server.ts
··· 1 1 import type { UserCache } from '$lib/types'; 2 2 import { loadData } from '$lib/website/load.js'; 3 + import type { Handle } from '@atcute/lexicons'; 3 4 import { json } from '@sveltejs/kit'; 4 5 5 6 export async function GET({ params, platform }) { ··· 7 8 const handle = params.handle; 8 9 9 10 const cache = platform?.env?.USER_DATA_CACHE as unknown; 10 - await loadData(handle, cache as UserCache, true); 11 + await loadData(handle as Handle, cache as UserCache, true); 11 12 12 13 return json('ok'); 13 14 }
+2 -1
src/routes/[handle]/og.png/+server.ts src/routes/[handle=handle]/og.png/+server.ts
··· 1 1 import type { UserCache } from '$lib/types'; 2 2 import { loadData } from '$lib/website/load'; 3 + import type { Handle } from '@atcute/lexicons'; 3 4 import { ImageResponse } from '@ethercorps/sveltekit-og'; 4 5 5 6 export async function GET({ params, platform }) { ··· 7 8 8 9 const cache = platform?.env?.USER_DATA_CACHE as unknown; 9 10 10 - const data = await loadData(params.handle, cache as UserCache); 11 + const data = await loadData(params.handle as Handle, cache as UserCache); 11 12 12 13 const image = data.profile.avatar; 13 14
+2 -1
src/routes/all/+page.server.ts
··· 1 1 import { env } from '$env/dynamic/public'; 2 2 import type { UserCache, WebsiteData } from '$lib/types.js'; 3 3 import { loadData } from '$lib/website/load'; 4 + import type { Handle } from '@atcute/lexicons'; 4 5 import type { ProfileViewDetailed } from '@atproto/api/dist/client/types/app/bsky/actor/defs.js'; 5 6 6 7 export async function load({ platform }) { ··· 24 25 25 26 const handle = env.PUBLIC_HANDLE; 26 27 27 - const data = await loadData(handle, cache as unknown as UserCache); 28 + const data = await loadData(handle as Handle, cache as unknown as UserCache); 28 29 29 30 data.publication ??= {}; 30 31 data.publication.preferences ??= {};
+2 -4
src/routes/api/links/+server.ts
··· 7 7 return json({ error: 'No link provided' }, { status: 400 }); 8 8 } 9 9 10 - // check if link is valid url 11 10 try { 12 11 new URL(link); 13 - // eslint-disable-next-line @typescript-eslint/no-unused-vars 14 - } catch (_) { 15 - return json({ error: 'Link is not a valid url' }, { status: 500 }); 12 + } catch { 13 + return json({ error: 'Link is not a valid url' }, { status: 400 }); 16 14 } 17 15 18 16 try {
+5 -3
src/routes/api/reloadRecent/+server.ts
··· 1 1 import { getDetailedProfile } from '$lib/atproto'; 2 - import type { ProfileViewDetailed } from '@atproto/api/dist/client/types/app/bsky/actor/defs'; 3 2 import { json } from '@sveltejs/kit'; 3 + import type { AppBskyActorDefs } from '@atcute/bluesky'; 4 4 5 5 export async function GET({ platform }) { 6 6 if (!platform?.env?.USER_DATA_CACHE) return json('no cache'); 7 7 const existingUsers = await platform?.env?.USER_DATA_CACHE?.get('updatedBlentos'); 8 8 9 - const existingUsersArray: ProfileViewDetailed[] = existingUsers ? JSON.parse(existingUsers) : []; 9 + const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers 10 + ? JSON.parse(existingUsers) 11 + : []; 10 12 11 13 const existingUsersSet = new Set(existingUsersArray.map((v) => v.did)); 12 14 13 - const newProfilesPromises: Promise<ProfileViewDetailed>[] = []; 15 + const newProfilesPromises: Promise<AppBskyActorDefs.ProfileViewDetailed | undefined>[] = []; 14 16 for (const did of Array.from(existingUsersSet)) { 15 17 const profile = getDetailedProfile({ did }); 16 18 newProfilesPromises.push(profile);
+4 -2
src/routes/api/update/+server.ts
··· 1 1 import type { UserCache } from '$lib/types'; 2 2 import { getCache, loadData } from '$lib/website/load'; 3 - import type { ProfileViewDetailed } from '@atproto/api/dist/client/types/app/bsky/actor/defs'; 3 + import type { AppBskyActorDefs } from '@atcute/bluesky'; 4 4 import { json } from '@sveltejs/kit'; 5 5 6 6 export async function GET({ platform }) { 7 7 if (!platform?.env?.USER_DATA_CACHE) return json('no cache'); 8 8 const existingUsers = await platform?.env?.USER_DATA_CACHE?.get('updatedBlentos'); 9 9 10 - const existingUsersArray: ProfileViewDetailed[] = existingUsers ? JSON.parse(existingUsers) : []; 10 + const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers 11 + ? JSON.parse(existingUsers) 12 + : []; 11 13 12 14 const existingUsersHandle = existingUsersArray.map((v) => v.handle); 13 15
+2 -1
src/routes/edit/+page.server.ts
··· 1 1 import { loadData } from '$lib/website/load'; 2 2 import { env } from '$env/dynamic/public'; 3 3 import type { UserCache } from '$lib/types'; 4 + import type { Handle } from '@atcute/lexicons'; 4 5 5 6 export async function load({ url, platform }) { 6 7 const hostname = url.hostname; ··· 12 13 13 14 const cache = platform?.env?.USER_DATA_CACHE as unknown; 14 15 15 - return await loadData(handle, cache as UserCache); 16 + return await loadData(handle as Handle, cache as UserCache); 16 17 }