Fix for url previews

This commit is contained in:
Christopher
2026-01-22 13:25:15 -08:00
parent 67a97ea8c4
commit fc86bc1901
2 changed files with 14 additions and 8 deletions
+13 -7
View File
@@ -14,15 +14,21 @@ export async function GET(req: NextRequest) {
url = 'https://' + url; url = 'https://' + url;
} }
const response = await fetch(url, { let response;
headers: { try {
'User-Agent': 'SynapsisBot/1.0', response = await fetch(url, {
}, headers: {
signal: AbortSignal.timeout(5000), // 5s timeout 'User-Agent': 'SynapsisBot/1.0',
}); },
signal: AbortSignal.timeout(5000), // 5s timeout
});
} catch (fetchError) {
console.warn(`Fetch failed for URL: ${url}`, fetchError);
return NextResponse.json({ error: 'Could not reach the URL' }, { status: 404 });
}
if (!response.ok) { if (!response.ok) {
throw new Error(`Failed to fetch URL: ${response.status}`); return NextResponse.json({ error: `URL returned status ${response.status}` }, { status: 404 });
} }
const html = await response.text(); const html = await response.text();
+1 -1
View File
@@ -230,7 +230,7 @@ function Compose({ onPost }: { onPost: (content: string, mediaIds: string[], lin
// Detect URLs in content // Detect URLs in content
useEffect(() => { useEffect(() => {
const urlRegex = /(?:https?:\/\/)?(?:www\.)?([a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+\.[a-z]{2,63})\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi; const urlRegex = /(?:https?:\/\/)?((?:[a-zA-Z0-9-]+\.)+[a-z]{2,63})\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi;
const matches = content.match(urlRegex); const matches = content.match(urlRegex);
if (matches && matches[0]) { if (matches && matches[0]) {