NCBACK-25 fix check duplicate exception
Test Workflow / test (push) Successful in 3s

This commit is contained in:
vladp
2026-01-25 19:59:16 +07:00
parent 69a79b7ac7
commit 76103b9d96
2 changed files with 17 additions and 5 deletions
@@ -130,9 +130,21 @@ public class ApiController {
return buildSuccessResponse(uploadId, chunkNumber, chunk);
} catch (DuplicateImageException e) {
return ResponseEntity.ok().body(new BaseResponse(20004, MessageCode.DUPLICATE_FILE_UPLOAD.getCode(),
Map<String, Object> duplicateData = new HashMap<>();
duplicateData.put("duplicateFileId", e.duplicateFileId());
duplicateData.put("userId", e.userId());
duplicateData.put("message", e.getMessage());
if (uploadId != null) {
duplicateData.put("uploadId", uploadId);
}
return ResponseEntity.ok().body(new BaseResponse(
20004,
MessageCode.DUPLICATE_FILE_UPLOAD.getCode(),
MessageCode.DUPLICATE_FILE_UPLOAD.getDescription(),
Map.of("duplicateOwnerId", e.userId(), "duplicateFileId", e.duplicateFileId())));
duplicateData
));
} catch (Exception e) {
log.error("Error uploading chunk", e);
return buildErrorResponse(uploadId, chunkNumber, "Failed to upload chunk: " + e.getMessage());
@@ -382,7 +382,7 @@ public class FileUploadServiceImpl implements FileUploadService {
}
private void checkForDuplicatesSynchronously(String filePath)
throws IOException {
throws IOException , DuplicateImageException {
Path path = Paths.get(filePath);
Map<String, Long> hash = imageHashService.calculateHash(path);
@@ -390,8 +390,8 @@ public class FileUploadServiceImpl implements FileUploadService {
hash.get("hi"), hash.get("low"));
if (!duplicates.isEmpty()) {
throw new DuplicateImageException("Duplicate", duplicates.get(0).getId(),
duplicates.get(0).getUserId());
throw new DuplicateImageException("Duplicate", duplicates.getFirst().getId(),
duplicates.getFirst().getUserId());
}
}