Merged in feature/support-more-types (pull request #219)
support new types for import * tests pass * missing file * bug fixes
This commit is contained in:
@@ -28,6 +28,30 @@ const (
|
||||
ConfigKeyUploadHandler = "uploadHandler"
|
||||
)
|
||||
|
||||
// acceptedExtensions defines the file extensions allowed in batch uploads.
|
||||
// Macro-enabled extensions (.docm, .xlsm, .pptm) are intentionally excluded --
|
||||
// documents with macros are rejected, so users must save as standard formats first.
|
||||
var acceptedExtensions = map[string]bool{
|
||||
".pdf": true,
|
||||
".tiff": true,
|
||||
".tif": true,
|
||||
".jpeg": true,
|
||||
".jpg": true,
|
||||
".png": true,
|
||||
".bmp": true,
|
||||
".docx": true,
|
||||
".xlsx": true,
|
||||
".pptx": true,
|
||||
".txt": true,
|
||||
".eml": true,
|
||||
}
|
||||
|
||||
// isAcceptedExtension checks if a filename has a supported file extension.
|
||||
func isAcceptedExtension(filename string) bool {
|
||||
ext := strings.ToLower(path.Ext(filename))
|
||||
return acceptedExtensions[ext]
|
||||
}
|
||||
|
||||
// sanitizeZipPath cleans a path from a zip file to prevent path traversal attacks
|
||||
// while preserving the internal folder structure.
|
||||
// Returns empty string if the path is invalid or attempts traversal.
|
||||
@@ -194,6 +218,12 @@ func processSingleBatch(
|
||||
invalidInt32 = maxInt32 // Max int32 value
|
||||
}
|
||||
|
||||
// Set total document count now that all files have been extracted
|
||||
totalInt32 := processedInt32 + failedInt32 + invalidInt32
|
||||
if err := batchService.SetTotalDocuments(ctx, batchInfo.ID, totalInt32); err != nil {
|
||||
logger.Error("Failed to set batch total documents", "batch_id", batchInfo.ID, "error", err)
|
||||
}
|
||||
|
||||
if err := batchService.UpdateProgress(ctx, batchInfo.ClientID, batchInfo.ID,
|
||||
processedInt32, failedInt32, invalidInt32); err != nil {
|
||||
logger.Error("Failed to update batch progress", "batch_id", batchInfo.ID, "error", err)
|
||||
@@ -320,8 +350,8 @@ func processZipFile(
|
||||
return 0, 1, 0
|
||||
}
|
||||
|
||||
// Check if file type is valid (PDF only for now)
|
||||
if !strings.HasSuffix(strings.ToLower(filename), ".pdf") {
|
||||
// Check if file type is supported
|
||||
if !isAcceptedExtension(filename) {
|
||||
logger.Warn("Invalid file type", "filename", filename)
|
||||
_ = batchService.AddFailedFilename(ctx, batchInfo.ID, filename)
|
||||
_ = batchService.RecordOutcome(ctx, batchInfo.ID, filename, repository.BatchOutcomeStatusInvalidType, nil, nil)
|
||||
|
||||
Reference in New Issue
Block a user