|
|
@@ -1,22 +1,15 @@
|
|
|
package cn.reghao.dfs.store.controller;
|
|
|
|
|
|
-import cn.reghao.dfs.store.model.s3.*;
|
|
|
-import cn.reghao.dfs.store.service.FileStoreService;
|
|
|
-import cn.reghao.dfs.store.util.s3.OssUtil;
|
|
|
-import cn.reghao.jutil.jdk.converter.ByteHex;
|
|
|
+import cn.reghao.dfs.store.model.dto.FilePartRet;
|
|
|
+import cn.reghao.dfs.store.model.dto.UploadFilePart;
|
|
|
+import cn.reghao.dfs.store.model.dto.UploadPrepare;
|
|
|
+import cn.reghao.dfs.store.model.dto.UploadPrepareRet;
|
|
|
+import cn.reghao.dfs.store.service.ObjectMultipartUploadService;
|
|
|
import cn.reghao.jutil.jdk.result.WebResult;
|
|
|
-import cn.reghao.jutil.jdk.security.Base64Util;
|
|
|
-import cn.reghao.jutil.jdk.security.DigestUtil;
|
|
|
import org.springframework.http.MediaType;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
-import java.text.DateFormat;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
@@ -25,121 +18,36 @@ import java.util.*;
|
|
|
*/
|
|
|
@RestController
|
|
|
public class ObjectMultipartUploadController {
|
|
|
- private static final Map<String, Map<Long, String>> map = new TreeMap<>();
|
|
|
- private final FileStoreService storeService;
|
|
|
+ private final ObjectMultipartUploadService objectMultipartUploadService;
|
|
|
|
|
|
- public ObjectMultipartUploadController(FileStoreService storeService) {
|
|
|
- this.storeService = storeService;
|
|
|
+ public ObjectMultipartUploadController(ObjectMultipartUploadService objectMultipartUploadService) {
|
|
|
+ this.objectMultipartUploadService = objectMultipartUploadService;
|
|
|
}
|
|
|
|
|
|
- @PostMapping(value = "/**", params = {"uploads"})
|
|
|
- public ResponseEntity<InitiateMultipartUploadResult> initiateMultipartUpload() {
|
|
|
- String objectName = OssUtil.getObjectName();
|
|
|
-
|
|
|
- String bucket = "tnb";
|
|
|
- String uploadId = UUID.randomUUID().toString().replace("-", "");
|
|
|
- map.put(uploadId, new HashMap<>());
|
|
|
- InitiateMultipartUploadResult result = new InitiateMultipartUploadResult(bucket, objectName, uploadId);
|
|
|
- return ResponseEntity.ok()
|
|
|
- .contentType(MediaType.APPLICATION_XML)
|
|
|
- .body(result);
|
|
|
+ @PostMapping(value = "/", params = {"create"}, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String videoFilePrepare(@Validated UploadPrepare uploadPrepare) {
|
|
|
+ UploadPrepareRet uploadPrepareRet = objectMultipartUploadService.prepareUpload(uploadPrepare);
|
|
|
+ return WebResult.success(uploadPrepareRet);
|
|
|
}
|
|
|
|
|
|
- @PutMapping(value = "/**", params = {"partNumber", "uploadId"})
|
|
|
- public ResponseEntity<String> uploadPart(@RequestParam("partNumber") long partNumber,
|
|
|
- @RequestParam("uploadId") String uploadId,
|
|
|
- @RequestBody File file) throws IOException, NoSuchAlgorithmException {
|
|
|
-
|
|
|
- map.get(uploadId).put(partNumber, file.getAbsolutePath());
|
|
|
-
|
|
|
- FileInputStream fis = new FileInputStream(file);
|
|
|
- byte[] md5 = DigestUtil.md5sum(fis.readAllBytes());
|
|
|
- String md5Hex = ByteHex.bytes2Hex(md5);
|
|
|
- String md5Base64 = Base64Util.encode(md5);
|
|
|
-
|
|
|
- DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", Locale.CHINA);
|
|
|
- df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
- String dateStr = df.format(new Date());
|
|
|
-
|
|
|
- return ResponseEntity.ok()
|
|
|
- .header("x-amz-request-id", UUID.randomUUID().toString().replace("-", ""))
|
|
|
- .header("Date", dateStr)
|
|
|
- .header("Content-Length", String.valueOf(file.length()))
|
|
|
- .header("Connection", "keep-alive")
|
|
|
- .header("Server", "TNBCloudOSS")
|
|
|
- .eTag(md5Hex)
|
|
|
- .build();
|
|
|
+ @GetMapping(value = "/", params = {"multipart"}, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String uploadedVideoFilePart() {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("skipUpload", false);
|
|
|
+ map.put("url", "");
|
|
|
+ map.put("needMerge", false);
|
|
|
+ map.put("uploaded", Collections.emptyList());
|
|
|
+ return WebResult.success(map);
|
|
|
}
|
|
|
|
|
|
- @PostMapping(value = "/**", params = {"uploadId"}, consumes = MediaType.APPLICATION_XML_VALUE)
|
|
|
- public ResponseEntity<CompleteMultipartUploadResult> completeMultipartUpload(@RequestParam("uploadId") String uploadId,
|
|
|
- @RequestBody CompleteMultipartUpload completeMultipartUpload) {
|
|
|
- List<Part> parts = completeMultipartUpload.getParts();
|
|
|
- String absolutePath = "/home/reghao/Downloads/test.dat";
|
|
|
- try {
|
|
|
- int start = 0;
|
|
|
- for (Map.Entry<Long, String> entry : map.get(uploadId).entrySet()) {
|
|
|
- Long index = entry.getKey();
|
|
|
- String path = entry.getValue();
|
|
|
- File file = new File(path);
|
|
|
- long length = file.length();
|
|
|
- FileInputStream fis = new FileInputStream(file);
|
|
|
- storeService.writeToFile(fis, absolutePath, start);
|
|
|
- start += length;
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- String location = "oss.reghao.cn";
|
|
|
- String bucket = "tnb";
|
|
|
- String key = "a/b/c";
|
|
|
- String eTag = "1234567890abcde";
|
|
|
- CompleteMultipartUploadResult result = new CompleteMultipartUploadResult(location, bucket, key, eTag);
|
|
|
- return ResponseEntity.ok()
|
|
|
- .contentType(MediaType.APPLICATION_XML)
|
|
|
- .body(result);
|
|
|
+ @PostMapping(value = "/", params = {"multipart"}, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String uploadVideoFile0(@Validated UploadFilePart uploadFilePart) throws Exception {
|
|
|
+ FilePartRet uploadedFileRet = objectMultipartUploadService.putFilePart(uploadFilePart);
|
|
|
+ return WebResult.success(uploadedFileRet);
|
|
|
}
|
|
|
|
|
|
- @DeleteMapping(value = "/**", params = {"uploadId"})
|
|
|
- public String abortMultipartUpload(@RequestParam("uploadId") String uploadId) {
|
|
|
- Map<Long, String> fileMap = map.get(uploadId);
|
|
|
-
|
|
|
+ @PostMapping(value = "/", params = {"merge"}, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public String merge() {
|
|
|
return WebResult.success();
|
|
|
}
|
|
|
-
|
|
|
- @GetMapping(value = "/**", params = {"uploadId"})
|
|
|
- public ResponseEntity<ListPartsResult> listParts(@RequestParam("uploadId") String uploadId,
|
|
|
- @RequestParam(value = "encodingType", required = false) String encodingType,
|
|
|
- @RequestParam(value = "maxParts", required = false) String maxParts,
|
|
|
- @RequestParam(value = "partNumberMarker", required = false) String partNumberMarker) {
|
|
|
- ListPartsResult listPartsResult = new ListPartsResult();
|
|
|
- listPartsResult.setBucket("");
|
|
|
- listPartsResult.setKey("");
|
|
|
- listPartsResult.setUploadId("");
|
|
|
- listPartsResult.setInitiator(new Initiator());
|
|
|
- listPartsResult.setOwner(new Owner());
|
|
|
- listPartsResult.setStorageClass("");
|
|
|
- listPartsResult.setPartNumberMarker(10);
|
|
|
- listPartsResult.setNextPartNumberMarker(10);
|
|
|
- // 表示列表已完全返回
|
|
|
- listPartsResult.setTruncated(false);
|
|
|
-
|
|
|
- List<Part> list = new ArrayList<>();
|
|
|
- list.add(new Part());
|
|
|
- listPartsResult.setParts(list);
|
|
|
-
|
|
|
- return ResponseEntity.ok()
|
|
|
- .contentType(MediaType.APPLICATION_XML)
|
|
|
- .body(listPartsResult);
|
|
|
- }
|
|
|
-
|
|
|
- @PutMapping(value = "/**", params = {"partNumber", "uploadId"}, headers = {"x-amz-copy-source"})
|
|
|
- public ResponseEntity<CopyPartResult> uploadPartCopy(@RequestParam("partNumber") long partNumber,
|
|
|
- @RequestParam("uploadId") String uploadId) {
|
|
|
- CopyPartResult result = new CopyPartResult();
|
|
|
- return ResponseEntity.ok()
|
|
|
- .contentType(MediaType.APPLICATION_XML)
|
|
|
- .body(result);
|
|
|
- }
|
|
|
}
|