This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user