yangdx
commited on
Commit
·
ae64c4f
1
Parent(s):
cfd1740
Feat: add duplicate file check
Browse files- lightrag/api/routers/document_routes.py +8 -0
- lightrag_webui/src/api/lightrag.ts +1 -1
- lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx +7 -1
- lightrag_webui/src/locales/ar.json +2 -1
- lightrag_webui/src/locales/en.json +2 -1
- lightrag_webui/src/locales/fr.json +2 -1
- lightrag_webui/src/locales/zh.json +2 -1
lightrag/api/routers/document_routes.py
CHANGED
@@ -542,6 +542,7 @@ def create_document_routes(
|
|
542 |
|
543 |
Returns:
|
544 |
InsertResponse: A response object containing the upload status and a message.
|
|
|
545 |
|
546 |
Raises:
|
547 |
HTTPException: If the file type is not supported (400) or other errors occur (500).
|
@@ -554,6 +555,13 @@ def create_document_routes(
|
|
554 |
)
|
555 |
|
556 |
file_path = doc_manager.input_dir / file.filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
with open(file_path, "wb") as buffer:
|
558 |
shutil.copyfileobj(file.file, buffer)
|
559 |
|
|
|
542 |
|
543 |
Returns:
|
544 |
InsertResponse: A response object containing the upload status and a message.
|
545 |
+
status can be "success", "duplicated", or error is thrown.
|
546 |
|
547 |
Raises:
|
548 |
HTTPException: If the file type is not supported (400) or other errors occur (500).
|
|
|
555 |
)
|
556 |
|
557 |
file_path = doc_manager.input_dir / file.filename
|
558 |
+
# Check if file already exists
|
559 |
+
if file_path.exists():
|
560 |
+
return InsertResponse(
|
561 |
+
status="duplicated",
|
562 |
+
message=f"File '{file.filename}' already exists in the input directory."
|
563 |
+
)
|
564 |
+
|
565 |
with open(file_path, "wb") as buffer:
|
566 |
shutil.copyfileobj(file.file, buffer)
|
567 |
|
lightrag_webui/src/api/lightrag.ts
CHANGED
@@ -109,7 +109,7 @@ export type QueryResponse = {
|
|
109 |
}
|
110 |
|
111 |
export type DocActionResponse = {
|
112 |
-
status: 'success' | 'partial_success' | 'failure'
|
113 |
message: string
|
114 |
}
|
115 |
|
|
|
109 |
}
|
110 |
|
111 |
export type DocActionResponse = {
|
112 |
+
status: 'success' | 'partial_success' | 'failure' | 'duplicated'
|
113 |
message: string
|
114 |
}
|
115 |
|
lightrag_webui/src/components/documents/UploadDocumentsDialog.tsx
CHANGED
@@ -89,7 +89,13 @@ export default function UploadDocumentsDialog() {
|
|
89 |
}))
|
90 |
})
|
91 |
|
92 |
-
if (result.status
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
uploadErrors[file.name] = result.message
|
94 |
setFileErrors(prev => ({
|
95 |
...prev,
|
|
|
89 |
}))
|
90 |
})
|
91 |
|
92 |
+
if (result.status === 'duplicated') {
|
93 |
+
uploadErrors[file.name] = t('documentPanel.uploadDocuments.fileUploader.duplicateFile')
|
94 |
+
setFileErrors(prev => ({
|
95 |
+
...prev,
|
96 |
+
[file.name]: t('documentPanel.uploadDocuments.fileUploader.duplicateFile')
|
97 |
+
}))
|
98 |
+
} else if (result.status !== 'success') {
|
99 |
uploadErrors[file.name] = result.message
|
100 |
setFileErrors(prev => ({
|
101 |
...prev,
|
lightrag_webui/src/locales/ar.json
CHANGED
@@ -70,7 +70,8 @@
|
|
70 |
"dropHere": "أفلت الملفات هنا",
|
71 |
"dragAndDrop": "اسحب وأفلت الملفات هنا، أو انقر للاختيار",
|
72 |
"removeFile": "إزالة الملف",
|
73 |
-
"uploadDescription": "يمكنك رفع {{isMultiple ? 'عدة' : count}} ملفات (حتى {{maxSize}} لكل منها)"
|
|
|
74 |
}
|
75 |
},
|
76 |
"documentManager": {
|
|
|
70 |
"dropHere": "أفلت الملفات هنا",
|
71 |
"dragAndDrop": "اسحب وأفلت الملفات هنا، أو انقر للاختيار",
|
72 |
"removeFile": "إزالة الملف",
|
73 |
+
"uploadDescription": "يمكنك رفع {{isMultiple ? 'عدة' : count}} ملفات (حتى {{maxSize}} لكل منها)",
|
74 |
+
"duplicateFile": "اسم الملف موجود بالفعل في ذاكرة التخزين المؤقت للخادم"
|
75 |
}
|
76 |
},
|
77 |
"documentManager": {
|
lightrag_webui/src/locales/en.json
CHANGED
@@ -70,7 +70,8 @@
|
|
70 |
"dropHere": "Drop the files here",
|
71 |
"dragAndDrop": "Drag and drop files here, or click to select files",
|
72 |
"removeFile": "Remove file",
|
73 |
-
"uploadDescription": "You can upload {{isMultiple ? 'multiple' : count}} files (up to {{maxSize}} each)"
|
|
|
74 |
}
|
75 |
},
|
76 |
"documentManager": {
|
|
|
70 |
"dropHere": "Drop the files here",
|
71 |
"dragAndDrop": "Drag and drop files here, or click to select files",
|
72 |
"removeFile": "Remove file",
|
73 |
+
"uploadDescription": "You can upload {{isMultiple ? 'multiple' : count}} files (up to {{maxSize}} each)",
|
74 |
+
"duplicateFile": "File name already exists in server cache"
|
75 |
}
|
76 |
},
|
77 |
"documentManager": {
|
lightrag_webui/src/locales/fr.json
CHANGED
@@ -70,7 +70,8 @@
|
|
70 |
"dropHere": "Déposez les fichiers ici",
|
71 |
"dragAndDrop": "Glissez et déposez les fichiers ici, ou cliquez pour sélectionner",
|
72 |
"removeFile": "Supprimer le fichier",
|
73 |
-
"uploadDescription": "Vous pouvez télécharger {{isMultiple ? 'plusieurs' : count}} fichiers (jusqu'à {{maxSize}} chacun)"
|
|
|
74 |
}
|
75 |
},
|
76 |
"documentManager": {
|
|
|
70 |
"dropHere": "Déposez les fichiers ici",
|
71 |
"dragAndDrop": "Glissez et déposez les fichiers ici, ou cliquez pour sélectionner",
|
72 |
"removeFile": "Supprimer le fichier",
|
73 |
+
"uploadDescription": "Vous pouvez télécharger {{isMultiple ? 'plusieurs' : count}} fichiers (jusqu'à {{maxSize}} chacun)",
|
74 |
+
"duplicateFile": "Le nom du fichier existe déjà dans le cache du serveur"
|
75 |
}
|
76 |
},
|
77 |
"documentManager": {
|
lightrag_webui/src/locales/zh.json
CHANGED
@@ -70,7 +70,8 @@
|
|
70 |
"dropHere": "将文件拖放到此处",
|
71 |
"dragAndDrop": "拖放文件到此处,或点击选择文件",
|
72 |
"removeFile": "移除文件",
|
73 |
-
"uploadDescription": "您可以上传{{isMultiple ? '多个' : count}}个文件(每个文件最大{{maxSize}})"
|
|
|
74 |
}
|
75 |
},
|
76 |
"documentManager": {
|
|
|
70 |
"dropHere": "将文件拖放到此处",
|
71 |
"dragAndDrop": "拖放文件到此处,或点击选择文件",
|
72 |
"removeFile": "移除文件",
|
73 |
+
"uploadDescription": "您可以上传{{isMultiple ? '多个' : count}}个文件(每个文件最大{{maxSize}})",
|
74 |
+
"duplicateFile": "文件名与服务器上的缓存重复"
|
75 |
}
|
76 |
},
|
77 |
"documentManager": {
|