···55export const dynamic = 'force-dynamic';
66import { containsBannedWords, sanitizeText } from '@/lib/content-filter';
7788+89// Define interfaces for type safety
910interface ProfileEntry {
1011 id: string;
···3839 '1️⃣', '2️⃣', '🟡', '🟤'
3940];
40414141-const DEFAULT_API_URL = 'https://bsky.social/xrpc';
4242+const DEFAULT_API_URL = 'https://public.api.bsky.app/xrpc';
4243const MAX_ENTRIES = 50;
4344const FLUSHING_STATUS_NSID = 'im.flushing.right.now';
4445···7273 // If the handle doesn't look like a DID, resolve it
7374 if (!handle.startsWith('did:')) {
7475 try {
7575- const resolveResponse = await fetch(`https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(handle)}`);
7676+ // Use public.api.bsky.app for handle resolution - this endpoint handles third-party PDS users better
7777+ const resolveEndpoint = 'https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle';
7878+ console.log(`Resolving handle ${handle} using ${resolveEndpoint}`);
7979+8080+ // Make request to public API endpoint
8181+ const resolveResponse = await fetch(`${resolveEndpoint}?handle=${encodeURIComponent(handle)}`);
76827783 if (!resolveResponse.ok) {
7884 return NextResponse.json(
···86928793 // Step 1.5: Get user profile data including description
8894 try {
8989- const profileResponse = await fetch(`https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(did)}`);
9595+ // Also use public API for profile data to support third-party PDS users
9696+ const profileResponse = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(did)}`);
90979198 if (profileResponse.ok) {
9299 userProfile = await profileResponse.json();
···106113 }
107114108115 // Step 2: Get the PDS service endpoint from PLC directory
109109- let serviceEndpoint = 'https://bsky.social'; // Default fallback
116116+ let serviceEndpoint = 'https://public.api.bsky.app'; // Default fallback
110117 try {
111118 const plcResponse = await fetch(`https://plc.directory/${did}/data`);
112119···133140 // Step 3: Call the repo.listRecords API to get the user's flushing statuses
134141 try {
135142 const listRecordsUrl = `${serviceEndpoint}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`;
143143+ console.log(`Fetching records from ${listRecordsUrl}`);
136144137145 const recordsResponse = await fetch(listRecordsUrl, {
138146 headers: {
···141149 });
142150143151 if (!recordsResponse.ok) {
144144- // If failed with one endpoint, try with the default endpoint
145145- if (serviceEndpoint !== 'https://bsky.social') {
146146- console.warn(`Failed to get records from ${serviceEndpoint}, trying default endpoint`);
147147- const fallbackUrl = `https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`;
152152+ // If failed with custom PDS service endpoint, try with the default public API endpoint
153153+ if (serviceEndpoint !== 'https://public.api.bsky.app') {
154154+ console.warn(`Failed to get records from ${serviceEndpoint}, trying public API endpoint`);
155155+ // Log the error for debugging third-party PDS issues
156156+ try {
157157+ const errorText = await recordsResponse.text();
158158+ console.error(`Error response from ${serviceEndpoint}: ${errorText}`);
159159+ } catch (e) {
160160+ console.error(`Could not read error response: ${e}`);
161161+ }
162162+ const fallbackUrl = `https://public.api.bsky.app/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`;
148163149164 const fallbackResponse = await fetch(fallbackUrl, {
150165 headers: {
···400415401416 try {
402417 if (!resolveHandle.startsWith('did:')) {
403403- // Always use bsky.social for resolving handles to DIDs
404404- const resolveResponse = await fetch(`https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(resolveHandle)}`);
418418+ // Use public.api.bsky.app for resolving handles to DIDs - better support for third-party PDS
419419+ const resolveResponse = await fetch(`https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(resolveHandle)}`);
405420406421 if (!resolveResponse.ok) {
407422 console.error(`Failed to resolve handle ${resolveHandle}:`, await resolveResponse.text());
···464479465480 // IMPORTANT: For third-party PDS users, we need to use the handle from describeRepo
466481 // which will be accurate for their PDS, rather than the handle we resolved earlier
467467- if (pdsEndpoint && pdsEndpoint !== 'https://bsky.social' && data.handle) {
482482+ if (pdsEndpoint && pdsEndpoint !== 'https://bsky.social' && pdsEndpoint !== 'https://public.api.bsky.app' && data.handle) {
468483 console.log(`Using handle from PDS response: ${data.handle} instead of ${userHandle}`);
469484 userHandle = data.handle;
470485 }