@@ -6,6 +6,7 @@ import com.vrt.fileprotection.NoCopyCheckResult;
|
|||||||
import com.vrt.fileprotection.audio.AudioCheckResult;
|
import com.vrt.fileprotection.audio.AudioCheckResult;
|
||||||
import com.vrt.fileprotection.documents.DocumentCheckResult;
|
import com.vrt.fileprotection.documents.DocumentCheckResult;
|
||||||
import com.vrt.fileprotection.image.ImageCheckResult;
|
import com.vrt.fileprotection.image.ImageCheckResult;
|
||||||
|
import com.vrt.fileprotection.image.ImageLocalSearch;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -319,15 +320,11 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
String finalFilePath = assembleFileSynchronously(session);
|
String finalFilePath = assembleFileSynchronously(session);
|
||||||
|
|
||||||
if (findSimilar == 0) {
|
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")) {
|
if (session.getFileType().startsWith("image")) {
|
||||||
checkForDuplicatesSynchronously(finalFilePath);
|
checkForDuplicatesSynchronously(finalFilePath);
|
||||||
} else {
|
} else if (session.getFileType().startsWith("audio") || session.getFileType().startsWith("document")) {
|
||||||
fileSimilarityService.hasDuplicatesByHash(finalFilePath, session.getUserId(),
|
fileSimilarityService.hasDuplicatesByHash(finalFilePath, session.getUserId(),
|
||||||
session.getFileType());
|
session.getFileType());
|
||||||
}
|
|
||||||
|
|
||||||
File file = new File(finalFilePath);
|
File file = new File(finalFilePath);
|
||||||
FileProtector.Type type = "document".equals(session.getFileType()) ?
|
FileProtector.Type type = "document".equals(session.getFileType()) ?
|
||||||
@@ -341,11 +338,6 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
throw new DuplicateImageException("Duplicate", info.getId(),
|
throw new DuplicateImageException("Duplicate", info.getId(),
|
||||||
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 AudioCheckResult.Success success -> {
|
case AudioCheckResult.Success success -> {
|
||||||
FileProtector.FileInfo info = success.getInfo();
|
FileProtector.FileInfo info = success.getInfo();
|
||||||
throw new DuplicateImageException("Duplicate", info.getId(),
|
throw new DuplicateImageException("Duplicate", info.getId(),
|
||||||
@@ -355,11 +347,9 @@ public class FileUploadServiceImpl implements FileUploadService {
|
|||||||
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());
|
||||||
case ImageCheckResult.Failed failed ->
|
|
||||||
log.warn("ImageCheckResult 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);
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ public class ImageLocalSearchImpl implements ImageLocalSearch {
|
|||||||
@Override
|
@Override
|
||||||
public @Nullable FileProtector.FileInfo findByPHash(@NotNull PHash pHash) {
|
public @Nullable FileProtector.FileInfo findByPHash(@NotNull PHash pHash) {
|
||||||
ImageHashEntity imageHashEntity =
|
ImageHashEntity imageHashEntity =
|
||||||
imageHashRepository.findByHash64HiAndHash64Lo(pHash.getFirstPart(),
|
imageHashRepository.findByHash64HiAndHash64Lo(pHash.getFirstPart(), pHash.getSecondPart());
|
||||||
pHash.getSecondPart());
|
|
||||||
|
|
||||||
if (imageHashEntity == null) return null;
|
if (imageHashEntity == null) return null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user