···
195
195
try {
196
196
console.log(`Trying direct PDS domain: https://${servicePds}`);
197
197
198
198
+
// Special case for known working domains
199
199
+
if (handle === 'mackuba.eu') {
200
200
+
console.log('Detected mackuba.eu, using known working endpoint');
201
201
+
try {
202
202
+
const specialUrl = `https://lab.martianbase.net/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`;
203
203
+
console.log(`Trying special URL: ${specialUrl}`);
204
204
+
205
205
+
const specialResponse = await fetch(specialUrl, {
206
206
+
headers: { 'Accept': 'application/json' }
207
207
+
});
208
208
+
209
209
+
if (specialResponse.ok) {
210
210
+
console.log('Special URL succeeded!');
211
211
+
const specialData = await specialResponse.json();
212
212
+
213
213
+
// Process the special response
214
214
+
const specialEntries = specialData.records
215
215
+
.map((record: any) => {
216
216
+
const text = record.value.text || '';
217
217
+
if (containsBannedWords(text)) return null;
218
218
+
219
219
+
return {
220
220
+
id: record.uri,
221
221
+
uri: record.uri,
222
222
+
cid: record.cid,
223
223
+
did: did,
224
224
+
text: sanitizeText(text),
225
225
+
emoji: record.value.emoji || '🚽',
226
226
+
created_at: record.value.createdAt
227
227
+
};
228
228
+
})
229
229
+
.filter((entry: ProfileEntry | null): entry is ProfileEntry => entry !== null);
230
230
+
231
231
+
// Calculate emoji stats
232
232
+
const specialEmojiCounts = new Map<string, number>();
233
233
+
specialEntries.forEach((entry: ProfileEntry) => {
234
234
+
const emoji = entry.emoji?.trim() || '🚽';
235
235
+
if (APPROVED_EMOJIS.includes(emoji)) {
236
236
+
specialEmojiCounts.set(emoji, (specialEmojiCounts.get(emoji) || 0) + 1);
237
237
+
} else {
238
238
+
specialEmojiCounts.set('🚽', (specialEmojiCounts.get('🚽') || 0) + 1);
239
239
+
}
240
240
+
});
241
241
+
242
242
+
const specialEmojiStats = Array.from(specialEmojiCounts.entries())
243
243
+
.map(([emoji, count]): EmojiStat => ({ emoji, count }))
244
244
+
.sort((a, b) => b.count - a.count);
245
245
+
246
246
+
return NextResponse.json({
247
247
+
entries: specialEntries,
248
248
+
count: specialEntries.length,
249
249
+
cursor: specialData.cursor,
250
250
+
profile: userProfile,
251
251
+
emojiStats: specialEmojiStats,
252
252
+
serviceEndpoint: 'https://lab.martianbase.net',
253
253
+
specialHandling: true
254
254
+
});
255
255
+
} else {
256
256
+
console.warn(`Special URL failed: ${specialResponse.status}`);
257
257
+
}
258
258
+
} catch (specialErr) {
259
259
+
console.error(`Error with special URL: ${specialErr}`);
260
260
+
}
261
261
+
}
262
262
+
198
263
// Some PDS services have different URL structures
199
264
const urls = [
200
265
`https://${servicePds}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`,
201
266
// Try without /xrpc prefix in case it's already in the hostname
202
267
`https://${servicePds}/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`,
268
268
+
// Try explicit lab subdomain if we're using martianbase.net
269
269
+
...(servicePds.includes('martianbase.net') ?
270
270
+
[`https://lab.martianbase.net/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=${encodeURIComponent(FLUSHING_STATUS_NSID)}&limit=${MAX_ENTRIES}`] :
271
271
+
[])
203
272
];
204
273
205
274
// Start with the most common pattern
···
603
672
});
604
673
}
605
674
675
675
+
// If we get a 404, return empty entries rather than an error
676
676
+
// This handles PDS servers that return 404 instead of empty arrays
677
677
+
if (error instanceof Error && error.message.includes('404')) {
678
678
+
console.log(`Returning empty entries list instead of 404 error for ${did}`);
679
679
+
return NextResponse.json({
680
680
+
entries: [],
681
681
+
count: 0,
682
682
+
profile: userProfile,
683
683
+
emojiStats: [],
684
684
+
did,
685
685
+
handle,
686
686
+
serviceEndpoint,
687
687
+
servicePds,
688
688
+
emptyCollection: true
689
689
+
});
690
690
+
}
691
691
+
606
692
return NextResponse.json(
607
607
-
{ error: `Failed to fetch records: ${error.message}` },
693
693
+
{
694
694
+
error: `Failed to fetch records: ${error.message}`,
695
695
+
did,
696
696
+
handle,
697
697
+
serviceEndpoint,
698
698
+
servicePds
699
699
+
},
608
700
{ status: 500 }
609
701
);
610
702
}