@@ -401,14 +401,14 @@ public class ApiController {
|
||||
public ResponseEntity<?> check(@PathVariable(required = false) String fileId,
|
||||
@PathVariable(required = false) String type) {
|
||||
Optional<FileEntity> optionalFileEntity = fileEntityRepository.findById(fileId);
|
||||
|
||||
if (!optionalFileEntity.isPresent()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
FileEntity fileEntity = optionalFileEntity.get();
|
||||
|
||||
Path path = type.toLowerCase().equals("image") ? Paths.get(fileEntity.getFilePath()) :
|
||||
Paths.get(fileEntity.getProtectedFilePath());
|
||||
Path path = Paths.get(fileEntity.getProtectedFilePath());
|
||||
|
||||
File file = path.toFile();
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ public enum MessageCode {
|
||||
FILE_NOT_FOUND(4, "File not found"),
|
||||
AUTH_PASSWORD_NOT_MATCHES(2, "Password does not match"),
|
||||
SEND_EMAIL_EXCEPTION(2, "Send email exception"),
|
||||
SIMILAR_FILES_FOUND(0, "Similar files found");
|
||||
SIMILAR_FILES_FOUND(0, "Similar files found"),
|
||||
FILE_IS_PROTECTED(0, "File is protected"),
|
||||
FILE_IS_NOT_PROTECTED(0, "File is not protected");
|
||||
|
||||
private final Integer code;
|
||||
|
||||
|
||||
@@ -8,16 +8,17 @@ import ru.soune.nocopy.dto.*;
|
||||
import ru.soune.nocopy.dto.file.*;
|
||||
import ru.soune.nocopy.entity.file.FileEntity;
|
||||
import ru.soune.nocopy.entity.file.FileStatus;
|
||||
import ru.soune.nocopy.entity.file.ProtectionStatus;
|
||||
import ru.soune.nocopy.exception.FileEntityNotFoundException;
|
||||
import ru.soune.nocopy.exception.NotFoundAuthToken;
|
||||
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.repository.ImageHashRepository;
|
||||
import ru.soune.nocopy.service.register.AuthService;
|
||||
import ru.soune.nocopy.service.file.FileEntityService;
|
||||
import ru.soune.nocopy.service.file.FileStatsService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -34,8 +35,6 @@ public class FileEntityHandler implements RequestHandler {
|
||||
|
||||
private final FileEntityRepository fileEntityRepository;
|
||||
|
||||
private final ImageHashRepository imageHashRepository;
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) {
|
||||
try {
|
||||
@@ -57,6 +56,8 @@ public class FileEntityHandler implements RequestHandler {
|
||||
return handleSearchFiles(request, fileRequest);
|
||||
case "storage_usage":
|
||||
return handleGetStorageUsage(request, fileRequest);
|
||||
case "check_protected":
|
||||
return handleProtectFile(request, fileRequest);
|
||||
case "delete_file":
|
||||
return handleDeleteFile(request, fileRequest);
|
||||
default:
|
||||
@@ -259,6 +260,29 @@ public class FileEntityHandler implements RequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private BaseResponse handleProtectFile(BaseRequest request, FileEntityRequest fileRequest) {
|
||||
String fileId = fileRequest.getFileId();
|
||||
Optional<FileEntity> optionalFileEntity = fileEntityRepository.findById(fileId);
|
||||
|
||||
if (optionalFileEntity.isEmpty()) {
|
||||
return new BaseResponse(request.getMsgId(),
|
||||
MessageCode.FILE_NOT_FOUND.getCode(),
|
||||
"File not found exception: " + fileRequest.getFileId(),
|
||||
null);
|
||||
}
|
||||
|
||||
FileEntity fileEntity = optionalFileEntity.get();
|
||||
ProtectionStatus protectionStatus = fileEntity.getProtectionStatus();
|
||||
|
||||
Integer code = protectionStatus == ProtectionStatus.PROTECTED ? MessageCode.FILE_IS_PROTECTED.getCode():
|
||||
MessageCode.FILE_IS_NOT_PROTECTED.getCode();
|
||||
String message = protectionStatus == ProtectionStatus.PROTECTED ? MessageCode.FILE_IS_PROTECTED.getDescription():
|
||||
MessageCode.FILE_IS_NOT_PROTECTED.getDescription();
|
||||
|
||||
return new BaseResponse(request.getMsgId(), code, message, fileEntityService.getById(fileId,
|
||||
request.getVersion()));
|
||||
}
|
||||
|
||||
private BaseResponse handleDeleteFile(BaseRequest request, FileEntityRequest fileRequest) {
|
||||
try {
|
||||
Long userId = authService.useUserAuthToken(fileRequest.getToken());
|
||||
|
||||
Reference in New Issue
Block a user