Administrator
4 days ago eafe95f8cc03bc838970ad38a3ce1e44bedfcb5a
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";
    /**
     * 上传文件分片
@@ -42,8 +42,11 @@
                                    @RequestParam("fileName") String fileName,
                                    @RequestParam("chunk") int chunk,
                                    @RequestParam("chunks") int chunks,
                                    @RequestParam("fileMd5") String fileMd5) {
                                    @RequestParam("fileMd5") String fileMd5,
                                    @RequestParam("companyId") String companyId) {
        try {
            // 构建公司专属分片目录
            String chunkDir = baseChunkDir + "/" + companyId;
            // 确保分片目录存在
            Path chunkPath = Paths.get(chunkDir, fileMd5);
            if (!Files.exists(chunkPath)) {
@@ -67,8 +70,11 @@
    @PostMapping("/mergeChunks")
    public FebsResponse mergeChunks(@RequestParam("fileName") String fileName,
                                    @RequestParam("fileMd5") String fileMd5,
                                    @RequestParam("chunks") int chunks) {
                                    @RequestParam("chunks") int chunks,
                                    @RequestParam("companyId") String companyId) {
        try {
            // 构建公司专属上传目录
            String uploadDir = baseUploadDir + "/" + companyId;
            // 确保上传目录存在
            Path uploadPath = Paths.get(uploadDir);
            if (!Files.exists(uploadPath)) {
@@ -79,6 +85,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)) {
@@ -115,9 +123,12 @@
    /**
     * 播放视频文件
     */
    @GetMapping("/play/{fileName}")
    public void playVideo(@PathVariable("fileName") String fileName, HttpServletResponse response) {
    @GetMapping("/play/{companyId}/{fileName}")
    public void playVideo(@PathVariable("companyId") String companyId,
                          @PathVariable("fileName") String fileName,
                          HttpServletResponse response) {
        try {
            String uploadDir = baseUploadDir + "/" + companyId;
            Path filePath = Paths.get(uploadDir, fileName);
            if (!Files.exists(filePath)) {
                response.setStatus(HttpStatus.NOT_FOUND.value());
@@ -147,9 +158,10 @@
    /**
     * 获取文件列表
     */
    @GetMapping("/list")
    public FebsResponse getFileList() {
    @GetMapping("/list/{companyId}")
    public FebsResponse getFileList(@PathVariable("companyId") String companyId) {
        try {
            String uploadDir = baseUploadDir + "/" + companyId;
            Path uploadPath = Paths.get(uploadDir);
            if (!Files.exists(uploadPath)) {
                return new FebsResponse().data(new ArrayList<>());
@@ -181,8 +193,10 @@
     * 删除文件
     */
    @PostMapping("/delete")
    public FebsResponse deleteFile(@RequestParam("fileName") String fileName) {
    public FebsResponse deleteFile(@RequestParam("fileName") String fileName,
                                   @RequestParam("companyId") String companyId) {
        try {
            String uploadDir = baseUploadDir + "/" + companyId;
            Path filePath = Paths.get(uploadDir, fileName);
            if (Files.exists(filePath)) {
                Files.delete(filePath);