11import { error } from "@sveltejs/kit" ;
22import { logger } from "$lib/server/logger.js" ;
3+ import { fetch } from "undici" ;
34
45const MAX_FILE_SIZE = 10 * 1024 * 1024 ; // 10MB
56const FETCH_TIMEOUT = 30000 ; // 30 seconds
@@ -30,7 +31,7 @@ function isValidUrl(urlString: string): boolean {
3031 }
3132}
3233
33- export async function GET ( { url, fetch } ) {
34+ export async function GET ( { url } ) {
3435 const targetUrl = url . searchParams . get ( "url" ) ;
3536
3637 if ( ! targetUrl ) {
@@ -48,19 +49,13 @@ export async function GET({ url, fetch }) {
4849 const controller = new AbortController ( ) ;
4950 const timeoutId = setTimeout ( ( ) => controller . abort ( ) , FETCH_TIMEOUT ) ;
5051
51- logger . debug ( { targetUrl } , "Fetching url" ) ;
5252 const response = await fetch ( targetUrl , {
5353 signal : controller . signal ,
5454 headers : {
5555 "User-Agent" : "HuggingChat-Attachment-Fetcher/1.0" ,
5656 } ,
5757 } ) . finally ( ( ) => clearTimeout ( timeoutId ) ) ;
5858
59- logger . debug (
60- { targetUrl, responseHeaders : JSON . stringify ( response . headers ) } ,
61- "URL fetch debug"
62- ) ;
63-
6459 if ( ! response . ok ) {
6560 logger . error ( { targetUrl, response } , `Error fetching URL. Response not ok.` ) ;
6661 throw error ( response . status , `Failed to fetch: ${ response . statusText } ` ) ;
0 commit comments