format code.

develop-QA
Tom Li 4 months ago
parent 9c9a13e5f3
commit dec68ef103
  1. 394
      blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/OssEndpoint.java

@ -53,202 +53,202 @@ import org.springframework.web.multipart.MultipartFile;
@Tag(name = "对象存储端点", description = "对象存储端点") @Tag(name = "对象存储端点", description = "对象存储端点")
public class OssEndpoint { public class OssEndpoint {
/** /**
* 对象存储构建类 * 对象存储构建类
*/ */
private final OssBuilder ossBuilder; private final OssBuilder ossBuilder;
/** /**
* 附件表服务 * 附件表服务
*/ */
private final IAttachService attachService; private final IAttachService attachService;
/** /**
* 创建存储桶 * 创建存储桶
* *
* @param bucketName 存储桶名称 * @param bucketName 存储桶名称
* @return Bucket * @return Bucket
*/ */
@SneakyThrows @SneakyThrows
@IsAdmin @IsAdmin
@PostMapping("/make-bucket") @PostMapping("/make-bucket")
public R makeBucket(@RequestParam String bucketName) { public R makeBucket(@RequestParam String bucketName) {
ossBuilder.template().makeBucket(bucketName); ossBuilder.template().makeBucket(bucketName);
return R.success("创建成功"); return R.success("创建成功");
} }
/** /**
* 创建存储桶 * 创建存储桶
* *
* @param bucketName 存储桶名称 * @param bucketName 存储桶名称
* @return R * @return R
*/ */
@SneakyThrows @SneakyThrows
@IsAdmin @IsAdmin
@PostMapping("/remove-bucket") @PostMapping("/remove-bucket")
public R removeBucket(@RequestParam String bucketName) { public R removeBucket(@RequestParam String bucketName) {
ossBuilder.template().removeBucket(bucketName); ossBuilder.template().removeBucket(bucketName);
return R.success("删除成功"); return R.success("删除成功");
} }
/** /**
* 拷贝文件 * 拷贝文件
* *
* @param fileName 存储桶对象名称 * @param fileName 存储桶对象名称
* @param destBucketName 目标存储桶名称 * @param destBucketName 目标存储桶名称
* @param destFileName 目标存储桶对象名称 * @param destFileName 目标存储桶对象名称
* @return R * @return R
*/ */
@SneakyThrows @SneakyThrows
@PostMapping("/copy-file") @PostMapping("/copy-file")
public R copyFile(@RequestParam String fileName, @RequestParam String destBucketName, String destFileName) { public R copyFile(@RequestParam String fileName, @RequestParam String destBucketName, String destFileName) {
ossBuilder.template().copyFile(fileName, destBucketName, destFileName); ossBuilder.template().copyFile(fileName, destBucketName, destFileName);
return R.success("操作成功"); return R.success("操作成功");
} }
/** /**
* 获取文件信息 * 获取文件信息
* *
* @param fileName 存储桶对象名称 * @param fileName 存储桶对象名称
* @return InputStream * @return InputStream
*/ */
@SneakyThrows @SneakyThrows
@GetMapping("/stat-file") @GetMapping("/stat-file")
public R<OssFile> statFile(@RequestParam String fileName) { public R<OssFile> statFile(@RequestParam String fileName) {
return R.data(ossBuilder.template().statFile(fileName)); return R.data(ossBuilder.template().statFile(fileName));
} }
/** /**
* 获取文件相对路径 * 获取文件相对路径
* *
* @param fileName 存储桶对象名称 * @param fileName 存储桶对象名称
* @return String * @return String
*/ */
@SneakyThrows @SneakyThrows
@GetMapping("/file-path") @GetMapping("/file-path")
public R<String> filePath(@RequestParam String fileName) { public R<String> filePath(@RequestParam String fileName) {
return R.data(ossBuilder.template().filePath(fileName)); return R.data(ossBuilder.template().filePath(fileName));
} }
/** /**
* 获取文件外链 * 获取文件外链
* *
* @param fileName 存储桶对象名称 * @param fileName 存储桶对象名称
* @return String * @return String
*/ */
@SneakyThrows @SneakyThrows
@GetMapping("/file-link") @GetMapping("/file-link")
public R<String> fileLink(@RequestParam String fileName) { public R<String> fileLink(@RequestParam String fileName) {
return R.data(ossBuilder.template().fileLink(fileName)); return R.data(ossBuilder.template().fileLink(fileName));
} }
/** /**
* 上传文件 * 上传文件
* *
* @param file 文件 * @param file 文件
* @return ObjectStat * @return ObjectStat
*/ */
@SneakyThrows @SneakyThrows
@PostMapping("/put-file") @PostMapping("/put-file")
public R<BladeFile> putFile(@RequestParam MultipartFile file) { public R<BladeFile> putFile(@RequestParam MultipartFile file) {
BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream()); BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
return R.data(bladeFile); return R.data(bladeFile);
} }
/** /**
* 上传文件 * 上传文件
* *
* @param fileName 存储桶对象名称 * @param fileName 存储桶对象名称
* @param file 文件 * @param file 文件
* @return ObjectStat * @return ObjectStat
*/ */
@SneakyThrows @SneakyThrows
@PostMapping("/put-file-by-name") @PostMapping("/put-file-by-name")
public R<BladeFile> putFile(@RequestParam String fileName, @RequestParam MultipartFile file) { public R<BladeFile> putFile(@RequestParam String fileName, @RequestParam MultipartFile file) {
BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
return R.data(bladeFile); return R.data(bladeFile);
} }
/** /**
* 上传文件并保存至附件表 * 上传文件并保存至附件表
* *
* @param file 文件 * @param file 文件
* @return ObjectStat * @return ObjectStat
*/ */
@SneakyThrows @SneakyThrows
@PostMapping("/put-file-attach") @PostMapping("/put-file-attach")
public R<BladeFile> putFileAttach(@RequestParam MultipartFile file) { public R<BladeFile> putFileAttach(@RequestParam MultipartFile file) {
String fileName = file.getOriginalFilename(); String fileName = file.getOriginalFilename();
BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
Long attachId = buildAttach(fileName, file.getSize(), bladeFile); Long attachId = buildAttach(fileName, file.getSize(), bladeFile);
bladeFile.setAttachId(attachId); bladeFile.setAttachId(attachId);
return R.data(bladeFile); return R.data(bladeFile);
} }
/** /**
* 上传文件并保存至附件表 * 上传文件并保存至附件表
* *
* @param fileName 存储桶对象名称 * @param fileName 存储桶对象名称
* @param file 文件 * @param file 文件
* @return ObjectStat * @return ObjectStat
*/ */
@SneakyThrows @SneakyThrows
@PostMapping("/put-file-attach-by-name") @PostMapping("/put-file-attach-by-name")
public R<BladeFile> putFileAttach(@RequestParam String fileName, @RequestParam MultipartFile file) { public R<BladeFile> putFileAttach(@RequestParam String fileName, @RequestParam MultipartFile file) {
BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
Long attachId = buildAttach(fileName, file.getSize(), bladeFile); Long attachId = buildAttach(fileName, file.getSize(), bladeFile);
bladeFile.setAttachId(attachId); bladeFile.setAttachId(attachId);
return R.data(bladeFile); return R.data(bladeFile);
} }
/** /**
* 构建附件表 * 构建附件表
* *
* @param fileName 文件名 * @param fileName 文件名
* @param fileSize 文件大小 * @param fileSize 文件大小
* @param bladeFile 对象存储文件 * @param bladeFile 对象存储文件
* @return attachId * @return attachId
*/ */
private Long buildAttach(String fileName, Long fileSize, BladeFile bladeFile) { private Long buildAttach(String fileName, Long fileSize, BladeFile bladeFile) {
String fileExtension = FileUtil.getFileExtension(fileName); String fileExtension = FileUtil.getFileExtension(fileName);
Attach attach = new Attach(); Attach attach = new Attach();
attach.setDomainUrl(bladeFile.getDomain()); attach.setDomainUrl(bladeFile.getDomain());
attach.setLink(bladeFile.getLink()); attach.setLink(bladeFile.getLink());
attach.setName(bladeFile.getName()); attach.setName(bladeFile.getName());
attach.setOriginalName(bladeFile.getOriginalName()); attach.setOriginalName(bladeFile.getOriginalName());
attach.setAttachSize(fileSize); attach.setAttachSize(fileSize);
attach.setExtension(fileExtension); attach.setExtension(fileExtension);
attachService.save(attach); attachService.save(attach);
return attach.getId(); return attach.getId();
} }
/** /**
* 删除文件 * 删除文件
* *
* @param fileName 存储桶对象名称 * @param fileName 存储桶对象名称
* @return R * @return R
*/ */
@SneakyThrows @SneakyThrows
@IsAdmin @IsAdmin
@PostMapping("/remove-file") @PostMapping("/remove-file")
public R removeFile(@RequestParam String fileName) { public R removeFile(@RequestParam String fileName) {
ossBuilder.template().removeFile(fileName); ossBuilder.template().removeFile(fileName);
return R.success("操作成功"); return R.success("操作成功");
} }
/** /**
* 批量删除文件 * 批量删除文件
* *
* @param fileNames 存储桶对象名称集合 * @param fileNames 存储桶对象名称集合
* @return R * @return R
*/ */
@SneakyThrows @SneakyThrows
@IsAdmin @IsAdmin
@PostMapping("/remove-files") @PostMapping("/remove-files")
public R removeFiles(@RequestParam String fileNames) { public R removeFiles(@RequestParam String fileNames) {
ossBuilder.template().removeFiles(Func.toStrList(fileNames)); ossBuilder.template().removeFiles(Func.toStrList(fileNames));
return R.success("操作成功"); return R.success("操作成功");
} }
} }

Loading…
Cancel
Save