@@ -5,6 +5,7 @@ import com.vrt.fileprotection.FileProtector;
|
||||
import com.vrt.fileprotection.NoCopyCheckResult;
|
||||
import com.vrt.fileprotection.audio.AudioCheckResult;
|
||||
import com.vrt.fileprotection.documents.DocumentCheckResult;
|
||||
import com.vrt.fileprotection.image.ImageCheckResult;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -382,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());
|
||||
|
||||
@@ -399,9 +400,12 @@ 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;
|
||||
|
||||
FileProtector.Type type = "document".equals(session.getFileType()) ?
|
||||
FileProtector.Type.DOC : FileProtector.Type.valueOf(session.getFileType().toUpperCase());
|
||||
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());
|
||||
|
||||
NoCopyCheckResult checkResult = noCopyFileService.checkFile(file, type);
|
||||
|
||||
@@ -411,18 +415,26 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
throw new DuplicateImageException("Duplicate", info.getId(),
|
||||
Long.valueOf(info.getOwnerId()));
|
||||
}
|
||||
|
||||
case AudioCheckResult.Success success -> {
|
||||
FileProtector.FileInfo info = success.getInfo();
|
||||
throw new DuplicateImageException("Duplicate", info.getId(),
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user