From 1dd6a6b7e26d4b31ec5f44b96321897ce46c246e Mon Sep 17 00:00:00 2001 From: backdev-1 Date: Tue, 21 Apr 2026 11:01:15 +0700 Subject: [PATCH] dev test baseurl for test --- .../nocopy/service/FileSimilarityService.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/soune/nocopy/service/FileSimilarityService.java b/src/main/java/ru/soune/nocopy/service/FileSimilarityService.java index a0cc183..7087e99 100644 --- a/src/main/java/ru/soune/nocopy/service/FileSimilarityService.java +++ b/src/main/java/ru/soune/nocopy/service/FileSimilarityService.java @@ -117,7 +117,7 @@ public class FileSimilarityService { } public FileEntity findDuplicateByHash(String path, String mimeType, Long userId) throws Exception { - String hash = calculateFileHash(path); + String hash = calculateFileHash(path, false); User user = userRepository.findById(userId).orElseThrow(); Company company = user.getCompany(); @@ -132,15 +132,15 @@ public class FileSimilarityService { List fileEntityList = fileEntityRepository.findByMimeTypeAndUserIds(mimeType, userIds); for (FileEntity file : fileEntityList) { - if (file.getProtectedFilePath() == null) continue; - File existingFile = cloudStorageService.readFileFromStorageByPath(file.getFilePath()); - File newFile = new File(path); +// if (file.getProtectedFilePath() == null) continue; +// File existingFile = cloudStorageService.readFileFromStorageByPath(file.getFilePath()); +// File newFile = new File(path); - if (existingFile.length() == newFile.length()) { - if (calculateFileHash(file.getFilePath()).equals(hash)) { +// if (existingFile.length() == newFile.length()) { + if (calculateFileHash(file.getFilePath(), true).equals(hash)) { return file; } - } +// } } return null; @@ -199,10 +199,12 @@ public class FileSimilarityService { } - private String calculateFileHash(String path) throws Exception { + private String calculateFileHash(String path, boolean cloud) throws Exception { MessageDigest digest = MessageDigest.getInstance("SHA-256"); - try (InputStream is = cloudStorageService.readFileFromStorage(path)) { + File file = cloud ? cloudStorageService.readFileFromStorageByPath(path): new File(path); + + try (InputStream is = new FileInputStream(file)) { byte[] buffer = new byte[8192]; int read; while ((read = is.read(buffer)) > 0) {