|
|
@@ -1,15 +1,21 @@
|
|
|
package cn.reghao.dfs.store.oss.controller;
|
|
|
|
|
|
+import cn.reghao.dfs.store.oss.model.FileMeta;
|
|
|
import cn.reghao.dfs.store.oss.model.object.DeleteObjects;
|
|
|
-import cn.reghao.dfs.store.oss.model.object.PostObject;
|
|
|
+import cn.reghao.dfs.store.oss.service.ObjectService;
|
|
|
import cn.reghao.jutil.jdk.result.WebBody;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.rocksdb.RocksDBException;
|
|
|
+import org.springframework.core.io.InputStreamResource;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -19,15 +25,94 @@ import java.util.Map;
|
|
|
@RestController
|
|
|
@RequestMapping("/object")
|
|
|
public class ObjectController {
|
|
|
+ private final ObjectService objectService;
|
|
|
+
|
|
|
+ public ObjectController(ObjectService objectService) {
|
|
|
+ this.objectService = objectService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("上传对象")
|
|
|
+ @PutMapping(value = "/{objectName:.+}")
|
|
|
+ public String putObject(@PathVariable("objectName") String objectName, MultipartFile file) throws Exception {
|
|
|
+ objectService.putObject(objectName, file);
|
|
|
+ return WebBody.success();
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation("使用 formdata 上传对象")
|
|
|
@PostMapping(value = "/")
|
|
|
- public String postObject(@RequestParam("key") String key, @RequestParam("file") MultipartFile file) {
|
|
|
+ public String postObject(@RequestParam("key") String objectName, @RequestParam("file") MultipartFile file) {
|
|
|
return WebBody.success();
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("上传对象")
|
|
|
- @PutMapping(value = "/{objectName}")
|
|
|
- public String putObject(@PathVariable("objectName") String objectName, MultipartFile file) {
|
|
|
+ @ApiOperation("开启分片上传")
|
|
|
+ @PostMapping(value = "/{objectName}", params = {"uploads"})
|
|
|
+ public String initiateMultipartUpload(@PathVariable("objectName") String objectName) {
|
|
|
+ return WebBody.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("分片上传对象")
|
|
|
+ @PutMapping(value = "/{objectName}", params = {"partNumber", "uploadId"})
|
|
|
+ public String uploadPart(@PathVariable("objectName") String objectName,
|
|
|
+ @RequestParam("partNumber") long partNumber,
|
|
|
+ @RequestParam("uploadId") String uploadId,
|
|
|
+ MultipartFile multipartFile) {
|
|
|
+ return WebBody.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "完成分片上传")
|
|
|
+ @PostMapping(value = "/{objectName}", params = {"uploadId"})
|
|
|
+ public String completeMultipartUpload(@PathVariable("objectName") String objectName,
|
|
|
+ @RequestParam("uploadId") String uploadId) {
|
|
|
+ return WebBody.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "终止分片上传")
|
|
|
+ @DeleteMapping(value = "/{objectName}", params = {"uploadId"})
|
|
|
+ public String abortMultipartUpload(@PathVariable("objectName") String objectName,
|
|
|
+ @RequestParam("uploadId") String uploadId) {
|
|
|
+ return WebBody.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("获取分片 uploadId 下的所有分片")
|
|
|
+ @GetMapping(value = "/{objectName}", params = {"uploadId"})
|
|
|
+ public String listParts(@PathVariable("objectName") String objectName, @RequestParam("uploadId") String uploadId) {
|
|
|
+ return WebBody.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("获取对象的元数据")
|
|
|
+ @RequestMapping(value = "/{objectName}", method = RequestMethod.HEAD)
|
|
|
+ public String headObject(@PathVariable("objectName") String objectName) throws RocksDBException {
|
|
|
+ objectService.headObject(objectName);
|
|
|
+ return WebBody.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("获取对象")
|
|
|
+ @GetMapping(value = "/{objectName:.+}")
|
|
|
+ public ResponseEntity<InputStreamResource> getObject(@PathVariable("objectName") String objectName) throws RocksDBException, FileNotFoundException {
|
|
|
+ FileMeta fileMeta = objectService.getObject(objectName);
|
|
|
+ if (fileMeta == null) {
|
|
|
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ String absolutePath = fileMeta.getAbsolutePath();
|
|
|
+ String contentType = fileMeta.getContentType();
|
|
|
+
|
|
|
+ FileInputStream fis = new FileInputStream(absolutePath);
|
|
|
+ InputStreamResource inputStreamResource = new InputStreamResource(fis);
|
|
|
+ return ResponseEntity.status(HttpStatus.OK)
|
|
|
+ .contentType(MediaType.parseMediaType(contentType))
|
|
|
+ .body(inputStreamResource);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除对象")
|
|
|
+ @DeleteMapping(value = "/{objectName}")
|
|
|
+ public String deleteObject(@PathVariable("objectName") String objectName) {
|
|
|
+ return WebBody.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除多个对象")
|
|
|
+ @PostMapping(value = "/", params = {"delete"})
|
|
|
+ public String deleteMultipleObjects(DeleteObjects deleteObjects) {
|
|
|
return WebBody.success();
|
|
|
}
|
|
|
|
|
|
@@ -55,21 +140,6 @@ public class ObjectController {
|
|
|
return WebBody.success();
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("开启分片上传")
|
|
|
- @PostMapping(value = "/{objectName}", params = {"uploads"})
|
|
|
- public String initiateMultipartUpload(@PathVariable("objectName") String objectName) {
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("分片上传对象")
|
|
|
- @PutMapping(value = "/{objectName}", params = {"partNumber", "uploadId"})
|
|
|
- public String uploadPart(@PathVariable("objectName") String objectName,
|
|
|
- @RequestParam("partNumber") long partNumber,
|
|
|
- @RequestParam("uploadId") String uploadId,
|
|
|
- MultipartFile multipartFile) {
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
-
|
|
|
@ApiOperation("复制已存在的对象作为源数据上传分片")
|
|
|
@PutMapping(value = "/{objectName}", params = {"partNumber", "uploadId"}, headers = {"x-amz-copy-source"})
|
|
|
public String uploadPartCopy(@PathVariable("objectName") String objectName,
|
|
|
@@ -79,32 +149,12 @@ public class ObjectController {
|
|
|
return WebBody.success();
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "完成分片上传")
|
|
|
- @PostMapping(value = "/{objectName}", params = {"uploadId"})
|
|
|
- public String completeMultipartUpload(@PathVariable("objectName") String objectName,
|
|
|
- @RequestParam("uploadId") String uploadId) {
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
-
|
|
|
@ApiOperation(value = "对存储类型为 GLACIER 的对象还原临时副本")
|
|
|
@PostMapping(value = "/{objectName}", params = {"restore"})
|
|
|
public String postObjectRestore(@PathVariable("objectName") String objectName) {
|
|
|
return WebBody.success();
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "终止分片上传")
|
|
|
- @DeleteMapping(value = "/{objectName}", params = {"uploadId"})
|
|
|
- public String abortMultipartUpload(@PathVariable("objectName") String objectName,
|
|
|
- @RequestParam("uploadId") String uploadId) {
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("获取对象")
|
|
|
- @GetMapping(value = "/{objectName}")
|
|
|
- public String getObject(@PathVariable("objectName") String objectName) {
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
-
|
|
|
@ApiOperation("获取对象的依法保留状态")
|
|
|
@GetMapping(value = "/{objectKey}", params = {"legal-hold"})
|
|
|
public String getObjectLegalHold(@PathVariable("objectKey") String objectKey) {
|
|
|
@@ -122,28 +172,4 @@ public class ObjectController {
|
|
|
public String getObjectTagging(@PathVariable("objectKey") String objectKey) {
|
|
|
return WebBody.success();
|
|
|
}
|
|
|
-
|
|
|
- @ApiOperation("获取对象的元数据")
|
|
|
- @RequestMapping(value = "/{objectName}", method = RequestMethod.HEAD)
|
|
|
- public String headObject(@PathVariable("objectName") String objectName) {
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("获取分片 uploadId 下的所有分片")
|
|
|
- @GetMapping(value = "/{objectName}", params = {"uploadId"})
|
|
|
- public String listParts(@PathVariable("objectName") String objectName, @RequestParam("uploadId") String uploadId) {
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "删除对象")
|
|
|
- @DeleteMapping(value = "/{objectName}")
|
|
|
- public String deleteObject(@PathVariable("objectName") String objectName) {
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "删除多个对象")
|
|
|
- @PostMapping(value = "/", params = {"delete"})
|
|
|
- public String deleteMultipleObjects(DeleteObjects deleteObjects) {
|
|
|
- return WebBody.success();
|
|
|
- }
|
|
|
}
|