From 733330ec04627a7d12bff86f36e3b07751bba50a Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 14 Jan 2026 10:37:15 +0800
Subject: [PATCH] feat(fileUpload): 实现多租户文件上传隔离功能

---
 src/main/java/cc/mrbird/febs/ai/controller/fileUpload/FileUploadController.java |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/ai/controller/fileUpload/FileUploadController.java b/src/main/java/cc/mrbird/febs/ai/controller/fileUpload/FileUploadController.java
index 1f1c849..d01bf06 100644
--- a/src/main/java/cc/mrbird/febs/ai/controller/fileUpload/FileUploadController.java
+++ b/src/main/java/cc/mrbird/febs/ai/controller/fileUpload/FileUploadController.java
@@ -28,11 +28,11 @@
 @RequestMapping(value = "/fileUpload")
 public class FileUploadController extends BaseController {
 
-    // @Value("${file.upload.dir}")
-    private String uploadDir = "d:/upload/files";
+    // 基础上传目录
+    private String baseUploadDir = "/home/javaweb/webresource/ai";
 
-    // @Value("${file.chunk.dir}")
-    private String chunkDir = "d:/upload/chunks";
+    // 分片存储目录
+    private String baseChunkDir = "/home/javaweb/webresource/ai/chunks";
 
     /**
      * 上传文件分片
@@ -44,6 +44,9 @@
                                     @RequestParam("chunks") int chunks,
                                     @RequestParam("fileMd5") String fileMd5) {
         try {
+            String companyId = getCurrentUserCompanyId();
+            // 构建公司专属分片目录
+            String chunkDir = baseChunkDir + "/" + companyId;
             // 确保分片目录存在
             Path chunkPath = Paths.get(chunkDir, fileMd5);
             if (!Files.exists(chunkPath)) {
@@ -69,6 +72,10 @@
                                     @RequestParam("fileMd5") String fileMd5,
                                     @RequestParam("chunks") int chunks) {
         try {
+
+            String companyId = getCurrentUserCompanyId();
+            // 构建公司专属上传目录
+            String uploadDir = baseUploadDir + "/" + companyId;
             // 确保上传目录存在
             Path uploadPath = Paths.get(uploadDir);
             if (!Files.exists(uploadPath)) {
@@ -79,6 +86,8 @@
             String uniqueFileName = UUID.randomUUID().toString() + "_" + fileName;
             Path targetFilePath = uploadPath.resolve(uniqueFileName);
 
+            // 构建公司专属分片目录
+            String chunkDir = baseChunkDir + "/" + companyId;
             // 确保分片目录存在
             Path chunkPath = Paths.get(chunkDir, fileMd5);
             if (!Files.exists(chunkPath)) {
@@ -118,6 +127,8 @@
     @GetMapping("/play/{fileName}")
     public void playVideo(@PathVariable("fileName") String fileName, HttpServletResponse response) {
         try {
+            String companyId = getCurrentUserCompanyId();
+            String uploadDir = baseUploadDir + "/" + companyId;
             Path filePath = Paths.get(uploadDir, fileName);
             if (!Files.exists(filePath)) {
                 response.setStatus(HttpStatus.NOT_FOUND.value());
@@ -150,6 +161,9 @@
     @GetMapping("/list")
     public FebsResponse getFileList() {
         try {
+
+            String companyId = getCurrentUserCompanyId();
+            String uploadDir = baseUploadDir + "/" + companyId;
             Path uploadPath = Paths.get(uploadDir);
             if (!Files.exists(uploadPath)) {
                 return new FebsResponse().data(new ArrayList<>());
@@ -183,6 +197,9 @@
     @PostMapping("/delete")
     public FebsResponse deleteFile(@RequestParam("fileName") String fileName) {
         try {
+
+            String companyId = getCurrentUserCompanyId();
+            String uploadDir = baseUploadDir + "/" + companyId;
             Path filePath = Paths.get(uploadDir, fileName);
             if (Files.exists(filePath)) {
                 Files.delete(filePath);

--
Gitblit v1.9.1