@@ -215,6 +215,7 @@ public class ApiController {
|
|||||||
NoCopyCheckResult checkResult = noCopyFileService.checkFile(file, FileProtector.Type.IMAGE);
|
NoCopyCheckResult checkResult = noCopyFileService.checkFile(file, FileProtector.Type.IMAGE);
|
||||||
log.info("checkResult: {}", checkResult);
|
log.info("checkResult: {}", checkResult);
|
||||||
|
|
||||||
|
|
||||||
return ResponseEntity.ok(new BaseResponse(1, 1, "1", checkResult));
|
return ResponseEntity.ok(new BaseResponse(1, 1, "1", checkResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -383,9 +383,9 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
String finalFilePath = assembleFileSynchronously(session);
|
String finalFilePath = assembleFileSynchronously(session);
|
||||||
|
|
||||||
if (findSimilar == 0) {
|
if (findSimilar == 0) {
|
||||||
// if (session.getFileType().startsWith("image")) {
|
if (session.getFileType().startsWith("image")) {
|
||||||
// checkForDuplicatesSynchronously(finalFilePath);
|
checkForDuplicatesSynchronously(finalFilePath);
|
||||||
// } else if (session.getFileType().startsWith("audio") || session.getFileType().startsWith("document")) {
|
} else if (session.getFileType().startsWith("audio") || session.getFileType().startsWith("document")) {
|
||||||
fileSimilarityService.hasDuplicatesByHash(finalFilePath ,session.getFileType(),
|
fileSimilarityService.hasDuplicatesByHash(finalFilePath ,session.getFileType(),
|
||||||
session.getUserId());
|
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 " +
|
throw new FileFormatException("Failed to upload chunk: .wav file not have RIFF header or " +
|
||||||
"another problems with .wav file");
|
"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);
|
NoCopyCheckResult checkResult = noCopyFileService.checkFile(file, type);
|
||||||
|
|
||||||
switch (checkResult) {
|
switch (checkResult) {
|
||||||
@@ -422,19 +418,13 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
Long.valueOf(info.getOwnerId()));
|
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 ->
|
case DocumentCheckResult.Failed failed ->
|
||||||
log.warn("Document check failed: {}", failed.getMessage());
|
log.warn("Document check failed: {}", failed.getMessage());
|
||||||
case AudioCheckResult.Failed failed ->
|
case AudioCheckResult.Failed failed ->
|
||||||
log.warn("Audio check failed: {}", failed.getMessage());
|
log.warn("Audio check failed: {}", failed.getMessage());
|
||||||
default -> log.warn("Unexpected result type: {}", checkResult.getClass().getSimpleName());
|
default -> log.warn("Unexpected result type: {}", checkResult.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session.setStatus(UploadStatus.COMPLETED);
|
session.setStatus(UploadStatus.COMPLETED);
|
||||||
@@ -590,8 +580,8 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
Path path = Paths.get(filePath);
|
Path path = Paths.get(filePath);
|
||||||
Map<String, Long> hash = imageHashService.calculateHash(path);
|
Map<String, Long> hash = imageHashService.calculateHash(path);
|
||||||
|
|
||||||
List<SimilarImageProjection> duplicates = fileSimilarityService.findDuplicatedByHash(
|
List<SimilarImageProjection> duplicates = fileSimilarityService.findDuplicatedByHash(hash.get("hi"),
|
||||||
hash.get("hi"), hash.get("low"));
|
hash.get("low"));
|
||||||
|
|
||||||
if (!duplicates.isEmpty()) {
|
if (!duplicates.isEmpty()) {
|
||||||
throw new DuplicateImageException("Duplicate", duplicates.getFirst().getId(),
|
throw new DuplicateImageException("Duplicate", duplicates.getFirst().getId(),
|
||||||
|
|||||||
Reference in New Issue
Block a user