This commit is contained in:
@@ -16,6 +16,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -24,25 +25,24 @@ public class ImageHashService {
|
||||
|
||||
private final ImageHashRepository repository;
|
||||
|
||||
public void create(FileEntity file, Path imagePath) {
|
||||
try {
|
||||
long hash64 = computePhash64(imagePath);
|
||||
public Map<String, Integer> calculateHash(Path imagePath) throws IOException {
|
||||
long hash64 = computePhash64(imagePath);
|
||||
|
||||
int hi = high32(hash64);
|
||||
int lo = low32(hash64);
|
||||
return Map.of(
|
||||
"hi", high32(hash64),
|
||||
"low", low32(hash64));
|
||||
}
|
||||
|
||||
ImageHashEntity entity = ImageHashEntity.builder()
|
||||
.file(file)
|
||||
.hash64Hi(hi)
|
||||
.hash64Lo(lo)
|
||||
.hashAlgorithm("PHASH64")
|
||||
.createdAt(LocalDateTime.now())
|
||||
.build();
|
||||
public void create(FileEntity file, Map<String, Integer> stringIntegerMap) {
|
||||
ImageHashEntity entity = ImageHashEntity.builder()
|
||||
.file(file)
|
||||
.hash64Hi(stringIntegerMap.get("hi"))
|
||||
.hash64Lo(stringIntegerMap.get("low"))
|
||||
.hashAlgorithm("PHASH64")
|
||||
.createdAt(LocalDateTime.now())
|
||||
.build();
|
||||
|
||||
repository.save(entity);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to compute image hash", e);
|
||||
}
|
||||
repository.save(entity);
|
||||
}
|
||||
|
||||
private long computePhash64(Path path) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user