|
|
|
@@ -3,22 +3,15 @@ package com.schisandra.oss.application.controller;
|
|
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.github.benmanes.caffeine.cache.Cache;
|
|
|
|
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.mybatisflex.annotation.RelationOneToMany;
|
|
|
|
|
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter;
|
|
|
|
|
import com.schisandra.oss.application.convert.SchisandraOssQiniuDTOConverter;
|
|
|
|
|
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
|
|
|
|
|
import com.schisandra.oss.application.dto.SchisandraOssQiniuDTO;
|
|
|
|
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
|
|
|
|
import com.schisandra.oss.application.oss.core.minio.MinioOssClient;
|
|
|
|
|
import com.schisandra.oss.application.oss.core.minio.MinioOssConfiguration;
|
|
|
|
|
import com.schisandra.oss.application.oss.model.OssInfo;
|
|
|
|
|
import com.schisandra.oss.common.entity.Result;
|
|
|
|
|
import com.schisandra.oss.common.utils.CaffeineUtil;
|
|
|
|
|
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
|
|
|
|
|
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
|
|
|
|
|
import com.schisandra.oss.domain.redis.RedisUtil;
|
|
|
|
|
import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
|
|
|
|
@@ -42,7 +35,6 @@ import java.net.URLEncoder;
|
|
|
|
|
import java.security.InvalidKeyException;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
@@ -81,23 +73,23 @@ public class SchisandraOssMinioController {
|
|
|
|
|
public Result returnOneById(String Id) {
|
|
|
|
|
SchisandraOssMinioBO bo = schisandraOssMinioDomainService.selectOneById(Id);
|
|
|
|
|
SchisandraOssMinioDTO dto = SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(bo);
|
|
|
|
|
if(dto == null){
|
|
|
|
|
if (dto == null) {
|
|
|
|
|
return Result.fail("查询失败");
|
|
|
|
|
}
|
|
|
|
|
return Result.ok(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回当前用户minio表所有数据
|
|
|
|
|
*
|
|
|
|
|
* @param userId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("return_online")
|
|
|
|
|
public Result returnOnline(String userId) {
|
|
|
|
|
List<SchisandraOssMinioBO> list = schisandraOssMinioDomainService.selectAllPresent(userId);
|
|
|
|
|
if(list.isEmpty()){
|
|
|
|
|
if (list.isEmpty()) {
|
|
|
|
|
return Result.fail();
|
|
|
|
|
}
|
|
|
|
|
return Result.ok(SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTOList(list));
|
|
|
|
@@ -178,12 +170,12 @@ public class SchisandraOssMinioController {
|
|
|
|
|
Preconditions.checkNotNull(userId, "不能为空");
|
|
|
|
|
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
|
|
|
|
bean.getMinioOssConfig().setBucketName(bucket);
|
|
|
|
|
List<OssInfo> object= (List<OssInfo>) caffeineUtil.caffeineBuild().getIfPresent(userId+bucket+dirName);
|
|
|
|
|
List<OssInfo> object = (List<OssInfo>) caffeineUtil.caffeineBuild().getIfPresent(userId + bucket + dirName);
|
|
|
|
|
if (object != null) {
|
|
|
|
|
return Result.ok(object);
|
|
|
|
|
}else {
|
|
|
|
|
List<OssInfo> list=bean.listDir(bucket,dirName);
|
|
|
|
|
caffeineUtil.caffeineBuild().put(userId+bucket+dirName, list);
|
|
|
|
|
} else {
|
|
|
|
|
List<OssInfo> list = bean.listDir(bucket, dirName);
|
|
|
|
|
caffeineUtil.caffeineBuild().put(userId + bucket + dirName, list);
|
|
|
|
|
return Result.ok(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -240,13 +232,13 @@ public class SchisandraOssMinioController {
|
|
|
|
|
* @author zlg
|
|
|
|
|
* @date: 2024/6/26 14:34
|
|
|
|
|
*/
|
|
|
|
|
@CacheEvict(value = "MinioListDir", key = "#userId+#bucket+#filePath.substring(filePath.lastIndexOf('/'))" )
|
|
|
|
|
@CacheEvict(value = "MinioListDir", key = "#userId+#bucket+#filePath.substring(filePath.lastIndexOf('/'))")
|
|
|
|
|
@PostMapping("deleteFile")
|
|
|
|
|
public Result deleteMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
|
|
|
|
Preconditions.checkNotNull(bucket, "不能为空");
|
|
|
|
|
Preconditions.checkNotNull(userId, "不能为空");
|
|
|
|
|
Preconditions.checkNotNull(filePath, "不能为空");
|
|
|
|
|
int index=filePath.lastIndexOf("/");
|
|
|
|
|
int index = filePath.lastIndexOf("/");
|
|
|
|
|
String fileName = filePath.substring(index + 1);
|
|
|
|
|
caffeineUtil.caffeineBuild().invalidate("MinioListDir" + userId + bucket + fileName);
|
|
|
|
|
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
|
|
|
@@ -263,19 +255,18 @@ public class SchisandraOssMinioController {
|
|
|
|
|
* @date: 2024/6/26 14:34
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping(value = "uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
|
|
public Result<Object> uploadMinioFile(SchisandraOssMinioDTO schisandraOssMinioDTO) throws IOException {
|
|
|
|
|
String path=schisandraOssMinioDTO.getPath();
|
|
|
|
|
MultipartFile file=schisandraOssMinioDTO.getMultipartFile();
|
|
|
|
|
String bucket=schisandraOssMinioDTO.getBucketName();
|
|
|
|
|
String userId=schisandraOssMinioDTO.getUserId();
|
|
|
|
|
public Result<Object> uploadMinioFile(@RequestPart("file") MultipartFile file,SchisandraOssMinioDTO schisandraOssMinioDTO) throws IOException {
|
|
|
|
|
String path = schisandraOssMinioDTO.getPath();
|
|
|
|
|
String bucket = schisandraOssMinioDTO.getBucketName();
|
|
|
|
|
String userId = schisandraOssMinioDTO.getUserId();
|
|
|
|
|
Preconditions.checkNotNull(path, "path不能为空");
|
|
|
|
|
Preconditions.checkNotNull(file, "file不能为空");
|
|
|
|
|
Preconditions.checkNotNull(bucket, "bucket不能为空");
|
|
|
|
|
Preconditions.checkNotNull(userId, "userId不能为空");
|
|
|
|
|
if (path.lastIndexOf("") == path.length() - 1) {
|
|
|
|
|
path=path+file.getName();
|
|
|
|
|
}else{
|
|
|
|
|
path=path+"/"+file.getOriginalFilename();
|
|
|
|
|
path = path + file.getName();
|
|
|
|
|
} else {
|
|
|
|
|
path = path + "/" + file.getOriginalFilename();
|
|
|
|
|
}
|
|
|
|
|
// 获取文件输入流
|
|
|
|
|
InputStream is = file.getInputStream();
|
|
|
|
@@ -410,18 +401,19 @@ public class SchisandraOssMinioController {
|
|
|
|
|
* @author zlg
|
|
|
|
|
* @date: 2024/6/26 17:37
|
|
|
|
|
*/
|
|
|
|
|
@Cacheable(value = "minioBucket", key = "#userId",unless = "#result==null")
|
|
|
|
|
@Cacheable(value = "minioBucket", key = "#userId", unless = "#result==null")
|
|
|
|
|
@PostMapping("seleteBucket")
|
|
|
|
|
public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
|
|
|
|
Preconditions.checkNotNull(userId, "不能为空");
|
|
|
|
|
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
|
|
|
|
return Result.ok(bean.selectAllBucket());
|
|
|
|
|
}
|
|
|
|
|
@Cacheable(value = "minioBucket", key = "#userId+#bucket",unless = "#result==null")
|
|
|
|
|
|
|
|
|
|
@Cacheable(value = "minioBucket", key = "#userId+#bucket", unless = "#result==null")
|
|
|
|
|
@PostMapping("getBucketSize")
|
|
|
|
|
public Result<String> getBucketSize(@RequestParam String userId, @RequestParam String bucket) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
|
|
|
|
Preconditions.checkNotNull(userId, "不能为空");
|
|
|
|
|
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
|
|
|
|
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
|
|
|
|
return Result.ok(bean.getMinioBucketSize(bucket));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|