NCBACK-25 add protection for audio and use hash method from library
Test Workflow / test (push) Successful in 2s
Test Workflow / test (push) Successful in 2s
This commit is contained in:
@@ -49,7 +49,7 @@ public class FileEntityService {
|
||||
throw new IOException("File not found on disk: " + filePath);
|
||||
}
|
||||
|
||||
Map<String, Integer> imageHash = Map.of();
|
||||
Map<String, Long> imageHash = Map.of();
|
||||
|
||||
if (session.getFileType().startsWith("image")) {
|
||||
imageHash = imageHashService.calculateHash(filePath);
|
||||
|
||||
@@ -283,12 +283,16 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
|
||||
FileEntity saved = fileEntityRepository.save(fileEntity);
|
||||
|
||||
Map<String, Integer> hash = imageHashService.calculateHash(filePath);
|
||||
if (session.getFileType().equals("image")) {
|
||||
Map<String, Long> hash = imageHashService.calculateHash(filePath);
|
||||
|
||||
imageHashService.create(saved, hash);
|
||||
imageHashService.create(saved, hash);
|
||||
}
|
||||
|
||||
cleanupSessionFiles(session);
|
||||
|
||||
noCopyFileService.addFile(fileUtil.createFileInfo(fileEntity));
|
||||
|
||||
log.info("File processing completed for session: {}", session.getUploadId());
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -380,7 +384,8 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
private void checkForDuplicatesSynchronously(String filePath)
|
||||
throws IOException {
|
||||
Path path = Paths.get(filePath);
|
||||
Map<String, Integer> hash = imageHashService.calculateHash(path);
|
||||
Map<String, Long> hash = imageHashService.calculateHash(path);
|
||||
|
||||
List<SimilarImageProjection> duplicates = fileSimilarityService.findDuplicatedByHash(
|
||||
hash.get("hi"), hash.get("low"));
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ public class ImageLocalSearchImpl implements ImageLocalSearch {
|
||||
@Override
|
||||
public @Nullable FileProtector.FileInfo findByPHash(@NotNull PHash pHash) {
|
||||
ImageHashEntity imageHashEntity =
|
||||
imageHashRepository.findByHash64HiAndHash64Lo(Math.toIntExact(pHash.getFirstPart()),
|
||||
Math.toIntExact(pHash.getSecondPart()));
|
||||
imageHashRepository.findByHash64HiAndHash64Lo(pHash.getFirstPart(),
|
||||
pHash.getSecondPart());
|
||||
FileEntity file = fileEntityRepository.findByFileId(imageHashEntity.getFileId());
|
||||
|
||||
return new FileProtector.FileInfo(FileProtector.Type.IMAGE, imageHashEntity.getFileId(),
|
||||
|
||||
@@ -10,12 +10,18 @@ import org.springframework.stereotype.Component;
|
||||
import ru.soune.nocopy.service.file.FileEntityService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ProtectionFileProviderImpl implements FileProtector.FileProvider {
|
||||
|
||||
private static final Path SIGNATURE_FILE_PATH = Paths.get("/data/uploads/signature");
|
||||
|
||||
private final FileEntityService fileEntityService;
|
||||
|
||||
@Nullable
|
||||
@@ -38,9 +44,41 @@ public class ProtectionFileProviderImpl implements FileProtector.FileProvider {
|
||||
|
||||
@Override
|
||||
public @Nullable File getSignature() {
|
||||
log.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GET SIGNATURE FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
File signatureFile = SIGNATURE_FILE_PATH.toFile();
|
||||
|
||||
if (signatureFile.exists() && signatureFile.isFile() && signatureFile.length() > 0) {
|
||||
return signatureFile;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull OperationResult writeSignature(@NotNull byte[] bytes) {
|
||||
log.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!! WRITING SIGNATURE FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!! WRITING SIGNATURE FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!! WRITING SIGNATURE FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!! WRITING SIGNATURE FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!! WRITING SIGNATURE FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!! WRITING SIGNATURE FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!! WRITING SIGNATURE FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info(" !!!!!!!!!!!!!!!!!!!!!!!!!!! WRITING SIGNATURE FILE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
try {
|
||||
Path directory = SIGNATURE_FILE_PATH.getParent();
|
||||
|
||||
if (directory != null && !Files.exists(directory)) {
|
||||
Files.createDirectories(directory);
|
||||
}
|
||||
|
||||
Files.write(SIGNATURE_FILE_PATH, bytes);
|
||||
|
||||
return OperationResult.Companion.success();
|
||||
} catch (IOException e) {
|
||||
return OperationResult.Companion.failure("Not saved signature file");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public com.vrt.fileprotection.OperationResult writeAudioFile(@NotNull String id, @NotNull byte[] data, @Nullable String fileExt) {
|
||||
@@ -76,9 +114,4 @@ public class ProtectionFileProviderImpl implements FileProtector.FileProvider {
|
||||
return OperationResult.Companion.failure("Failed to create protected file");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull OperationResult writeSignature(@NotNull byte[] bytes) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user