dev delete config
Test Workflow / test (push) Waiting to run

This commit is contained in:
vladp
2026-02-17 15:39:26 +07:00
parent 8de13b410b
commit 74ba9709a9
5 changed files with 15 additions and 173 deletions
@@ -46,51 +46,9 @@ public class FileSimilarityService {
private final FileEntityRepository fileEntityRepository;
// @Lazy
// private final NoCopyFileService noCopyFileService;
@Value("${server.baseurl}")
private String baseUrl;
public List<SimilarFileDTO> findSimilarFiles(String fileId) {
var imageHashEntity = hashRepository.findById(fileId)
.orElseThrow(() -> new RuntimeException("Hash not found"));
Long hash64Hi = imageHashEntity.getHash64Hi();
Long hash64Lo = imageHashEntity.getHash64Lo();
List<SimilarImageProjection> candidates = repository.findCandidates(fileId);
return candidates.stream()
.map(c -> {
Long cHi = c.getHash64Hi();
Long cLo = c.getHash64Lo();
int hamming = fileUtil.hamming64(hash64Hi, hash64Lo, cHi, cLo);
String level;
if (hamming <= 5) {
level = "DUPLICATE";
} else if (hamming <= 12) {
level = "SIMILAR";
} else {
level = "DIFFERENT";
}
return SimilarFileDTO.builder()
.fileId(c.getId())
.ownerId(c.getUserId())
.originalFileName(c.getOriginalFileName())
.fileSize(c.getFileSize())
.hammingDistance(hamming)
.similarityLevel(level)
.build();
})
.sorted((a, b) ->
Integer.compare(a.getHammingDistance(), b.getHammingDistance()))
.toList();
}
public List<SimilarFileDTO> findDuplicateByHammingDistance(String fileId, int hammingDistance,
int duplicate, int similar) {
List<SimilarImageProjection> candidates = repository.findCandidates(fileId);
@@ -152,50 +110,17 @@ public class FileSimilarityService {
return duplicates;
}
// public void hasDuplicatesByHash(String path, Long userId, String mimeType) throws Exception {
// String hash = calculateFileHash(path);
// List<FileEntity> fileEntityList = fileEntityRepository.findByUserIdAndMimeType(userId, mimeType);
//
// for (FileEntity file : fileEntityList) {
// if (calculateFileHash(file.getFilePath()).equals(hash)) {
// throw new DuplicateImageException("Duplicate", file.getId(),
// file.getUserId());
// }
// }
// }
public void hasDuplicatesByHash(String path, Long userId, String mimeType) throws Exception {
String hash = calculateFileHash(path);
List<FileEntity> fileEntityList = fileEntityRepository.findByUserIdAndMimeType(userId, mimeType);
// public Page<SimilarFileDTO> findSimilarFiles(String fileId, SimilarityFilter filter, Pageable pageable,
// String authToken) throws Exception {
//
// var imageHashEntity = hashRepository.findById(fileId)
// .orElseThrow(() -> new RuntimeException("Hash not found"));
//
// Long hash64Hi = imageHashEntity.getHash64Hi();
// Long hash64Lo = imageHashEntity.getHash64Lo();
// List<SimilarImageProjection> candidates = authToken.equals("all") ? repository.findCandidates(fileId):
// repository.findCandidatesFromUserFiles(fileId, authTokenRepository.findUserIdByToken(authToken));
//
// List<String> similarityLevels = (filter != null && filter.getSimilarityLevels() != null)
// ? filter.getSimilarityLevels()
// : List.of("DUPLICATE", "SIMILAR", "DIFFERENT");
//
// List<SimilarFileDTO> allResults = candidates.stream()
// .map(c -> createSimilarFileResponse(c, hash64Hi, hash64Lo))
// .filter(response -> similarityLevels.contains(response.getSimilarityLevel()))
// .sorted(Comparator.comparingInt(SimilarFileDTO::getHammingDistance))
// .collect(Collectors.toList());
//
// int total = allResults.size();
// int page = (pageable != null) ? pageable.getPageNumber() : 0;
// int size = (pageable != null) ? pageable.getPageSize() : 20;
//
// int fromIndex = Math.min(page * size, total);
// int toIndex = Math.min(fromIndex + size, total);
//
// List<SimilarFileDTO> pageContent = allResults.subList(fromIndex, toIndex);
//
// return new PageImpl<>(pageContent, pageable, total);
// }
for (FileEntity file : fileEntityList) {
if (calculateFileHash(file.getFilePath()).equals(hash)) {
throw new DuplicateImageException("Duplicate", file.getId(),
file.getUserId());
}
}
}
public Page<SimilarFileDTO> findSimilarFiles(
String fileId,