云文件系统初始化
This commit is contained in:
@@ -5,6 +5,7 @@ import com.filesystem.entity.FileShare;
|
||||
import com.filesystem.security.UserPrincipal;
|
||||
import com.filesystem.service.FileService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -250,5 +251,37 @@ public class FileController {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/batchDownload")
|
||||
public ResponseEntity<?> batchDownload(
|
||||
@AuthenticationPrincipal UserPrincipal principal,
|
||||
@RequestBody Map<String, List<Long>> request,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<Long> ids = request.get("ids");
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "请选择要下载的文件"));
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] zipBytes = fileService.createZipArchive(ids, principal.getUserId());
|
||||
|
||||
response.setContentType("application/zip");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"download.zip\"");
|
||||
response.setContentLength(zipBytes.length);
|
||||
response.getOutputStream().write(zipBytes);
|
||||
response.getOutputStream().flush();
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
} catch (RuntimeException e) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/movableFolders")
|
||||
public ResponseEntity<?> getMovableFolders(
|
||||
@AuthenticationPrincipal UserPrincipal principal,
|
||||
@RequestParam(required = false) List<Long> excludeIds) {
|
||||
List<FileEntity> folders = fileService.getMovableFolders(principal.getUserId(), excludeIds);
|
||||
return ResponseEntity.ok(Map.of("data", folders));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user