Feat: add duplicate file check
This commit is contained in:
@@ -542,6 +542,7 @@ def create_document_routes(
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
InsertResponse: A response object containing the upload status and a message.
|
InsertResponse: A response object containing the upload status and a message.
|
||||||
|
status can be "success", "duplicated", or error is thrown.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
HTTPException: If the file type is not supported (400) or other errors occur (500).
|
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
|
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:
|
with open(file_path, "wb") as buffer:
|
||||||
shutil.copyfileobj(file.file, buffer)
|
shutil.copyfileobj(file.file, buffer)
|
||||||
|
|
||||||
|
@@ -109,7 +109,7 @@ export type QueryResponse = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type DocActionResponse = {
|
export type DocActionResponse = {
|
||||||
status: 'success' | 'partial_success' | 'failure'
|
status: 'success' | 'partial_success' | 'failure' | 'duplicated'
|
||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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
|
uploadErrors[file.name] = result.message
|
||||||
setFileErrors(prev => ({
|
setFileErrors(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
|
@@ -70,7 +70,8 @@
|
|||||||
"dropHere": "أفلت الملفات هنا",
|
"dropHere": "أفلت الملفات هنا",
|
||||||
"dragAndDrop": "اسحب وأفلت الملفات هنا، أو انقر للاختيار",
|
"dragAndDrop": "اسحب وأفلت الملفات هنا، أو انقر للاختيار",
|
||||||
"removeFile": "إزالة الملف",
|
"removeFile": "إزالة الملف",
|
||||||
"uploadDescription": "يمكنك رفع {{isMultiple ? 'عدة' : count}} ملفات (حتى {{maxSize}} لكل منها)"
|
"uploadDescription": "يمكنك رفع {{isMultiple ? 'عدة' : count}} ملفات (حتى {{maxSize}} لكل منها)",
|
||||||
|
"duplicateFile": "اسم الملف موجود بالفعل في ذاكرة التخزين المؤقت للخادم"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"documentManager": {
|
"documentManager": {
|
||||||
|
@@ -70,7 +70,8 @@
|
|||||||
"dropHere": "Drop the files here",
|
"dropHere": "Drop the files here",
|
||||||
"dragAndDrop": "Drag and drop files here, or click to select files",
|
"dragAndDrop": "Drag and drop files here, or click to select files",
|
||||||
"removeFile": "Remove file",
|
"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": {
|
"documentManager": {
|
||||||
|
@@ -70,7 +70,8 @@
|
|||||||
"dropHere": "Déposez les fichiers ici",
|
"dropHere": "Déposez les fichiers ici",
|
||||||
"dragAndDrop": "Glissez et déposez les fichiers ici, ou cliquez pour sélectionner",
|
"dragAndDrop": "Glissez et déposez les fichiers ici, ou cliquez pour sélectionner",
|
||||||
"removeFile": "Supprimer le fichier",
|
"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": {
|
"documentManager": {
|
||||||
|
@@ -70,7 +70,8 @@
|
|||||||
"dropHere": "将文件拖放到此处",
|
"dropHere": "将文件拖放到此处",
|
||||||
"dragAndDrop": "拖放文件到此处,或点击选择文件",
|
"dragAndDrop": "拖放文件到此处,或点击选择文件",
|
||||||
"removeFile": "移除文件",
|
"removeFile": "移除文件",
|
||||||
"uploadDescription": "您可以上传{{isMultiple ? '多个' : count}}个文件(每个文件最大{{maxSize}})"
|
"uploadDescription": "您可以上传{{isMultiple ? '多个' : count}}个文件(每个文件最大{{maxSize}})",
|
||||||
|
"duplicateFile": "文件名与服务器上的缓存重复"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"documentManager": {
|
"documentManager": {
|
||||||
|
Reference in New Issue
Block a user