dev test baseurl for test
Test Workflow / test (push) Has been cancelled

This commit is contained in:
2026-04-21 19:09:27 +07:00
parent dfc9a22bc5
commit 6c3742913c
5 changed files with 110 additions and 27 deletions
@@ -12,6 +12,7 @@ import ru.soune.nocopy.service.file.cloud.CloudStorageService;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.Map;
@@ -25,22 +26,48 @@ public class ImageHashService {
private final CloudStorageService cloudStorageService;
public Map<String, Long> calculateHash(Path imagePath) throws IOException {
// File file = cloudStorageService.readFileFromStorageByPath(imagePath.toString());
File file = imagePath.toFile();
if (file == null) {
file = cloudStorageService.readFileFromStorageByPath(imagePath.toString());
}
// public Map<String, Long> calculateHash(Path imagePath) throws IOException {
//// File file = cloudStorageService.readFileFromStorageByPath(imagePath.toString());
// File file = imagePath.toFile();
// if (file == null) {
// file = cloudStorageService.readFileFromStorageByPath(imagePath.toString());
// }
//
// PHash pHash = PerceptualHashHelper.INSTANCE.generateDCTPerceptualHash(file);
//
// Long firstPart = pHash.getFirstPart();
// Long secondPart = pHash.getSecondPart();
// Map<String, Long> hash = Map.of(
// "hi", firstPart,
// "low", secondPart);
//
// return hash;
// }
PHash pHash = PerceptualHashHelper.INSTANCE.generateDCTPerceptualHash(file);
public Map<String, Long> calculateHash(Path imagePath) throws IOException {
PHash pHash;
if (imagePath.toFile().exists()) {
pHash = PerceptualHashHelper.INSTANCE.generateDCTPerceptualHash(imagePath.toFile());
} else {
byte[] data = cloudStorageService.readFileFromStorageBytes(imagePath.toString());
Path tempFile = Files.createTempFile("perceptual_hash_", ".tmp");
try {
Files.write(tempFile, data);
pHash = PerceptualHashHelper.INSTANCE.generateDCTPerceptualHash(tempFile.toFile());
} finally {
Files.deleteIfExists(tempFile);
}
}
Long firstPart = pHash.getFirstPart();
Long secondPart = pHash.getSecondPart();
Map<String, Long> hash = Map.of(
"hi", firstPart,
"low", secondPart);
return hash;
return Map.of(
"hi", firstPart,
"low", secondPart
);
}
public void create(FileEntity file, Map<String, Long> stringIntegerMap) {