|
|
| const BACKEND_URL = '/api/upload'; |
|
|
| interface BatchItem { |
| id: string; |
| file: File; |
| path: string; |
| } |
|
|
| export const uploadBatchToHub = async (items: BatchItem[]): Promise<string[]> => { |
| const formData = new FormData(); |
|
|
| |
| 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) { |
| |
| throw new Error(err?.message || "Connection failed"); |
| } |
| }; |
|
|