dev
Test Workflow / test (push) Successful in 3s

This commit is contained in:
vladp
2026-01-27 20:27:39 +07:00
parent cf2f73955b
commit 4a185e6f9a
12 changed files with 185 additions and 21 deletions
@@ -1,7 +1,10 @@
package ru.soune.nocopy.service;
import com.vrt.fileprotection.image.phash.PHash;
import com.vrt.fileprotection.image.phash.PerceptualHashHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
@@ -31,6 +34,9 @@ public class FileSimilarityService {
private final AuthTokenRepository authTokenRepository;
@Value("${server.baseurl}")
private String baseUrl;
public List<SimilarFileDTO> findSimilarFiles(String fileId) {
var imageHashEntity = hashRepository.findById(fileId)
.orElseThrow(() -> new RuntimeException("Hash not found"));
@@ -167,11 +173,11 @@ public class FileSimilarityService {
Long hash64Hi, Long hash64Lo) {
Long imageProjectionHash64Hi = similarImageProjection.getHash64Hi();
Long similarImageProjectionHash64Lo = similarImageProjection.getHash64Lo();
int hamming = fileUtil.hamming64(hash64Hi, hash64Lo, imageProjectionHash64Hi, similarImageProjectionHash64Lo);
int hamming = PerceptualHashHelper.INSTANCE.hammingDistance(new PHash(hash64Hi, hash64Lo),
new PHash(imageProjectionHash64Hi, similarImageProjectionHash64Lo));
String level;
if (hamming <= 5) {
if (hamming <= 6) {
level = "DUPLICATE";
} else if (hamming <= 12) {
level = "SIMILAR";
@@ -186,6 +192,10 @@ public class FileSimilarityService {
.fileSize(similarImageProjection.getFileSize())
.hammingDistance(hamming)
.similarityLevel(level)
.supportId(similarImageProjection.getSupportId())
.uploadDate(similarImageProjection.getUploadDate())
.status(similarImageProjection.getProtectionStatus())
.url(baseUrl + "/api/files/public/" + similarImageProjection.getId())
.build();
}
}