dev conver files
Test Workflow / test (push) Waiting to run

This commit is contained in:
vladp
2026-02-27 01:47:50 +07:00
parent a2c680d10a
commit f3a0ab8181
4 changed files with 38 additions and 45 deletions
@@ -103,16 +103,35 @@ public class FileSimilarityService {
return duplicates;
}
public void hasDuplicatesByHash(String path, String mimeType) throws Exception {
public void hasDuplicatesByHash(String path, String mimeType, Long userId) throws Exception {
FileEntity duplicateByHash = findDuplicateByHash(path, mimeType, userId);
if (duplicateByHash != null) {
throw new DuplicateImageException("Duplicate", duplicateByHash.getId(),
duplicateByHash.getUserId());
}
}
public FileEntity findDuplicateByHash(String path, String mimeType, Long userId) throws Exception {
String hash = calculateFileHash(path);
List<FileEntity> fileEntityList = fileEntityRepository.findByMimeType(mimeType);
User user = userRepository.findById(userId).orElseThrow();
Company company = user.getCompany();
List<Long> userIds = new ArrayList<>();
if (company != null) {
userIds.addAll(company.getUsers().stream().map(User::getId).toList());
} else {
userIds.add(userId);
}
List<FileEntity> fileEntityList = fileEntityRepository.findByMimeTypeAndUserIds(mimeType, userIds);
for (FileEntity file : fileEntityList) {
if (calculateFileHash(file.getFilePath()).equals(hash)) {
throw new DuplicateImageException("Duplicate", file.getId(),
file.getUserId());
return file;
}
}
return null;
}
private final UserRepository userRepository;