From 506b7d5577e797cb65b89e953daed75da0d6512b Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期二, 28 四月 2026 14:22:39 +0800
Subject: [PATCH] 修改上传文件相关

---
 src/main/java/com/ruoyi/project/common/CommonController.java |   35 +++++++++++++++++++++++++++++------
 1 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/ruoyi/project/common/CommonController.java b/src/main/java/com/ruoyi/project/common/CommonController.java
index bf7bda4..9ee3c93 100644
--- a/src/main/java/com/ruoyi/project/common/CommonController.java
+++ b/src/main/java/com/ruoyi/project/common/CommonController.java
@@ -128,15 +128,32 @@
 //    }
     @PostMapping({"/upload"})
     @Operation(summary = "鏂囦欢涓婁紶")
-    public R upload(@RequestParam("files") List<MultipartFile> files) throws Exception {
-        return R.ok(storageBlobService.upload(files));
+    public R upload(@RequestParam("files") List<MultipartFile> files) {
+        return R.ok(storageBlobService.upload(files, false));
     }
 
+    /**
+     * 鍏叡鏂囦欢涓婁紶
+     * 姝ゆ帴鍙d笂浼犵殑鏂囦欢姘镐箙鏈夋晥锛屾厧鐢�
+     */
+    @PostMapping({"/public/upload"})
+    @Operation(summary = "鏂囦欢涓婁紶")
+    public R publicUpload(@RequestParam("files") List<MultipartFile> files) {
+        return R.ok(storageBlobService.upload(files, true));
+    }
 
     @GetMapping("/download/{fileName}")
     @Anonymous
-    public void download(@PathVariable String fileName, @RequestParam("token") String token, HttpServletResponse response) throws Exception {
-        File file = storageBlobService.getFileByToken(fileName, token);
+    public void download(@PathVariable String fileName,
+                         @RequestParam(value = "token", required = false) String token,
+                         @RequestParam(value = "publicKey", required = false) String publicKey,
+                         HttpServletResponse response) throws Exception {
+        File file;
+        if (publicKey != null) {
+            file = fileUtil.compressFile(storageBlobService.getPublicFile(fileName, publicKey));
+        } else {
+            file = fileUtil.compressFile(storageBlobService.getFileByToken(fileName, token));
+        }
         String originalFileName = storageBlobService.getDownloadFileName(fileName);
         String encodedFileName = URLEncoder.encode(originalFileName, StandardCharsets.UTF_8.name()).replace("+", "%20");
         response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + encodedFileName);
@@ -147,8 +164,14 @@
     @GetMapping("/preview/{fileName}")
     @Anonymous
     public ResponseEntity<FileSystemResource> preview(@PathVariable String fileName,
-                                                      @RequestParam("token") String token) throws Exception {
-        File file = fileUtil.compressFile(storageBlobService.getFileByToken(fileName, token));
+                                                      @RequestParam(value = "token", required = false) String token,
+                                                      @RequestParam(value = "publicKey", required = false) String publicKey) throws Exception {
+        File file;
+        if (publicKey != null) {
+            file = fileUtil.compressFile(storageBlobService.getPublicFile(fileName, publicKey));
+        } else {
+            file = fileUtil.compressFile(storageBlobService.getFileByToken(fileName, token));
+        }
         String contentType = Files.probeContentType(file.toPath());
 
         ContentDisposition contentDisposition = ContentDisposition.inline()

--
Gitblit v1.9.3