source for getorbyt.com getorbyt.com/
client bsky orbytapp app orbyt bluesky getorbyt orbytvideo atproto video
0
fork

Configure Feed

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

refactor: improve color fetching logic in getColor function

- Update getColor function to handle optional binding parameter for better flexibility.
- Enhance error handling and add multiple fetch targets, including local development and production APIs.
- Simplify color data retrieval process by iterating through potential fetch sources.

+31 -12
+3 -3
src/pages/@[handle].astro
··· 30 30 const videoPosts = videoFeed.posts; 31 31 const nextCursor = videoFeed.cursor; 32 32 33 - // Fetch profile colors via Service Binding 34 - const colorData = profileData.did && env?.ORBYT_API 35 - ? await getColor(profileData.did, env.ORBYT_API) 33 + // Fetch profile colors 34 + const colorData = profileData.did 35 + ? await getColor(profileData.did, env?.ORBYT_API) 36 36 : null; 37 37 38 38 // Extract metadata with fallbacks
+28 -9
src/utils/orbyt-api.ts
··· 11 11 12 12 export async function getColor( 13 13 did: string, 14 - binding: OrbytApiBinding 14 + binding?: OrbytApiBinding 15 15 ): Promise<ColorData | null> { 16 16 const endpoint = `/v1/colors/${encodeURIComponent(did)}`; 17 - 18 - try { 19 - const response = await binding.fetch(`https://orbyt-api${endpoint}`); 20 - if (!response.ok) return null; 21 - return response.json(); 22 - } catch (error) { 23 - console.warn('Color API unavailable:', error instanceof Error ? error.message : error); 24 - return null; 17 + const targets: Array<{ url: string; fetcher: (url: string) => Promise<Response> }> = []; 18 + if (binding) { 19 + targets.push({ 20 + url: `https://orbyt-api${endpoint}`, 21 + fetcher: (url) => binding.fetch(url), 22 + }); 23 + } else if (import.meta.env.DEV) { 24 + targets.push({ 25 + url: `http://127.0.0.1:8787${endpoint}`, 26 + fetcher: (url) => fetch(url), 27 + }); 28 + } 29 + targets.push({ 30 + url: `https://api.getorbyt.com${endpoint}`, 31 + fetcher: (url) => fetch(url), 32 + }); 33 + 34 + for (const { url, fetcher } of targets) { 35 + try { 36 + const response = await fetcher(url); 37 + if (!response.ok) continue; 38 + return response.json(); 39 + } catch (error) { 40 + console.warn('Color API attempt failed:', error instanceof Error ? error.message : error); 41 + } 25 42 } 43 + 44 + return null; 26 45 }