From adb4ca9294b0809c9a3a61af98501e1c82c0dbea Mon Sep 17 00:00:00 2001 From: yangdx Date: Fri, 28 Mar 2025 16:49:35 +0800 Subject: [PATCH] Fix linting --- lightrag/api/routers/document_routes.py | 2 +- .../documents/UploadDocumentsDialog.tsx | 28 +++++++++---------- .../src/components/ui/FileUploader.tsx | 26 ++++++++--------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lightrag/api/routers/document_routes.py b/lightrag/api/routers/document_routes.py index 4b519628..445008ec 100644 --- a/lightrag/api/routers/document_routes.py +++ b/lightrag/api/routers/document_routes.py @@ -559,7 +559,7 @@ def create_document_routes( if file_path.exists(): return InsertResponse( status="duplicated", - message=f"File '{file.filename}' already exists in the input directory." + message=f"File '{file.filename}' already exists in the input directory.", ) with open(file_path, "wb") as buffer: diff --git a/lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx b/lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx index 5c9a99bd..977c4030 100644 --- a/lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx +++ b/lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx @@ -30,18 +30,18 @@ export default function UploadDocumentsDialog() { rejectedFiles.forEach(({ file, errors }) => { // Get the first error message let errorMsg = errors[0]?.message || t('documentPanel.uploadDocuments.fileUploader.fileRejected', { name: file.name }) - + // Simplify error message for unsupported file types if (errorMsg.includes('file-invalid-type')) { errorMsg = t('documentPanel.uploadDocuments.fileUploader.unsupportedType') } - + // Set progress to 100% to display error message setProgresses((pre) => ({ ...pre, [file.name]: 100 })) - + // Add error message to fileErrors setFileErrors(prev => ({ ...prev, @@ -55,7 +55,7 @@ export default function UploadDocumentsDialog() { const handleDocumentsUpload = useCallback( async (filesToUpload: File[]) => { setIsUploading(true) - + // Only clear errors for files that are being uploaded, keep errors for rejected files setFileErrors(prev => { const newErrors = { ...prev }; @@ -64,14 +64,14 @@ export default function UploadDocumentsDialog() { }); return newErrors; }); - + // Show uploading toast const toastId = toast.loading(t('documentPanel.uploadDocuments.batch.uploading')) - + try { // Track errors locally to ensure we have the final state const uploadErrors: Record = {} - + await Promise.all( filesToUpload.map(async (file) => { try { @@ -80,7 +80,7 @@ export default function UploadDocumentsDialog() { ...pre, [file.name]: 0 })) - + const result = await uploadDocument(file, (percentCompleted: number) => { console.debug(t('documentPanel.uploadDocuments.single.uploading', { name: file.name, percent: percentCompleted })) setProgresses((pre) => ({ @@ -104,10 +104,10 @@ export default function UploadDocumentsDialog() { } } catch (err) { console.error(`Upload failed for ${file.name}:`, err) - + // Handle HTTP errors, including 400 errors let errorMsg = errorMessage(err) - + // If it's an axios error with response data, try to extract more detailed error info if (err && typeof err === 'object' && 'response' in err) { const axiosError = err as { response?: { status: number, data?: { detail?: string } } } @@ -115,14 +115,14 @@ export default function UploadDocumentsDialog() { // Extract specific error message from backend response errorMsg = axiosError.response.data?.detail || errorMsg } - + // Set progress to 100% to display error message setProgresses((pre) => ({ ...pre, [file.name]: 100 })) } - + // Record error message in both local tracking and state uploadErrors[file.name] = errorMsg setFileErrors(prev => ({ @@ -132,10 +132,10 @@ export default function UploadDocumentsDialog() { } }) ) - + // Check if any files failed to upload using our local tracking const hasErrors = Object.keys(uploadErrors).length > 0 - + // Update toast status if (hasErrors) { toast.error(t('documentPanel.uploadDocuments.batch.error'), { id: toastId }) diff --git a/lightrag_webui/src/components/ui/FileUploader.tsx b/lightrag_webui/src/components/ui/FileUploader.tsx index 24c415dc..1e337d52 100644 --- a/lightrag_webui/src/components/ui/FileUploader.tsx +++ b/lightrag_webui/src/components/ui/FileUploader.tsx @@ -155,7 +155,7 @@ function FileUploader(props: FileUploaderProps) { (acceptedFiles: File[], rejectedFiles: FileRejection[]) => { // Calculate total file count including both accepted and rejected files const totalFileCount = (files?.length ?? 0) + acceptedFiles.length + rejectedFiles.length - + // Check file count limits if (!multiple && maxFileCount === 1 && (acceptedFiles.length + rejectedFiles.length) > 1) { toast.error(t('documentPanel.uploadDocuments.fileUploader.singleFileLimit')) @@ -186,19 +186,19 @@ function FileUploader(props: FileUploaderProps) { preview: URL.createObjectURL(file) }) ) - + // Process rejected files for UI display - const newRejectedFiles = rejectedFiles.map(({ file }) => + const newRejectedFiles = rejectedFiles.map(({ file }) => Object.assign(file, { preview: URL.createObjectURL(file), rejected: true }) ) - + // Combine all files for display const allNewFiles = [...newAcceptedFiles, ...newRejectedFiles] const updatedFiles = files ? [...files, ...allNewFiles] : allNewFiles - + // Update the files state with all files setFiles(updatedFiles) @@ -211,13 +211,13 @@ function FileUploader(props: FileUploaderProps) { const isAccepted = Object.entries(accept || {}).some(([mimeType, extensions]) => { return file.type === mimeType || extensions.includes(fileExt); }); - + // Check file size const isSizeValid = file.size <= maxSize; - + return isAccepted && isSizeValid; }); - + if (validFiles.length > 0) { onUpload(validFiles); } @@ -265,24 +265,24 @@ function FileUploader(props: FileUploaderProps) { const isAccepted = Object.entries(accept || {}).some(([mimeType, extensions]) => { return file.type === mimeType || extensions.includes(fileExt); }); - + if (!isAccepted) { return { code: 'file-invalid-type', message: t('documentPanel.uploadDocuments.fileUploader.unsupportedType') }; } - + // Check file size if (file.size > maxSize) { return { code: 'file-too-large', - message: t('documentPanel.uploadDocuments.fileUploader.fileTooLarge', { - maxSize: formatBytes(maxSize) + message: t('documentPanel.uploadDocuments.fileUploader.fileTooLarge', { + maxSize: formatBytes(maxSize) }) }; } - + return null; }} >