This repository has no description
0

Configure Feed

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

fix paths

+26 -11
+26 -11
app/src/app/api/bluesky/profile/route.ts
··· 5 5 export const dynamic = 'force-dynamic'; 6 6 import { containsBannedWords, sanitizeText } from '@/lib/content-filter'; 7 7 8 + 8 9 // Define interfaces for type safety 9 10 interface ProfileEntry { 10 11 id: string; ··· 38 39 '1️⃣', '2️⃣', '🟡', '🟤' 39 40 ]; 40 41 41 - const DEFAULT_API_URL = 'https://bsky.social/xrpc'; 42 + const DEFAULT_API_URL = 'https://public.api.bsky.app/xrpc'; 42 43 const MAX_ENTRIES = 50; 43 44 const FLUSHING_STATUS_NSID = 'im.flushing.right.now'; 44 45 ··· 72 73 // If the handle doesn't look like a DID, resolve it 73 74 if (!handle.startsWith('did:')) { 74 75 try { 75 - const resolveResponse = await fetch(`https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(handle)}`); 76 + // Use public.api.bsky.app for handle resolution - this endpoint handles third-party PDS users better 77 + const resolveEndpoint = 'https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle'; 78 + console.log(`Resolving handle ${handle} using ${resolveEndpoint}`); 79 + 80 + // Make request to public API endpoint 81 + const resolveResponse = await fetch(`${resolveEndpoint}?handle=${encodeURIComponent(handle)}`); 76 82 77 83 if (!resolveResponse.ok) { 78 84 return NextResponse.json( ··· 86 92 87 93 // Step 1.5: Get user profile data including description 88 94 try { 89 - const profileResponse = await fetch(`https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(did)}`); 95 + // Also use public API for profile data to support third-party PDS users 96 + const profileResponse = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(did)}`); 90 97 91 98 if (profileResponse.ok) { 92 99 userProfile = await profileResponse.json(); ··· 106 113 } 107 114 108 115 // Step 2: Get the PDS service endpoint from PLC directory 109 - let serviceEndpoint = 'https://bsky.social'; // Default fallback 116 + let serviceEndpoint = 'https://public.api.bsky.app'; // Default fallback 110 117 try { 111 118 const plcResponse = await fetch(`https://plc.directory/${did}/data`); 112 119 ··· 133 140 // Step 3: Call the repo.listRecords API to get the user's flushing statuses 134 141 try { 135 142 const listRecordsUrl = `${serviceEndpoint}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`; 143 + console.log(`Fetching records from ${listRecordsUrl}`); 136 144 137 145 const recordsResponse = await fetch(listRecordsUrl, { 138 146 headers: { ··· 141 149 }); 142 150 143 151 if (!recordsResponse.ok) { 144 - // If failed with one endpoint, try with the default endpoint 145 - if (serviceEndpoint !== 'https://bsky.social') { 146 - console.warn(`Failed to get records from ${serviceEndpoint}, trying default endpoint`); 147 - const fallbackUrl = `https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`; 152 + // If failed with custom PDS service endpoint, try with the default public API endpoint 153 + if (serviceEndpoint !== 'https://public.api.bsky.app') { 154 + console.warn(`Failed to get records from ${serviceEndpoint}, trying public API endpoint`); 155 + // Log the error for debugging third-party PDS issues 156 + try { 157 + const errorText = await recordsResponse.text(); 158 + console.error(`Error response from ${serviceEndpoint}: ${errorText}`); 159 + } catch (e) { 160 + console.error(`Could not read error response: ${e}`); 161 + } 162 + const fallbackUrl = `https://public.api.bsky.app/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`; 148 163 149 164 const fallbackResponse = await fetch(fallbackUrl, { 150 165 headers: { ··· 400 415 401 416 try { 402 417 if (!resolveHandle.startsWith('did:')) { 403 - // Always use bsky.social for resolving handles to DIDs 404 - const resolveResponse = await fetch(`https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(resolveHandle)}`); 418 + // Use public.api.bsky.app for resolving handles to DIDs - better support for third-party PDS 419 + const resolveResponse = await fetch(`https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(resolveHandle)}`); 405 420 406 421 if (!resolveResponse.ok) { 407 422 console.error(`Failed to resolve handle ${resolveHandle}:`, await resolveResponse.text()); ··· 464 479 465 480 // IMPORTANT: For third-party PDS users, we need to use the handle from describeRepo 466 481 // which will be accurate for their PDS, rather than the handle we resolved earlier 467 - if (pdsEndpoint && pdsEndpoint !== 'https://bsky.social' && data.handle) { 482 + if (pdsEndpoint && pdsEndpoint !== 'https://bsky.social' && pdsEndpoint !== 'https://public.api.bsky.app' && data.handle) { 468 483 console.log(`Using handle from PDS response: ${data.handle} instead of ${userHandle}`); 469 484 userHandle = data.handle; 470 485 }