hejianhao
2026-09-01 540ef65220e05b75c183cd3554aaeb554927600a
tcm-training-admin-backend/src/main/java/com/tcm/training/admin/upload/UploadController.java
@@ -1,8 +1,10 @@
package com.tcm.training.admin.upload;
import com.tcm.training.admin.common.ApiResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -14,6 +16,9 @@
import java.util.HashSet;
import java.util.Set;
import javax.validation.Valid;
@Validated
@RestController
@RequestMapping({"/api/v1", "/api"})
public class UploadController {
@@ -40,11 +45,18 @@
    private static final String PLATFORM_IOS = "IOS";
    private final ObsUploadService obsUploadService;
    private final LocalAppPackageStorageService localAppPackageStorageService;
    private final UploadProgressService uploadProgressService;
    private final RemoteVideoDurationService remoteVideoDurationService;
    public UploadController(ObsUploadService obsUploadService, UploadProgressService uploadProgressService) {
    public UploadController(ObsUploadService obsUploadService,
                            LocalAppPackageStorageService localAppPackageStorageService,
                            UploadProgressService uploadProgressService,
                            RemoteVideoDurationService remoteVideoDurationService) {
        this.obsUploadService = obsUploadService;
        this.localAppPackageStorageService = localAppPackageStorageService;
        this.uploadProgressService = uploadProgressService;
        this.remoteVideoDurationService = remoteVideoDurationService;
    }
    /**
@@ -65,13 +77,22 @@
        return ApiResponse.ok(storeFile(file, VIDEO_MAX_SIZE, ALLOWED_VIDEO_TYPES, "仅支持 MP4、MOV、AVI、MKV、WebM 格式", "video", uploadTaskId));
    }
    /**
     * 远程视频时长识别。
     */
    @PostMapping("/upload/video/duration")
    public ApiResponse<VideoDurationDetectVO> detectVideoDuration(
            @Valid @RequestBody VideoDurationDetectRequest request) {
        return ApiResponse.ok(remoteVideoDurationService.detectDuration(request.getVideoUrl()));
    }
    @PostMapping("/upload/app-package")
    public ApiResponse<UploadResult> uploadAppPackage(
            @RequestParam("file") MultipartFile file,
            @RequestParam("platform") String platform) throws IOException {
        String normalizedPlatform = normalizePlatform(platform);
        validateAppPackage(file, normalizedPlatform);
        UploadFileResult uploadResult = obsUploadService.upload(file, "app-package/" + normalizedPlatform.toLowerCase(), null);
        UploadFileResult uploadResult = localAppPackageStorageService.store(file, normalizedPlatform);
        return ApiResponse.ok(new UploadResult(uploadResult.getUrl(), uploadResult.getFileName()));
    }