| | |
| | | package com.vci.ubcs.resource.endpoint; |
| | | |
| | | import com.vci.ubcs.resource.entity.Attach; |
| | | import com.vci.ubcs.common.validator.ComprehensiveFileValidator; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | |
| | | import org.springblade.core.tool.utils.Func; |
| | | import com.vci.ubcs.resource.builder.oss.OssBuilder; |
| | | import com.vci.ubcs.resource.service.IAttachService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * 对象存储端点 |
| | | * |
| | | * 这个类不使用,统一用fileController |
| | | * |
| | | * @author Chill |
| | | */ |
| | |
| | | @AllArgsConstructor |
| | | @RequestMapping("/oss/endpoint") |
| | | @Api(value = "对象存储端点", tags = "对象存储端点") |
| | | @Deprecated |
| | | public class OssEndpoint { |
| | | |
| | | /** |
| | |
| | | * 附件表服务 |
| | | */ |
| | | private final IAttachService attachService; |
| | | |
| | | /** |
| | | * 文件安全检查 |
| | | */ |
| | | @Autowired |
| | | private ComprehensiveFileValidator fileValidator; |
| | | |
| | | /** |
| | | * 创建存储桶 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 创建存储桶 |
| | | * 删除存储桶 |
| | | * |
| | | * @param bucketName 存储桶名称 |
| | | * @return R |
| | |
| | | return R.data(ossBuilder.template().statFile(fileName)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取文件相对路径 |
| | | * |
| | |
| | | @SneakyThrows |
| | | @PostMapping("/put-file") |
| | | public R<BladeFile> putFile(@RequestParam MultipartFile file) { |
| | | // 使用文件安全验证器 |
| | | ComprehensiveFileValidator.UploadValidationResult result = fileValidator.validateFile(file); |
| | | if (!result.isValid()) { |
| | | return R.fail(result.getMessage()); |
| | | } |
| | | BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream()); |
| | | return R.data(bladeFile); |
| | | } |
| | |
| | | @SneakyThrows |
| | | @PostMapping("/put-file-by-name") |
| | | public R<BladeFile> putFile(@RequestParam String fileName, @RequestParam MultipartFile file) { |
| | | // 使用文件安全验证器 |
| | | ComprehensiveFileValidator.UploadValidationResult result = fileValidator.validateFile(file); |
| | | if (!result.isValid()) { |
| | | return R.fail(result.getMessage()); |
| | | } |
| | | BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); |
| | | return R.data(bladeFile); |
| | | } |
| | | |
| | | /** |
| | | * 上传文件并保存至附件表 |
| | | * |
| | | * @param file 文件 |
| | | * @return ObjectStat |
| | | */ |
| | | @SneakyThrows |
| | | @PostMapping("/put-file-attach") |
| | | public R<BladeFile> putFileAttach(@RequestParam MultipartFile file) { |
| | | String fileName = file.getOriginalFilename(); |
| | | BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); |
| | | Long attachId = buildAttach(fileName, file.getSize(), bladeFile); |
| | | bladeFile.setAttachId(attachId); |
| | | return R.data(bladeFile); |
| | | } |
| | | |
| | | /** |
| | | * 上传文件并保存至附件表 |
| | | * |
| | | * @param fileName 存储桶对象名称 |
| | | * @param file 文件 |
| | | * @return ObjectStat |
| | | */ |
| | | @SneakyThrows |
| | | @PostMapping("/put-file-attach-by-name") |
| | | public R<BladeFile> putFileAttach(@RequestParam String fileName, @RequestParam MultipartFile file) { |
| | | BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream()); |
| | | Long attachId = buildAttach(fileName, file.getSize(), bladeFile); |
| | | bladeFile.setAttachId(attachId); |
| | | return R.data(bladeFile); |
| | | } |
| | | |