@@ -22,6 +22,7 @@ import ru.soune.nocopy.repository.UserRepository;
|
|||||||
import ru.soune.nocopy.service.file.cloud.CloudStorageService;
|
import ru.soune.nocopy.service.file.cloud.CloudStorageService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -240,11 +241,18 @@ public class FileEntityService {
|
|||||||
String extension = determineFileExtension(fileExt, fileEntity);
|
String extension = determineFileExtension(fileExt, fileEntity);
|
||||||
Path protectedFilePath = prepareProtectedPath(fileEntity, extension);
|
Path protectedFilePath = prepareProtectedPath(fileEntity, extension);
|
||||||
|
|
||||||
if (Files.exists(protectedFilePath)) {
|
Files.createDirectories(protectedFilePath.getParent());
|
||||||
Files.delete(protectedFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
try (FileChannel channel = FileChannel.open(protectedFilePath, StandardOpenOption.WRITE)) {
|
Files.deleteIfExists(protectedFilePath);
|
||||||
|
|
||||||
|
try (FileChannel channel = FileChannel.open(protectedFilePath,
|
||||||
|
StandardOpenOption.CREATE,
|
||||||
|
StandardOpenOption.WRITE)) {
|
||||||
|
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||||
|
while (buffer.hasRemaining()) {
|
||||||
|
channel.write(buffer);
|
||||||
|
}
|
||||||
channel.force(true);
|
channel.force(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ public class ProtectionFileProviderImpl implements FileProtector.FileProvider {
|
|||||||
FileEntity fileEntity = fileEntityService.writeProtectedFile(id, data, fileExt);
|
FileEntity fileEntity = fileEntityService.writeProtectedFile(id, data, fileExt);
|
||||||
|
|
||||||
Path filePath = Paths.get(fileEntity.getProtectedFilePath());
|
Path filePath = Paths.get(fileEntity.getProtectedFilePath());
|
||||||
|
|
||||||
if (!Files.exists(filePath)) {
|
if (!Files.exists(filePath)) {
|
||||||
log.error("File not found after write: {}", filePath);
|
log.error("File not found after write: {}", filePath);
|
||||||
return OperationResult.Companion.failure("File not found");
|
return OperationResult.Companion.failure("File not found");
|
||||||
@@ -171,45 +172,6 @@ public class ProtectionFileProviderImpl implements FileProtector.FileProvider {
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull OperationResult writeDocumentFile(@NotNull String id, @NotNull byte[] data) {
|
public @NotNull OperationResult writeDocumentFile(@NotNull String id, @NotNull byte[] data) {
|
||||||
try {
|
try {
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
log.info("SAVE DOCUMENT");
|
|
||||||
FileEntity fileEntity = fileEntityService.writeProtectedFile(id, data, null);
|
FileEntity fileEntity = fileEntityService.writeProtectedFile(id, data, null);
|
||||||
|
|
||||||
cloudStorageService.saveFilesToStorage(fileEntity.getMimeType(), fileEntity.getFileExtension(),
|
cloudStorageService.saveFilesToStorage(fileEntity.getMimeType(), fileEntity.getFileExtension(),
|
||||||
|
|||||||
Reference in New Issue
Block a user