js -> ts
This commit is contained in:
@@ -24,6 +24,7 @@ interface LinkPreviewMeta {
|
||||
type: string | null;
|
||||
video: string | null;
|
||||
themeColor: string | null;
|
||||
trusted: boolean;
|
||||
}
|
||||
|
||||
// Trusted domains that can be loaded client-side
|
||||
@@ -73,6 +74,7 @@ function parseMetaTags(html: string, url: string): LinkPreviewMeta {
|
||||
type: null,
|
||||
video: null,
|
||||
themeColor: null,
|
||||
trusted: false,
|
||||
};
|
||||
|
||||
const decode = str => str?.replace(/&(#(?:x[0-9a-fA-F]+|\d+)|[a-zA-Z]+);/g,
|
||||
@@ -253,6 +255,13 @@ export async function GET({ request }) {
|
||||
}
|
||||
|
||||
// Read first 50KB
|
||||
if (!response.body) {
|
||||
return new Response(JSON.stringify({ error: 'Empty response body' }), {
|
||||
status: 502,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
const reader = response.body.getReader();
|
||||
let html = '';
|
||||
let bytesRead = 0;
|
||||
@@ -281,7 +290,8 @@ export async function GET({ request }) {
|
||||
return resp;
|
||||
|
||||
} catch (err) {
|
||||
console.error('[link-preview] Error fetching URL:', err.message);
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
console.error('[link-preview] Error fetching URL:', message);
|
||||
// Don't expose internal error details to client
|
||||
return new Response(JSON.stringify({ error: 'Failed to fetch preview' }), {
|
||||
status: 500,
|
||||
|
||||
Reference in New Issue
Block a user