|
|
@@ -1,55 +0,0 @@
|
|
|
-package cn.reghao.dfs.store.controller;
|
|
|
-
|
|
|
-import cn.reghao.dfs.store.model.dto.UploadingFile;
|
|
|
-import cn.reghao.dfs.store.service.FileUploadService;
|
|
|
-import cn.reghao.jutil.jdk.result.WebBody;
|
|
|
-import cn.reghao.dfs.store.db.mapper.FileUserMapper;
|
|
|
-import cn.reghao.dfs.store.model.dto.UploadedFile;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import javax.validation.constraints.NotNull;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author reghao
|
|
|
- * @date 2020-03-11 16:10:16
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@RestController
|
|
|
-@RequestMapping("/api/file/upload/spider")
|
|
|
-@Deprecated
|
|
|
-public class SpiderFileController {
|
|
|
- private final FileUploadService fileUploadService;
|
|
|
- private final FileUserMapper fileUserMapper;
|
|
|
-
|
|
|
- public SpiderFileController(FileUploadService fileUploadService, FileUserMapper fileUserMapper) {
|
|
|
- this.fileUploadService = fileUploadService;
|
|
|
- this.fileUserMapper = fileUserMapper;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "上传文件")
|
|
|
- @PostMapping(value = "/file", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public String uploadFile(@NotNull MultipartFile file, String username) throws Exception {
|
|
|
- String filename = file.getOriginalFilename();
|
|
|
- long size = file.getSize();
|
|
|
- String contentType = Objects.requireNonNull(file.getContentType());
|
|
|
- InputStream inputStream = file.getInputStream();
|
|
|
-
|
|
|
- if (contentType.startsWith("image") || contentType.startsWith("video")) {
|
|
|
- String userId = fileUserMapper.findUserIdByUsername(username);
|
|
|
- if (userId == null) {
|
|
|
- return WebBody.failWithMsg(username + " 不存在");
|
|
|
- }
|
|
|
-
|
|
|
- UploadingFile uploadingFile = new UploadingFile(filename, size, contentType, inputStream);
|
|
|
- UploadedFile uploadedFile = fileUploadService.put(uploadingFile/*, userId*/);
|
|
|
- return WebBody.success(uploadedFile);
|
|
|
- }
|
|
|
- return WebBody.failWithMsg("content-type 错误");
|
|
|
- }
|
|
|
-}
|