This commit is contained in:
@@ -130,9 +130,21 @@ public class ApiController {
|
|||||||
|
|
||||||
return buildSuccessResponse(uploadId, chunkNumber, chunk);
|
return buildSuccessResponse(uploadId, chunkNumber, chunk);
|
||||||
} catch (DuplicateImageException e) {
|
} 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(),
|
MessageCode.DUPLICATE_FILE_UPLOAD.getDescription(),
|
||||||
Map.of("duplicateOwnerId", e.userId(), "duplicateFileId", e.duplicateFileId())));
|
duplicateData
|
||||||
|
));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error uploading chunk", e);
|
log.error("Error uploading chunk", e);
|
||||||
return buildErrorResponse(uploadId, chunkNumber, "Failed to upload chunk: " + e.getMessage());
|
return buildErrorResponse(uploadId, chunkNumber, "Failed to upload chunk: " + e.getMessage());
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkForDuplicatesSynchronously(String filePath)
|
private void checkForDuplicatesSynchronously(String filePath)
|
||||||
throws IOException {
|
throws IOException , DuplicateImageException {
|
||||||
Path path = Paths.get(filePath);
|
Path path = Paths.get(filePath);
|
||||||
Map<String, Long> hash = imageHashService.calculateHash(path);
|
Map<String, Long> hash = imageHashService.calculateHash(path);
|
||||||
|
|
||||||
@@ -390,8 +390,8 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
hash.get("hi"), hash.get("low"));
|
hash.get("hi"), hash.get("low"));
|
||||||
|
|
||||||
if (!duplicates.isEmpty()) {
|
if (!duplicates.isEmpty()) {
|
||||||
throw new DuplicateImageException("Duplicate", duplicates.get(0).getId(),
|
throw new DuplicateImageException("Duplicate", duplicates.getFirst().getId(),
|
||||||
duplicates.get(0).getUserId());
|
duplicates.getFirst().getUserId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user