This commit is contained in:
@@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
|
||||
import ru.soune.nocopy.dto.file.SimilarFileDTO;
|
||||
import ru.soune.nocopy.dto.file.SimilarityFilter;
|
||||
import ru.soune.nocopy.entity.file.ImageHashEntity;
|
||||
import ru.soune.nocopy.repository.AuthTokenRepository;
|
||||
import ru.soune.nocopy.repository.ImageHashRepository;
|
||||
import ru.soune.nocopy.repository.ImageSimilarityRepository;
|
||||
import ru.soune.nocopy.repository.SimilarImageProjection;
|
||||
@@ -28,6 +29,8 @@ public class FileSimilarityService {
|
||||
|
||||
private final FileUtil fileUtil;
|
||||
|
||||
private final AuthTokenRepository authTokenRepository;
|
||||
|
||||
public List<SimilarFileDTO> findSimilarFiles(String fileId) {
|
||||
var imageHashEntity = hashRepository.findById(fileId)
|
||||
.orElseThrow(() -> new RuntimeException("Hash not found"));
|
||||
@@ -128,14 +131,15 @@ public class FileSimilarityService {
|
||||
return duplicates;
|
||||
}
|
||||
|
||||
public Page<SimilarFileDTO> findSimilarFiles(String fileId, SimilarityFilter filter, Pageable pageable) {
|
||||
public Page<SimilarFileDTO> findSimilarFiles(String fileId, SimilarityFilter filter, Pageable pageable, String authToken) {
|
||||
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);
|
||||
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()
|
||||
|
||||
@@ -202,7 +202,8 @@ public class FileEntityService {
|
||||
|
||||
Files.delete(path);
|
||||
|
||||
markAsDeleted(fileEntity);
|
||||
// markAsDeleted(fileEntity);
|
||||
fileEntityRepository.delete(fileEntity);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -248,6 +249,10 @@ public class FileEntityService {
|
||||
return fileEntityRepository.findBySignature(signature);
|
||||
}
|
||||
|
||||
public String findFileIdByPath(String filePath) {
|
||||
return fileEntityRepository.findFileIdByFilePath(filePath);
|
||||
}
|
||||
|
||||
public File getFileById(String id) {
|
||||
try {
|
||||
FileEntity fileEntity = fileEntityRepository.findById(id).orElseThrow(() ->
|
||||
|
||||
@@ -14,7 +14,7 @@ public interface FileUploadService {
|
||||
|
||||
void cancelUpload(String uploadId);
|
||||
|
||||
void uploadChunk(String uploadId, Integer chunkNumber, MultipartFile chunkFile);
|
||||
UploadProgressResponse uploadChunk(String uploadId, Integer chunkNumber, MultipartFile chunkFile, Integer findSimilar);
|
||||
|
||||
UploadProgressResponse getUploadProgress(String uploadId);
|
||||
|
||||
|
||||
@@ -177,8 +177,8 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void uploadChunk(String uploadId, Integer chunkNumber,
|
||||
MultipartFile chunkFile) {
|
||||
public UploadProgressResponse uploadChunk(String uploadId, Integer chunkNumber,
|
||||
MultipartFile chunkFile, Integer findSimilar) {
|
||||
FileUploadSession session = sessionRepository.findById(uploadId)
|
||||
.orElseThrow(() -> new UploadSessionNotFoundException(uploadId));
|
||||
|
||||
@@ -204,7 +204,7 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
throw new ChunkSizeExceededException(chunkFile.getSize(), chunkSize);
|
||||
}
|
||||
|
||||
processChunk(session, chunkNumber, chunkFile);
|
||||
return processChunk(session, chunkNumber, chunkFile, findSimilar);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,12 +285,13 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
}
|
||||
}
|
||||
|
||||
private UploadProgressResponse processChunk(FileUploadSession session, Integer chunkNumber, MultipartFile chunkFile) {
|
||||
private UploadProgressResponse processChunk(FileUploadSession session, Integer chunkNumber, MultipartFile chunkFile,
|
||||
Integer findSimilar) {
|
||||
String chunkPath = null;
|
||||
|
||||
try {
|
||||
if (session.getChunkPaths().containsKey(chunkNumber)) {
|
||||
return handleExistingChunk(session, chunkNumber, chunkFile);
|
||||
return handleExistingChunk(session, chunkNumber, chunkFile, findSimilar);
|
||||
}
|
||||
|
||||
chunkPath = saveChunkWithIntegrityCheck(session, chunkNumber, chunkFile);
|
||||
@@ -311,7 +312,7 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
|
||||
String finalFilePath = assembleFileSynchronously(session);
|
||||
|
||||
if (session.getFileType().startsWith("image")) {
|
||||
if (session.getFileType().startsWith("image") && findSimilar == 0) {
|
||||
checkForDuplicatesSynchronously(finalFilePath);
|
||||
}
|
||||
|
||||
@@ -381,7 +382,8 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
|
||||
private UploadProgressResponse handleExistingChunk(FileUploadSession session,
|
||||
Integer chunkNumber,
|
||||
MultipartFile chunkFile) throws IOException {
|
||||
MultipartFile chunkFile,
|
||||
Integer findSimilar) throws IOException {
|
||||
String existingPath = session.getChunkPaths().get(chunkNumber);
|
||||
Path chunkPath = Paths.get(existingPath);
|
||||
|
||||
@@ -390,7 +392,7 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
session.setChunksUploaded(session.getChunksUploaded() - 1);
|
||||
sessionRepository.save(session);
|
||||
|
||||
return processChunk(session, chunkNumber, chunkFile);
|
||||
return processChunk(session, chunkNumber, chunkFile, findSimilar);
|
||||
}
|
||||
|
||||
long existingSize = Files.size(chunkPath);
|
||||
@@ -401,7 +403,7 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
session.setChunksUploaded(session.getChunksUploaded() - 1);
|
||||
sessionRepository.save(session);
|
||||
|
||||
return processChunk(session, chunkNumber, chunkFile);
|
||||
return processChunk(session, chunkNumber, chunkFile, findSimilar);
|
||||
}
|
||||
|
||||
return UploadProgressResponse.fromSession(session);
|
||||
|
||||
Reference in New Issue
Block a user