@@ -19,4 +19,5 @@ public class SimilarFileDTO {
|
||||
ProtectionStatus status;
|
||||
LocalDateTime uploadDate;
|
||||
String url;
|
||||
Boolean owner;
|
||||
}
|
||||
|
||||
@@ -155,19 +155,21 @@ public class FileSimilarityService {
|
||||
.orElseThrow(() -> new RuntimeException("Hash not found for file: " + fileId));
|
||||
|
||||
List<SimilarImageProjection> candidates;
|
||||
if (authToken == null || "all".equals(authToken)) {
|
||||
List<Long> userIds;
|
||||
// if (authToken == null || "all".equals(authToken)) {
|
||||
candidates = repository.findCandidates(fileId);
|
||||
} else {
|
||||
// } else {
|
||||
Long userId = authTokenRepository.findUserIdByToken(authToken);
|
||||
User user = userRepository.findById(userId).orElseThrow(() -> new RuntimeException("User not found"));
|
||||
Company company = user.getCompany();
|
||||
if (company != null) {
|
||||
Set<Long> userIds = company.getUsers().stream().map(User::getId).collect(Collectors.toSet());
|
||||
candidates = repository.findCandidatesFromUserFiles(fileId, userIds);
|
||||
userIds = company.getUsers().stream().map(User::getId).collect(Collectors.toList());
|
||||
// candidates = repository.findCandidatesFromUserFiles(fileId, userIds);
|
||||
} else {
|
||||
candidates = repository.findCandidatesFromUserFiles(fileId, userId);
|
||||
}
|
||||
userIds = List.of(userId);
|
||||
// candidates = repository.findCandidatesFromUserFiles(fileId, userId);
|
||||
}
|
||||
// }
|
||||
|
||||
List<String> levels = (similarityLevels != null && !similarityLevels.isEmpty())
|
||||
? similarityLevels
|
||||
@@ -176,7 +178,7 @@ public class FileSimilarityService {
|
||||
List<SimilarFileDTO> allResults = candidates.stream()
|
||||
.map(c -> createSimilarFileResponse(c,
|
||||
imageHashEntity.getHash64Hi(),
|
||||
imageHashEntity.getHash64Lo()))
|
||||
imageHashEntity.getHash64Lo(), userIds))
|
||||
.filter(dto -> levels.contains(dto.getSimilarityLevel()))
|
||||
.sorted(Comparator.comparingInt(SimilarFileDTO::getHammingDistance))
|
||||
.collect(Collectors.toList());
|
||||
@@ -211,7 +213,7 @@ public class FileSimilarityService {
|
||||
}
|
||||
|
||||
private SimilarFileDTO createSimilarFileResponse(SimilarImageProjection similarImageProjection,
|
||||
Long hash64Hi, Long hash64Lo) {
|
||||
Long hash64Hi, Long hash64Lo, List<Long> userIds) {
|
||||
Long imageProjectionHash64Hi = similarImageProjection.getHash64Hi();
|
||||
Long similarImageProjectionHash64Lo = similarImageProjection.getHash64Lo();
|
||||
int hamming = PerceptualHashHelper.INSTANCE.hammingDistance(new PHash(hash64Hi, hash64Lo),
|
||||
@@ -238,6 +240,7 @@ public class FileSimilarityService {
|
||||
.supportId(similarImageProjection.getSupportId())
|
||||
.uploadDate(similarImageProjection.getUploadDate())
|
||||
.status(similarImageProjection.getProtectionStatus())
|
||||
.owner(userIds.contains(similarImageProjection.getUserId()))
|
||||
// .url(baseUrl + "/api/files/protected/" + similarImageProjection.getId())
|
||||
.url(baseUrl + "/api/files/protected/" + similarImageProjection.getId() + "/thumbnail")
|
||||
.build();
|
||||
|
||||
Reference in New Issue
Block a user