dev add violation link
Test Workflow / test (push) Successful in 2s

This commit is contained in:
vladp
2026-04-07 16:43:08 +07:00
parent 29ed74745f
commit a8a7a78ebf
2 changed files with 9 additions and 18 deletions
@@ -215,6 +215,7 @@ public class ApiController {
NoCopyCheckResult checkResult = noCopyFileService.checkFile(file, FileProtector.Type.IMAGE);
log.info("checkResult: {}", checkResult);
return ResponseEntity.ok(new BaseResponse(1, 1, "1", checkResult));
}
@@ -383,9 +383,9 @@ public class FileUploadServiceImpl implements FileUploadService {
String finalFilePath = assembleFileSynchronously(session);
if (findSimilar == 0) {
// if (session.getFileType().startsWith("image")) {
// checkForDuplicatesSynchronously(finalFilePath);
// } else if (session.getFileType().startsWith("audio") || session.getFileType().startsWith("document")) {
if (session.getFileType().startsWith("image")) {
checkForDuplicatesSynchronously(finalFilePath);
} else if (session.getFileType().startsWith("audio") || session.getFileType().startsWith("document")) {
fileSimilarityService.hasDuplicatesByHash(finalFilePath ,session.getFileType(),
session.getUserId());
@@ -400,13 +400,9 @@ public class FileUploadServiceImpl implements FileUploadService {
throw new FileFormatException("Failed to upload chunk: .wav file not have RIFF header or " +
"another problems with .wav file");
}
FileProtector.Type type = FileProtector.Type.IMAGE;
if (session.getFileType().startsWith("audio")) type = FileProtector.Type.AUDIO;
if (session.getFileType().startsWith("document")) type = FileProtector.Type.DOC;
// FileProtector.Type type = "document".equals(session.getFileType()) ?
// FileProtector.Type.DOC : FileProtector.Type.valueOf(session.getFileType().toUpperCase());
FileProtector.Type type = "document".equals(session.getFileType()) ?
FileProtector.Type.DOC : FileProtector.Type.valueOf(session.getFileType().toUpperCase());
NoCopyCheckResult checkResult = noCopyFileService.checkFile(file, type);
switch (checkResult) {
@@ -422,19 +418,13 @@ public class FileUploadServiceImpl implements FileUploadService {
Long.valueOf(info.getOwnerId()));
}
case ImageCheckResult.Success success -> {
FileProtector.FileInfo info = success.getInfo();
throw new DuplicateImageException("Duplicate", info.getId(),
Long.valueOf(info.getOwnerId()));
}
case DocumentCheckResult.Failed failed ->
log.warn("Document check failed: {}", failed.getMessage());
case AudioCheckResult.Failed failed ->
log.warn("Audio check failed: {}", failed.getMessage());
default -> log.warn("Unexpected result type: {}", checkResult.getClass().getSimpleName());
}
// }
}
}
session.setStatus(UploadStatus.COMPLETED);
@@ -590,8 +580,8 @@ public class FileUploadServiceImpl implements FileUploadService {
Path path = Paths.get(filePath);
Map<String, Long> hash = imageHashService.calculateHash(path);
List<SimilarImageProjection> duplicates = fileSimilarityService.findDuplicatedByHash(
hash.get("hi"), hash.get("low"));
List<SimilarImageProjection> duplicates = fileSimilarityService.findDuplicatedByHash(hash.get("hi"),
hash.get("low"));
if (!duplicates.isEmpty()) {
throw new DuplicateImageException("Duplicate", duplicates.getFirst().getId(),