dev add pdf docs protect
Test Workflow / test (push) Successful in 4s

This commit is contained in:
vladp
2026-02-10 18:38:46 +07:00
parent fea2d5ad89
commit 8149c450b2
7 changed files with 54 additions and 5 deletions
@@ -0,0 +1,29 @@
package ru.soune.nocopy.service.file.impl;
import com.vrt.fileprotection.FileProtector;
import com.vrt.fileprotection.documents.DocumentLocalSearch;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Service;
import ru.soune.nocopy.entity.file.FileEntity;
import ru.soune.nocopy.repository.FileEntityRepository;
import ru.soune.nocopy.util.FileUtil;
@Slf4j
@Service
@RequiredArgsConstructor
public class DocumentLocalSearchImpl implements DocumentLocalSearch {
private final FileUtil fileUtil;
private final FileEntityRepository fileEntityRepository;
@Override
public @Nullable FileProtector.FileInfo findByIds(@NotNull String ownerId, @NotNull String fileId) {
FileEntity fileEntity = fileEntityRepository.findByIdAndUserId(fileId, Long.valueOf(ownerId));
return fileUtil.createFileInfo(fileEntity);
}
}
@@ -42,6 +42,11 @@ public class ProtectionFileProviderImpl implements FileProtector.FileProvider {
return fileEntityService.getFileById(id);
}
@Override
public @Nullable File getDocument(@NotNull String id) {
return fileEntityService.getFileById(id);
}
@Override
public @Nullable File getSignature() {
File signatureFile = SIGNATURE_FILE_PATH.toFile();
@@ -105,4 +110,15 @@ public class ProtectionFileProviderImpl implements FileProtector.FileProvider {
return OperationResult.Companion.failure("Failed to create protected file");
}
}
@Override
public @NotNull OperationResult writeDocumentFile(@NotNull String id, @NotNull byte[] data) {
try {
fileEntityService.writeProtectedFile(id, data, null);
return OperationResult.Companion.success();
} catch (Exception e) {
log.error("Failed to create protected file: {}", id, e);
return OperationResult.Companion.failure("Failed to create protected file");
}
}
}