const BACKEND_URL = '/api/upload'; interface BatchItem { id: string; file: File; path: string; } export const uploadBatchToHub = async (items: BatchItem[]): Promise => { const formData = new FormData(); // Optimized append loop for (const item of items) { formData.append('paths', item.path); formData.append('files', item.file); } try { const response = await fetch(BACKEND_URL, { method: 'POST', body: formData, }); const contentType = response.headers.get("content-type"); if (!contentType || !contentType.includes("application/json")) { const text = await response.text(); console.error("Non-JSON Response:", text); throw new Error(`Server returned unexpected status ${response.status}. Check server logs.`); } const data = await response.json(); if (!response.ok || !data.success) { throw new Error(data.error || 'Upload failed on server'); } return data.urls; } catch (err: any) { // Retry logic could be added here if needed throw new Error(err?.message || "Connection failed"); } };