This commit is contained in:
@@ -2,8 +2,8 @@ package ru.soune.nocopy.controller;
|
||||
|
||||
import com.vrt.NoCopyFileService;
|
||||
import com.vrt.fileprotection.FileProtector;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -17,6 +17,7 @@ import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.file.CheckCounterService;
|
||||
import ru.soune.nocopy.service.file.FileStorageService;
|
||||
import ru.soune.nocopy.service.file.ImageResizeService;
|
||||
import ru.soune.nocopy.service.file.ZipService;
|
||||
import ru.soune.nocopy.util.FileUtil;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -31,29 +32,25 @@ import java.nio.file.Paths;
|
||||
@RestController
|
||||
@RequestMapping("/api/files")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class FileController {
|
||||
|
||||
@Autowired
|
||||
private FileStorageService fileStorageService;
|
||||
|
||||
@Autowired
|
||||
private FileEntityRepository fileRepository;
|
||||
|
||||
@Autowired
|
||||
private CheckCounterService checkCounterService;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private ImageResizeService imageResizeService;
|
||||
|
||||
@Autowired
|
||||
private NoCopyFileService noCopyFileService;
|
||||
|
||||
@Autowired
|
||||
private FileUtil fileUtil;
|
||||
|
||||
private ZipService zipService;
|
||||
|
||||
@GetMapping("/public/{fileId}")
|
||||
public ResponseEntity<Resource> getPublicFile(@PathVariable String fileId) {
|
||||
try {
|
||||
@@ -166,4 +163,21 @@ public class FileController {
|
||||
.ok()
|
||||
.body(fileInfo);
|
||||
}
|
||||
|
||||
@GetMapping("/download/user-passport/archive/{userId}")
|
||||
public ResponseEntity<byte[]> downloadPassportZip(@PathVariable Long userId) {
|
||||
try {
|
||||
byte[] zipBytes = zipService.assembleZipFromSplitFiles(userId);
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=passport_" + userId + ".zip")
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.contentLength(zipBytes.length)
|
||||
.body(zipBytes);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to assemble passport for user {}", userId, e);
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user