@@ -5,6 +5,7 @@ import com.vrt.fileprotection.FileProtector;
|
|||||||
import com.vrt.fileprotection.NoCopyCheckResult;
|
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 jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -318,15 +319,19 @@ 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 if (session.getFileType().startsWith("audio") || session.getFileType().startsWith("document")) {
|
} else {
|
||||||
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()) ?
|
||||||
FileProtector.Type.DOC : FileProtector.Type.AUDIO;
|
FileProtector.Type.DOC : FileProtector.Type.valueOf(session.getFileType());
|
||||||
|
|
||||||
NoCopyCheckResult checkResult = noCopyFileService.checkFile(file, type);
|
NoCopyCheckResult checkResult = noCopyFileService.checkFile(file, type);
|
||||||
|
|
||||||
@@ -336,6 +341,11 @@ 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(),
|
||||||
@@ -345,9 +355,11 @@ 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);
|
||||||
|
|||||||
Reference in New Issue
Block a user