This commit is contained in:
@@ -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