+1
-1
@@ -59,7 +59,7 @@ dependencies {
|
|||||||
testImplementation 'org.mockito:mockito-core:5.3.1'
|
testImplementation 'org.mockito:mockito-core:5.3.1'
|
||||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
|
|
||||||
implementation name: 'testlib-fat-0.2.1-all'
|
implementation name: 'testlib-fat-0.3.0-all'
|
||||||
|
|
||||||
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.12.0'
|
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.12.0'
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -3,9 +3,9 @@ package ru.soune.nocopy.configuration;
|
|||||||
import com.vrt.AudioFilePathProvider;
|
import com.vrt.AudioFilePathProvider;
|
||||||
import com.vrt.fileprotection.FileProtector;
|
import com.vrt.fileprotection.FileProtector;
|
||||||
import com.vrt.fileprotection.audio.AudioLocalSearch;
|
import com.vrt.fileprotection.audio.AudioLocalSearch;
|
||||||
|
import com.vrt.fileprotection.documents.DocumentLocalSearch;
|
||||||
import com.vrt.fileprotection.image.ImageLocalSearch;
|
import com.vrt.fileprotection.image.ImageLocalSearch;
|
||||||
import com.vrt.fileprotection.image.ImageUniqueCheck;
|
import com.vrt.fileprotection.image.ImageUniqueCheck;
|
||||||
import com.vrt.fileprotection.image.phash.PerceptualHashHelper;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -33,7 +33,8 @@ public class ApplicationConfig {
|
|||||||
ImageUniqueCheck imageUniqueCheck,
|
ImageUniqueCheck imageUniqueCheck,
|
||||||
ImageLocalSearch imageLocalSearch,
|
ImageLocalSearch imageLocalSearch,
|
||||||
AudioLocalSearch audioLocalSearch,
|
AudioLocalSearch audioLocalSearch,
|
||||||
AudioFilePathProvider audioFilePathProvider) {
|
AudioFilePathProvider audioFilePathProvider,
|
||||||
|
DocumentLocalSearch documentLocalSearch) {
|
||||||
|
|
||||||
return new com.vrt.NoCopyFileService(
|
return new com.vrt.NoCopyFileService(
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
@@ -42,7 +43,8 @@ public class ApplicationConfig {
|
|||||||
imageUniqueCheck,
|
imageUniqueCheck,
|
||||||
imageLocalSearch,
|
imageLocalSearch,
|
||||||
audioLocalSearch,
|
audioLocalSearch,
|
||||||
audioFilePathProvider
|
audioFilePathProvider,
|
||||||
|
documentLocalSearch
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public enum FileType {
|
|||||||
VIDEO("video", Arrays.asList("mp4", "avi", "mov", "wmv", "flv", "mkv", "webm", "m4v", "mpg", "mpeg",
|
VIDEO("video", Arrays.asList("mp4", "avi", "mov", "wmv", "flv", "mkv", "webm", "m4v", "mpg", "mpeg",
|
||||||
"3gp", "3g2", "f4v", "m2ts", "mts", "vob", "ogv", "divx")),
|
"3gp", "3g2", "f4v", "m2ts", "mts", "vob", "ogv", "divx")),
|
||||||
AUDIO("audio", List.of("wav")),
|
AUDIO("audio", List.of("wav")),
|
||||||
DOCUMENT("document", Arrays.asList("pdf", "txt", "doc", "docx"));
|
DOCUMENT("document", Arrays.asList("pdf"));
|
||||||
|
|
||||||
|
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import java.util.Optional;
|
|||||||
public interface FileEntityRepository extends JpaRepository<FileEntity, String> {
|
public interface FileEntityRepository extends JpaRepository<FileEntity, String> {
|
||||||
List<FileEntity> findByUserId(Long userId);
|
List<FileEntity> findByUserId(Long userId);
|
||||||
|
|
||||||
|
FileEntity findByIdAndUserId(String id, Long userId);
|
||||||
|
|
||||||
Optional<FileEntity> findByUserIdAndChecksum(Long userId, String imageHash);
|
Optional<FileEntity> findByUserIdAndChecksum(Long userId, String imageHash);
|
||||||
|
|
||||||
List<FileEntity> findByUserIdAndStatus(Long userId, FileStatus status);
|
List<FileEntity> findByUserIdAndStatus(Long userId, FileStatus status);
|
||||||
|
|||||||
@@ -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);
|
return fileEntityService.getFileById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable File getDocument(@NotNull String id) {
|
||||||
|
return fileEntityService.getFileById(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable File getSignature() {
|
public @Nullable File getSignature() {
|
||||||
File signatureFile = SIGNATURE_FILE_PATH.toFile();
|
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");
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user