|
|
@@ -4,9 +4,8 @@ import cn.reghao.dfs.store.model.dto.*;
|
|
|
import cn.reghao.dfs.store.model.po.VideoFile;
|
|
|
import cn.reghao.dfs.store.model.vo.*;
|
|
|
import cn.reghao.dfs.store.service.FileUploadService;
|
|
|
-import cn.reghao.dfs.store.service.media.ImageFileService;
|
|
|
-import cn.reghao.jutil.jdk.result.WebBody;
|
|
|
import cn.reghao.dfs.store.service.media.VideoFileService;
|
|
|
+import cn.reghao.jutil.jdk.result.WebBody;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -15,74 +14,37 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import javax.validation.constraints.NotNull;
|
|
|
-
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2022-04-28 13:56:13
|
|
|
*/
|
|
|
-@Api(tags = "媒体文件上传接口")
|
|
|
+@Api(tags = "视频文件上传接口")
|
|
|
@RestController
|
|
|
@RequestMapping("/api/file/upload")
|
|
|
@Slf4j
|
|
|
-public class MediaUploadController {
|
|
|
+public class VideoUploadController {
|
|
|
private final FileUploadService fileUploadService;
|
|
|
private final VideoFileService videoService;
|
|
|
- private final ImageFileService imageFileService;
|
|
|
|
|
|
- public MediaUploadController(FileUploadService fileUploadService, VideoFileService videoService,
|
|
|
- ImageFileService imageFileService) {
|
|
|
+ public VideoUploadController(FileUploadService fileUploadService, VideoFileService videoService) {
|
|
|
this.fileUploadService = fileUploadService;
|
|
|
- this.videoService = videoService;
|
|
|
- this.imageFileService = imageFileService;
|
|
|
+ this.videoService = videoService;;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "上传小图片(小于 1MiB)")
|
|
|
- @PostMapping(value = "/img", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public String uploadSmallImage(@NotNull MultipartFile file) throws Exception {
|
|
|
- String contentType = file.getContentType();
|
|
|
- if (contentType == null || !contentType.startsWith("image")) {
|
|
|
- return WebBody.failWithMsg("content-type 错误");
|
|
|
- }
|
|
|
-
|
|
|
- long size = file.getSize();
|
|
|
- if (size > 1024*1024) {
|
|
|
- return WebBody.failWithMsg("仅支持小于 1MiB 的图片");
|
|
|
- }
|
|
|
-
|
|
|
- UploadingFile uploadingFile = new UploadingFile(file);
|
|
|
- UploadedFile uploadedFile = fileUploadService.put(uploadingFile);
|
|
|
- ImageFileRet imageFileRet = imageFileService.process(uploadedFile);
|
|
|
-
|
|
|
- UploadFileRet uploadFileRet = new UploadFileRet(uploadedFile.getUploadId(), uploadedFile.getPathUrl().getUrl());
|
|
|
- return WebBody.success(uploadFileRet);
|
|
|
- }
|
|
|
+ @ApiOperation(value = "上传视频封面")
|
|
|
+ @PostMapping(value = "/video/cover", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String uploadVideoCover(@Validated VideoCover videoCover) throws Exception {
|
|
|
+ String videoFileId = videoCover.getVideoFileId();
|
|
|
+ MultipartFile file = videoCover.getFile();
|
|
|
|
|
|
- @ApiOperation(value = "上传图片文件")
|
|
|
- @PostMapping(value = "/image", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public String uploadImageFile(@NotNull MultipartFile file) throws Exception {
|
|
|
String contentType = file.getContentType();
|
|
|
if (contentType == null || !contentType.startsWith("image")) {
|
|
|
return WebBody.failWithMsg("content-type 错误");
|
|
|
}
|
|
|
|
|
|
UploadingFile uploadingFile = new UploadingFile(file);
|
|
|
- UploadedFile uploadedFile = fileUploadService.put(uploadingFile);
|
|
|
- ImageFileRet imageFileRet = imageFileService.process(uploadedFile);
|
|
|
- return WebBody.success(imageFileRet);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "上传小视频文件(20 MiB 以内)")
|
|
|
- @PostMapping(value = "/vid", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public String uploadVidFile(@NotNull MultipartFile file) throws Exception {
|
|
|
- String contentType = file.getContentType();
|
|
|
- if (contentType == null || !contentType.startsWith("video")) {
|
|
|
- return WebBody.failWithMsg("content-type 错误");
|
|
|
- }
|
|
|
-
|
|
|
- String uploadId = "";
|
|
|
- VideoFile videoFile = new VideoFile();
|
|
|
- return WebBody.success(new VideoFileRet(uploadId, videoFile));
|
|
|
+ videoService.setVideoCover(videoFileId, uploadingFile);
|
|
|
+ return WebBody.success();
|
|
|
}
|
|
|
|
|
|
@ApiOperation("文件上传前的准备, 客户端传递文件的 sha256sum, 文件若存在则直接返回文件关联的 id")
|
|
|
@@ -92,11 +54,11 @@ public class MediaUploadController {
|
|
|
return WebBody.success(uploadPrepareRet);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "上传视频文件")
|
|
|
+ @ApiOperation(value = "获取已上传的视频文件分片")
|
|
|
@GetMapping(value = "/video", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public String uploadVideoFile1() throws Exception {
|
|
|
- log.info("视频文件");
|
|
|
- return WebBody.success();
|
|
|
+ public String uploadedVideoFilePart() {
|
|
|
+ log.info("已上传的视频文件分片(待实现)");
|
|
|
+ return WebBody.failWithMsg("已上传的视频文件分片(待实现)");
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "上传视频分片文件")
|
|
|
@@ -114,23 +76,7 @@ public class MediaUploadController {
|
|
|
return WebBody.success(new VideoFileRet(uploadId, videoFile));
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "上传视频封面")
|
|
|
- @PostMapping(value = "/video/cover", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public String uploadVideoCover(@Validated VideoCover videoCover) throws Exception {
|
|
|
- String videoFileId = videoCover.getVideoFileId();
|
|
|
- MultipartFile file = videoCover.getFile();
|
|
|
-
|
|
|
- String contentType = file.getContentType();
|
|
|
- if (contentType == null || !contentType.startsWith("image")) {
|
|
|
- return WebBody.failWithMsg("content-type 错误");
|
|
|
- }
|
|
|
-
|
|
|
- UploadingFile uploadingFile = new UploadingFile(file);
|
|
|
- videoService.setVideoCover(videoFileId, uploadingFile);
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "上传视频分片文件")
|
|
|
+ @ApiOperation(value = "处理爬取视频的数据(弃用)")
|
|
|
@PostMapping(value = "/video1", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@Deprecated
|
|
|
public String uploadVideoFile1(@RequestBody @Validated VideoFileSbt videoFileSbt) {
|