|
@@ -0,0 +1,104 @@
|
|
|
+package edu.travel.controller;
|
|
|
+
|
|
|
+import edu.travel.adapter.service.upload.UploadAdapter;
|
|
|
+import edu.travel.resp.BaseResponse;
|
|
|
+import edu.travel.rpc.RPCBaseResponse;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/upload")
|
|
|
+public class UploadController {
|
|
|
+ @Autowired
|
|
|
+ private UploadAdapter uploadAdapter;
|
|
|
+ /**
|
|
|
+ * 文件是否存在
|
|
|
+ * @param md5
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/exits/md5")
|
|
|
+ @PreAuthorize("permitAll()")
|
|
|
+ public BaseResponse exitsFile(String md5) {
|
|
|
+ RPCBaseResponse rpcBaseResponse = uploadAdapter.exitsFile(md5);
|
|
|
+ if (rpcBaseResponse != null) {
|
|
|
+ if (rpcBaseResponse.getCode() == 200){
|
|
|
+ return new BaseResponse(200,"success",rpcBaseResponse.getData());
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 上传过哪些分片
|
|
|
+ * @param md5
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/exits/blob")
|
|
|
+ @PreAuthorize("permitAll()")
|
|
|
+ public BaseResponse exitsBlob(String md5) {
|
|
|
+ RPCBaseResponse rpcBaseResponse = uploadAdapter.exitsBlob(md5);
|
|
|
+ if (rpcBaseResponse != null) {
|
|
|
+ if (rpcBaseResponse.getCode() == 200){
|
|
|
+ return new BaseResponse(200,"success",rpcBaseResponse.getData());
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 上传大文件分片
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/uploadBlob")
|
|
|
+ @PreAuthorize("permitAll()")
|
|
|
+ public BaseResponse uploadBigFile(MultipartFile file) {
|
|
|
+ RPCBaseResponse rpcBaseResponse = uploadAdapter.uploadBigFile(file);
|
|
|
+ if (rpcBaseResponse != null) {
|
|
|
+ if (rpcBaseResponse.getCode() == 200){
|
|
|
+ return new BaseResponse(200,"success",rpcBaseResponse.getData());
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 合并大文件
|
|
|
+ * @param json
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/mergeFile")
|
|
|
+ @PreAuthorize("permitAll()")
|
|
|
+ public BaseResponse mergeFile(String json) {
|
|
|
+ RPCBaseResponse rpcBaseResponse = uploadAdapter.mergeFile(json);
|
|
|
+ if (rpcBaseResponse != null) {
|
|
|
+ if (rpcBaseResponse.getCode() == 200){
|
|
|
+ return new BaseResponse(200,"success",rpcBaseResponse.getData());
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 上传小文件
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/upload")
|
|
|
+ @PreAuthorize("permitAll()")
|
|
|
+ public BaseResponse uploadFile(MultipartFile file) {
|
|
|
+ RPCBaseResponse rpcBaseResponse = uploadAdapter.uploadFile(file);
|
|
|
+ if (rpcBaseResponse != null) {
|
|
|
+ if (rpcBaseResponse.getCode() == 200){
|
|
|
+ return new BaseResponse(200,"success",rpcBaseResponse.getData());
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+ return new BaseResponse(500,"request is error",null);
|
|
|
+ }
|
|
|
+}
|