This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user