dev add check similar
Test Workflow / test (push) Has been cancelled

This commit is contained in:
2026-04-29 16:59:27 +07:00
parent 0f8017a5a9
commit f032caf0a3
3 changed files with 32 additions and 6 deletions
@@ -137,7 +137,7 @@ public class ImageFoundRequestHandler implements RequestHandler {
int page = imageSearchRequest.getPage() != null ? imageSearchRequest.getPage() : 1;
int pageSize = 5;
boolean checkSimilar = imageSearchRequest.getCheckSimilarFirst() == null ? false:
boolean checkSimilar = imageSearchRequest.getCheckSimilarFirst() == null ? true:
imageSearchRequest.getCheckSimilarFirst();
if (checkSimilar && !allUniqueImages.isEmpty()) {
@@ -149,12 +149,14 @@ public class ImageFoundRequestHandler implements RequestHandler {
tempFile = fileUploadService.downloadImageFromUrl(url);
String filePath = tempFile.toAbsolutePath().toString();
Map<String, Long> hash = imageHashService.calculateHash(Paths.get(filePath));
Map<String, Long> hashSearchApiFile = imageHashService.calculateHash(Paths.get(filePath));
List<SimilarImageProjection> duplicates = fileSimilarityService.findDuplicatedByHash(hash.get("hi"),
hash.get("low"));
Map<String, Long> hashCheckFile = imageHashService.calculateHash(Paths.get(fileEntity.getFilePath()));
if (duplicates.isEmpty()) {
boolean hashesAreEqual = hashSearchApiFile.get("hi").equals(hashCheckFile.get("hi"))
&& hashSearchApiFile.get("low").equals(hashCheckFile.get("low"));
if (!hashesAreEqual) {
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
"Not found similar pictures", new YandexSearchResponse());
}
@@ -114,5 +114,29 @@ public interface ImageSimilarityRepository
List<SimilarImageProjection> findExactDuplicates(
@Param("hash64Hi") Long hash64_hi,
@Param("hash64Lo") Long hash64_lo);
@Query(value = """
SELECT
h.hash64_hi AS hash64Hi,
h.hash64_lo AS hash64Lo,
h.file_id AS fileId,
f.user_id AS userId,
f.original_file_name AS originalFileName,
f.file_size AS fileSize,
f.stored_file_name AS similarFileId,
f.support_id AS supportId,
f.created_at AS uploadDate,
f.file_extension AS extension,
f.protection_status AS protectionStatus
FROM image_hashes h
JOIN file_entities f ON f.id = h.file_id
WHERE h.hash64_hi = :hash64Hi
AND h.hash64_lo = :hash64Lo
AND (f.status = 'TEMP')
""",
nativeQuery = true)
List<SimilarImageProjection> findExactDuplicatesTemp(
@Param("hash64Hi") Long hash64_hi,
@Param("hash64Lo") Long hash64_lo);
}
@@ -99,7 +99,7 @@ public class FileSimilarityService {
}
public List<SimilarImageProjection> findDuplicatedByHash(Long hash64Hi, Long hash64Lo) {
List<SimilarImageProjection> duplicates = repository.findExactDuplicates(hash64Hi,hash64Lo);
List<SimilarImageProjection> duplicates = repository.findExactDuplicatesTemp(hash64Hi,hash64Lo);
if (duplicates.isEmpty()) {
return new ArrayList<>();