diff --git a/lightrag/api/routers/document_routes.py b/lightrag/api/routers/document_routes.py index d6434e08..4b519628 100644 --- a/lightrag/api/routers/document_routes.py +++ b/lightrag/api/routers/document_routes.py @@ -542,6 +542,7 @@ def create_document_routes( Returns: InsertResponse: A response object containing the upload status and a message. + status can be "success", "duplicated", or error is thrown. Raises: HTTPException: If the file type is not supported (400) or other errors occur (500). @@ -554,6 +555,13 @@ def create_document_routes( ) file_path = doc_manager.input_dir / file.filename + # Check if file already exists + if file_path.exists(): + return InsertResponse( + status="duplicated", + message=f"File '{file.filename}' already exists in the input directory." + ) + with open(file_path, "wb") as buffer: shutil.copyfileobj(file.file, buffer) diff --git a/lightrag_webui/src/api/lightrag.ts b/lightrag_webui/src/api/lightrag.ts index 8b59ccbf..364ecb44 100644 --- a/lightrag_webui/src/api/lightrag.ts +++ b/lightrag_webui/src/api/lightrag.ts @@ -109,7 +109,7 @@ export type QueryResponse = { } export type DocActionResponse = { - status: 'success' | 'partial_success' | 'failure' + status: 'success' | 'partial_success' | 'failure' | 'duplicated' message: string } diff --git a/lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx b/lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx index bf1d00b7..5c9a99bd 100644 --- a/lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx +++ b/lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx @@ -89,7 +89,13 @@ export default function UploadDocumentsDialog() { })) }) - if (result.status !== 'success') { + if (result.status === 'duplicated') { + uploadErrors[file.name] = t('documentPanel.uploadDocuments.fileUploader.duplicateFile') + setFileErrors(prev => ({ + ...prev, + [file.name]: t('documentPanel.uploadDocuments.fileUploader.duplicateFile') + })) + } else if (result.status !== 'success') { uploadErrors[file.name] = result.message setFileErrors(prev => ({ ...prev, diff --git a/lightrag_webui/src/locales/ar.json b/lightrag_webui/src/locales/ar.json index 1775b1c5..f4e8f316 100644 --- a/lightrag_webui/src/locales/ar.json +++ b/lightrag_webui/src/locales/ar.json @@ -70,7 +70,8 @@ "dropHere": "أفلت الملفات هنا", "dragAndDrop": "اسحب وأفلت الملفات هنا، أو انقر للاختيار", "removeFile": "إزالة الملف", - "uploadDescription": "يمكنك رفع {{isMultiple ? 'عدة' : count}} ملفات (حتى {{maxSize}} لكل منها)" + "uploadDescription": "يمكنك رفع {{isMultiple ? 'عدة' : count}} ملفات (حتى {{maxSize}} لكل منها)", + "duplicateFile": "اسم الملف موجود بالفعل في ذاكرة التخزين المؤقت للخادم" } }, "documentManager": { diff --git a/lightrag_webui/src/locales/en.json b/lightrag_webui/src/locales/en.json index 7d89f040..a48eded3 100644 --- a/lightrag_webui/src/locales/en.json +++ b/lightrag_webui/src/locales/en.json @@ -70,7 +70,8 @@ "dropHere": "Drop the files here", "dragAndDrop": "Drag and drop files here, or click to select files", "removeFile": "Remove file", - "uploadDescription": "You can upload {{isMultiple ? 'multiple' : count}} files (up to {{maxSize}} each)" + "uploadDescription": "You can upload {{isMultiple ? 'multiple' : count}} files (up to {{maxSize}} each)", + "duplicateFile": "File name already exists in server cache" } }, "documentManager": { diff --git a/lightrag_webui/src/locales/fr.json b/lightrag_webui/src/locales/fr.json index 0c56f524..600503ee 100644 --- a/lightrag_webui/src/locales/fr.json +++ b/lightrag_webui/src/locales/fr.json @@ -70,7 +70,8 @@ "dropHere": "Déposez les fichiers ici", "dragAndDrop": "Glissez et déposez les fichiers ici, ou cliquez pour sélectionner", "removeFile": "Supprimer le fichier", - "uploadDescription": "Vous pouvez télécharger {{isMultiple ? 'plusieurs' : count}} fichiers (jusqu'à {{maxSize}} chacun)" + "uploadDescription": "Vous pouvez télécharger {{isMultiple ? 'plusieurs' : count}} fichiers (jusqu'à {{maxSize}} chacun)", + "duplicateFile": "Le nom du fichier existe déjà dans le cache du serveur" } }, "documentManager": { diff --git a/lightrag_webui/src/locales/zh.json b/lightrag_webui/src/locales/zh.json index 23389f47..6f182f38 100644 --- a/lightrag_webui/src/locales/zh.json +++ b/lightrag_webui/src/locales/zh.json @@ -70,7 +70,8 @@ "dropHere": "将文件拖放到此处", "dragAndDrop": "拖放文件到此处,或点击选择文件", "removeFile": "移除文件", - "uploadDescription": "您可以上传{{isMultiple ? '多个' : count}}个文件(每个文件最大{{maxSize}})" + "uploadDescription": "您可以上传{{isMultiple ? '多个' : count}}个文件(每个文件最大{{maxSize}})", + "duplicateFile": "文件名与服务器上的缓存重复" } }, "documentManager": {