Pre Kiro
This commit is contained in:
@@ -390,91 +390,7 @@ class DocumentService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy multipart upload method (kept for compatibility)
|
||||
*/
|
||||
async uploadDocumentLegacy(
|
||||
file: File,
|
||||
onProgress?: (progress: number) => void,
|
||||
signal?: AbortSignal
|
||||
): Promise<Document> {
|
||||
try {
|
||||
// Check authentication before upload
|
||||
const token = await authService.getToken();
|
||||
if (!token) {
|
||||
throw new Error('Authentication required. Please log in to upload documents.');
|
||||
}
|
||||
|
||||
console.log('📤 Starting legacy multipart upload...');
|
||||
console.log('📤 File:', file.name, 'Size:', file.size, 'Type:', file.type);
|
||||
console.log('📤 Token available:', !!token);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('document', file);
|
||||
|
||||
// Always use optimized agentic RAG processing - no strategy selection needed
|
||||
formData.append('processingStrategy', 'optimized_agentic_rag');
|
||||
|
||||
const response = await apiClient.post('/documents/upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
signal, // Add abort signal support
|
||||
onUploadProgress: (progressEvent) => {
|
||||
if (onProgress && progressEvent.total) {
|
||||
const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
||||
onProgress(progress);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
console.log('✅ Legacy document upload successful:', response.data);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error('❌ Legacy document upload failed:', error);
|
||||
|
||||
// Provide more specific error messages
|
||||
if (error.response?.status === 401) {
|
||||
if (error.response?.data?.error === 'No valid authorization header') {
|
||||
throw new Error('Authentication required. Please log in to upload documents.');
|
||||
} else if (error.response?.data?.error === 'Token expired') {
|
||||
throw new Error('Your session has expired. Please log in again.');
|
||||
} else if (error.response?.data?.error === 'Invalid token') {
|
||||
throw new Error('Authentication failed. Please log in again.');
|
||||
} else {
|
||||
throw new Error('Authentication error. Please log in again.');
|
||||
}
|
||||
} else if (error.response?.status === 400) {
|
||||
if (error.response?.data?.error === 'No file uploaded') {
|
||||
throw new Error('No file was selected for upload.');
|
||||
} else if (error.response?.data?.error === 'File too large') {
|
||||
throw new Error('File is too large. Please select a smaller file.');
|
||||
} else if (error.response?.data?.error === 'File type not allowed') {
|
||||
throw new Error('File type not supported. Please upload a PDF or text file.');
|
||||
} else {
|
||||
throw new Error(`Upload failed: ${error.response?.data?.error || 'Bad request'}`);
|
||||
}
|
||||
} else if (error.response?.status === 413) {
|
||||
throw new Error('File is too large. Please select a smaller file.');
|
||||
} else if (error.response?.status >= 500) {
|
||||
throw new Error('Server error. Please try again later.');
|
||||
} else if (error.code === 'ERR_NETWORK') {
|
||||
throw new Error('Network error. Please check your connection and try again.');
|
||||
} else if (error.name === 'AbortError') {
|
||||
throw new Error('Upload was cancelled.');
|
||||
}
|
||||
|
||||
// Handle GCS-specific errors
|
||||
if (error.response?.data?.type === 'storage_error' ||
|
||||
error.message?.includes('GCS') ||
|
||||
error.message?.includes('storage.googleapis.com')) {
|
||||
throw GCSErrorHandler.createGCSError(error, 'upload');
|
||||
}
|
||||
|
||||
// Generic error fallback
|
||||
throw new Error(error.response?.data?.error || error.message || 'Upload failed');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all documents for the current user
|
||||
|
||||
Reference in New Issue
Block a user