your personal website on atproto - mirror blento.app

small fixes

+24 -18
+19 -14
src/lib/cache.ts
··· 1 import type { KVNamespace } from '@cloudflare/workers-types'; 2 3 /** TTL in seconds for each cache namespace */ 4 const NAMESPACE_TTL = { 5 - user: 60 * 60 * 24, // 24 hours 6 identity: 60 * 60 * 24 * 7, // 7 days 7 github: 60 * 60 * 12, // 12 hours 8 'gh-contrib': 60 * 60 * 12, // 12 hours ··· 22 return this.kv.get(`${namespace}:${key}`); 23 } 24 25 - async put(namespace: CacheNamespace, key: string, value: string, ttlSeconds?: number): Promise<void> { 26 const ttl = ttlSeconds ?? NAMESPACE_TTL[namespace] ?? 0; 27 await this.kv.put(`${namespace}:${key}`, value, ttl > 0 ? { expirationTtl: ttl } : undefined); 28 } ··· 54 await this.put(namespace, key, JSON.stringify(value), ttlSeconds); 55 } 56 57 - // === User data (keyed by DID, with handle↔did resolution) === 58 - 59 - async getUser(identifier: string): Promise<string | null> { 60 const did = await this.resolveDid(identifier); 61 if (!did) return null; 62 - return this.get('user', did); 63 } 64 65 - async putUser(did: string, handle: string, data: string): Promise<void> { 66 await Promise.all([ 67 - this.put('user', did, data), 68 this.put('identity', `h:${handle}`, did), 69 this.put('identity', `d:${did}`, handle) 70 ]); 71 } 72 73 - async listUsers(): Promise<string[]> { 74 - return this.list('user'); 75 } 76 77 // === Identity resolution === 78 - 79 - async resolveDid(identifier: string): Promise<string | null> { 80 - if (identifier.startsWith('did:')) return identifier; 81 return this.get('identity', `h:${identifier}`); 82 } 83 84 - async resolveHandle(did: string): Promise<string | null> { 85 return this.get('identity', `d:${did}`); 86 } 87 }
··· 1 + import type { ActorIdentifier, Did } from '@atcute/lexicons'; 2 + import { isDid } from '@atcute/lexicons/syntax'; 3 import type { KVNamespace } from '@cloudflare/workers-types'; 4 5 /** TTL in seconds for each cache namespace */ 6 const NAMESPACE_TTL = { 7 + blento: 60 * 60 * 24, // 24 hours 8 identity: 60 * 60 * 24 * 7, // 7 days 9 github: 60 * 60 * 12, // 12 hours 10 'gh-contrib': 60 * 60 * 12, // 12 hours ··· 24 return this.kv.get(`${namespace}:${key}`); 25 } 26 27 + async put( 28 + namespace: CacheNamespace, 29 + key: string, 30 + value: string, 31 + ttlSeconds?: number 32 + ): Promise<void> { 33 const ttl = ttlSeconds ?? NAMESPACE_TTL[namespace] ?? 0; 34 await this.kv.put(`${namespace}:${key}`, value, ttl > 0 ? { expirationTtl: ttl } : undefined); 35 } ··· 61 await this.put(namespace, key, JSON.stringify(value), ttlSeconds); 62 } 63 64 + // === blento data (keyed by DID, with handle↔did resolution) === 65 + async getBlento(identifier: ActorIdentifier): Promise<string | null> { 66 const did = await this.resolveDid(identifier); 67 if (!did) return null; 68 + return this.get('blento', did); 69 } 70 71 + async putBlento(did: string, handle: string, data: string): Promise<void> { 72 await Promise.all([ 73 + this.put('blento', did, data), 74 this.put('identity', `h:${handle}`, did), 75 this.put('identity', `d:${did}`, handle) 76 ]); 77 } 78 79 + async listBlentos(): Promise<string[]> { 80 + return this.list('blento'); 81 } 82 83 // === Identity resolution === 84 + async resolveDid(identifier: ActorIdentifier): Promise<string | null> { 85 + if (isDid(identifier)) return identifier; 86 return this.get('identity', `h:${identifier}`); 87 } 88 89 + async resolveHandle(did: Did): Promise<string | null> { 90 return this.get('identity', `d:${did}`); 91 } 92 }
+2 -1
src/lib/layout/EditableGrid.svelte
··· 373 ondrop={handleFileDrop} 374 /> 375 376 - <!-- svelte-ignore a11y_no_static_element_interactions a11y_click_events_have_key_events --> 377 <div 378 bind:this={container} 379 onpointerdown={handlePointerDown}
··· 373 ondrop={handleFileDrop} 374 /> 375 376 + <!-- svelte-ignore a11y_no_static_element_interactions --> 377 + <!-- svelte-ignore a11y_click_events_have_key_events --> 378 <div 379 bind:this={container} 380 onpointerdown={handlePointerDown}
+3 -3
src/lib/website/load.ts
··· 10 11 const CURRENT_CACHE_VERSION = 1; 12 13 - export async function getCache(identifier: string, page: string, cache?: CacheService) { 14 try { 15 - const cachedResult = await cache?.getUser(identifier); 16 17 if (!cachedResult) return; 18 const result = JSON.parse(cachedResult); ··· 134 // Only cache results that have cards to avoid caching PDS errors 135 if (result.cards.length > 0) { 136 const stringifiedResult = JSON.stringify(result); 137 - await cache?.putUser(did, handle as string, stringifiedResult); 138 } 139 140 const parsedResult = structuredClone(result) as any;
··· 10 11 const CURRENT_CACHE_VERSION = 1; 12 13 + export async function getCache(identifier: ActorIdentifier, page: string, cache?: CacheService) { 14 try { 15 + const cachedResult = await cache?.getBlento(identifier); 16 17 if (!cachedResult) return; 18 const result = JSON.parse(cachedResult); ··· 134 // Only cache results that have cards to avoid caching PDS errors 135 if (result.cards.length > 0) { 136 const stringifiedResult = JSON.stringify(result); 137 + await cache?.putBlento(did, handle as string, stringifiedResult); 138 } 139 140 const parsedResult = structuredClone(result) as any;