Administrator
3 days ago 733330ec04627a7d12bff86f36e3b07751bba50a
feat(fileUpload): 实现多租户文件上传隔离功能

- 将上传目录从固定路径改为可配置的基础目录
- 添加公司ID获取方法实现多租户支持
- 为每个公司创建独立的上传目录结构
- 为每个公司创建独立的分片存储目录
- 修改文件操作逻辑以使用公司专属路径
- 更新视频播放接口使用公司目录
- 调整文件列表和删除功能支持按公司隔离
1 files modified
25 ■■■■ changed files
src/main/java/cc/mrbird/febs/ai/controller/fileUpload/FileUploadController.java 25 ●●●● patch | view | raw | blame | history
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);