(sessionId: string, files: File[])
| 341 | |
| 342 | // Legacy upload function - can be removed if no longer needed |
| 343 | async uploadPDFs(sessionId: string, files: File[]): Promise<{ |
| 344 | message: string; |
| 345 | uploaded_files: any[]; |
| 346 | processing_results: any[]; |
| 347 | session_documents: any[]; |
| 348 | total_session_documents: number; |
| 349 | }> { |
| 350 | try { |
| 351 | // Test if files have content and show size info |
| 352 | let totalSize = 0; |
| 353 | for (const file of files) { |
| 354 | if (file.size === 0) { |
| 355 | throw new Error(`File ${file.name} is empty (0 bytes)`); |
| 356 | } |
| 357 | totalSize += file.size; |
| 358 | const sizeMB = (file.size / (1024 * 1024)).toFixed(2); |
| 359 | console.log(`📄 File ${file.name}: ${sizeMB}MB (${file.size} bytes), type: ${file.type}`); |
| 360 | } |
| 361 | |
| 362 | const totalSizeMB = (totalSize / (1024 * 1024)).toFixed(2); |
| 363 | console.log(`📄 Total upload size: ${totalSizeMB}MB`); |
| 364 | |
| 365 | if (totalSize > 50 * 1024 * 1024) { // 50MB limit |
| 366 | throw new Error(`Total file size ${totalSizeMB}MB exceeds 50MB limit`); |
| 367 | } |
| 368 | |
| 369 | const formData = new FormData(); |
| 370 | |
| 371 | // Use a generic field name 'file' that the backend expects |
| 372 | let i = 0; |
| 373 | for (const file of files) { |
| 374 | formData.append(`file_${i}`, file, file.name); |
| 375 | i++; |
| 376 | } |
| 377 | |
| 378 | const response = await fetch(`${API_BASE_URL}/sessions/${sessionId}/upload`, { |
| 379 | method: 'POST', |
| 380 | body: formData, |
| 381 | }); |
| 382 | |
| 383 | if (!response.ok) { |
| 384 | const errorData = await response.json().catch(() => ({ error: 'Unknown error' })); |
| 385 | throw new Error(`Upload error: ${errorData.error || response.statusText}`); |
| 386 | } |
| 387 | |
| 388 | return await response.json(); |
| 389 | } catch (error) { |
| 390 | console.error('PDF upload failed:', error); |
| 391 | throw error; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | // Convert database message format to ChatMessage format |
| 396 | convertDbMessage(dbMessage: Record<string, unknown>): ChatMessage { |
nothing calls this directly
no outgoing calls
no test coverage detected