Merge remote-tracking branch 'refs/remotes/origin/dev'
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
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.google.common.base.Preconditions;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssAliDTOConverter;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssAliDTO;
|
||||
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||
import com.schisandra.oss.application.oss.core.ali.AliOssClient;
|
||||
@@ -11,23 +13,30 @@ import com.schisandra.oss.application.oss.core.ali.AliOssConfiguration;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
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.SchisandraOssAliDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
/**
|
||||
@@ -50,37 +59,6 @@ public class SchisandraOssAliController {
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* @description: 预览文件
|
||||
* @param: [userId, bucket, filePath]
|
||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||
* @date: 2024/6/27 10:14
|
||||
*/
|
||||
@PostMapping("previewFile")
|
||||
public Result<String> previewMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String filePath) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String formattedDate = dateFormat.format(date);
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX, "previewFile", formattedDate, userId, filePath);
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
String url = bean.getAliPreviewUrl(filePath);
|
||||
map.put("url", url);
|
||||
map.put("time", formattedDate);
|
||||
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
|
||||
return Result.ok(url);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回ali表所有数据
|
||||
*
|
||||
@@ -280,10 +258,7 @@ public class SchisandraOssAliController {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(fileName, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
|
||||
//设置热力图
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
@@ -296,7 +271,10 @@ public class SchisandraOssAliController {
|
||||
} else {
|
||||
redisUtil.set(key, String.valueOf(1));
|
||||
}
|
||||
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
if(bean.upLoad(is, fileName, true) != null){
|
||||
return Result.ok(bean.upLoad(is, fileName, true));
|
||||
}else{
|
||||
@@ -306,6 +284,7 @@ public class SchisandraOssAliController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @description: 下载文件
|
||||
* @param: [schisandraOssAliDTO]
|
||||
@@ -313,18 +292,43 @@ public class SchisandraOssAliController {
|
||||
* @date: 2024/6/26 13:56
|
||||
*/
|
||||
@GetMapping("downloadFile")
|
||||
public Result getAliFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath, HttpServletResponse response) throws Exception {
|
||||
public void getAliFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam List<String> filePath, HttpServletResponse response) throws Exception {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
ServletOutputStream output = response.getOutputStream();
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filePath.substring(filePath.lastIndexOf("/") + 1), "UTF-8"));
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("下载.zip", "UTF-8"));
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
bean.downLoad(output, filePath);
|
||||
return Result.ok();
|
||||
HashMap<String,InputStream> list=bean.downLoadMany(filePath);
|
||||
String[] path = new String[list.size()];
|
||||
InputStream[] inputStreams = new InputStream[list.size()];
|
||||
path = list.keySet().toArray(path);
|
||||
inputStreams = list.values().toArray(inputStreams);
|
||||
//记录用户下载
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String formattedDate = dateFormat.format(date);
|
||||
AtomicInteger count = new AtomicInteger(0);
|
||||
InputStream[] inputStream2 = new InputStream[list.size()];
|
||||
list.keySet().forEach( name -> {
|
||||
try {
|
||||
byte[] bytes = StreamUtils.copyToByteArray(list.get(name));
|
||||
inputStream2[count.get()] = new ByteArrayInputStream(bytes);
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX, "download", formattedDate, userId, name);
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
map.put("size", bytes.length);
|
||||
map.put("time",formattedDate);
|
||||
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
|
||||
count.incrementAndGet();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
});
|
||||
ZipUtil.zip(output, path, inputStream2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -9,6 +9,7 @@ import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
|
||||
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.domain.bo.SchisandraOssMinioBO;
|
||||
import com.schisandra.oss.domain.redis.RedisUtil;
|
||||
@@ -16,6 +17,7 @@ import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
|
||||
import io.minio.errors.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.util.StreamUtils;
|
||||
@@ -25,12 +27,15 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
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;
|
||||
@@ -128,9 +133,9 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/26 13:55
|
||||
*/
|
||||
@Cacheable(value = "MinioListDir", key = "#userId+#bucket+#dirName")
|
||||
@Cacheable(value = "MinioListDir", key = "#userId+#bucket+#dirName",unless = "#result == null")
|
||||
@GetMapping("listDir")
|
||||
public Result<String> listMinioInfo(@RequestParam String userId, @RequestParam String dirName, @RequestParam String bucket) throws Exception {
|
||||
public Result listMinioInfo(@RequestParam String userId, @RequestParam String dirName, @RequestParam String bucket) throws Exception {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
@@ -152,16 +157,14 @@ public class SchisandraOssMinioController {
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
HashMap<String, InputStream> list = bean.getTargetDir(listObjectsArgs);
|
||||
|
||||
ServletOutputStream output = response.getOutputStream();
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("下载.zip", "UTF-8"));
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
ServletOutputStream output = response.getOutputStream();
|
||||
String[] path = new String[list.size()];
|
||||
InputStream[] inputStreams = new InputStream[list.size()];
|
||||
path = list.keySet().toArray(path);
|
||||
inputStreams = list.values().toArray(inputStreams);
|
||||
|
||||
//记录用户下载
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
@@ -169,6 +172,7 @@ public class SchisandraOssMinioController {
|
||||
list.keySet().forEach(name -> {
|
||||
try {
|
||||
byte[] bytes = StreamUtils.copyToByteArray(list.get(name));
|
||||
list.get(name).reset();
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX, "download", formattedDate, userId, name);
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
map.put("size", bytes.length);
|
||||
@@ -177,7 +181,6 @@ public class SchisandraOssMinioController {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
});
|
||||
ZipUtil.zip(output, path, inputStreams);
|
||||
}
|
||||
@@ -189,7 +192,7 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/26 14:34
|
||||
*/
|
||||
@CacheEvict(value = "MinioListDir", key = "#userId+#bucket+#dirName")
|
||||
@CacheEvict(value = "MinioListDir", key = "#userId+#bucket+#filePath")
|
||||
@PostMapping("deleteFile")
|
||||
public Result deleteMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
@@ -345,12 +348,20 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/26 17:37
|
||||
*/
|
||||
@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")
|
||||
@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);
|
||||
return Result.ok(bean.getMinioBucketSize(bucket));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 创建bucket
|
||||
@@ -359,6 +370,7 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/26 17:38
|
||||
*/
|
||||
@CacheEvict(value = "minioBucket", key = "#userId")
|
||||
@PostMapping("createBucket")
|
||||
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -375,6 +387,7 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/26 17:38
|
||||
*/
|
||||
@CacheEvict(value = "minioBucket", key = "#userId")
|
||||
@PostMapping("deleteBucket")
|
||||
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
|
@@ -24,6 +24,9 @@ import com.schisandra.oss.domain.redis.RedisUtil;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssTencentDomainService;
|
||||
import io.minio.errors.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -47,16 +50,17 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class SchisandraOssTencentController {
|
||||
|
||||
@Resource
|
||||
private SchisandraOssTencentDomainService schisandraOssTencentDomainService;
|
||||
@Resource
|
||||
TencentOssConfiguration tencentOssConfiguration;
|
||||
private final String USER_OSS_PREFIX = "oss:user:heat";
|
||||
@Resource
|
||||
TencentOssConfiguration tencentOssConfiguration;
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
@Resource
|
||||
private SchisandraOssTencentDomainService schisandraOssTencentDomainService;
|
||||
|
||||
/**
|
||||
* 返回tencent表所有数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("returnAll")
|
||||
@@ -110,12 +114,23 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/29 13:28
|
||||
*/
|
||||
@Cacheable(value = "TencentBucket", key = "#userId")
|
||||
@PostMapping("seleteBucket")
|
||||
public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
return Result.ok(bean.selectAllBucket());
|
||||
}
|
||||
|
||||
@Cacheable(value = "TencentBucket", key = "#userId+#bucket")
|
||||
@PostMapping("getBucketSize")
|
||||
public Result<String> getBucketSize(@RequestParam String userId, @RequestParam String bucket) throws Exception {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
bean.getTencentOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.getTencentBucketSize(bucket));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 查询指定目录
|
||||
* @param: [userId, dirName, bucket]
|
||||
@@ -123,6 +138,7 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/29 13:28
|
||||
*/
|
||||
@Cacheable(value = "TencentBucketDir", key = "#userId+#bucket+#dirName")
|
||||
@GetMapping("listDir")
|
||||
public Result<String> listTencentInfo(@RequestParam String userId, @RequestParam String dirName, @RequestParam String bucket) throws Exception {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
@@ -131,6 +147,7 @@ public class SchisandraOssTencentController {
|
||||
bean.getTencentOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.listTargetDir(bucket, dirName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 创建桶
|
||||
* @param: [userId, bucket, appId]
|
||||
@@ -138,6 +155,7 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/29 13:27
|
||||
*/
|
||||
@CacheEvict(value = "TencentBucket", key = "#userId")
|
||||
@PostMapping("createBucket")
|
||||
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket, @RequestParam String appId) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -146,6 +164,7 @@ public class SchisandraOssTencentController {
|
||||
// bean.getTencentOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.createBuctet(bucket, appId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 删除腾讯云对象存储bucket
|
||||
* @param: [userId, bucket, appId]
|
||||
@@ -153,6 +172,7 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/29 13:27
|
||||
*/
|
||||
@CacheEvict(value = "TencentBucket", key = "#userId")
|
||||
@PostMapping("deleteBucket")
|
||||
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket, @RequestParam String appId) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -165,6 +185,7 @@ public class SchisandraOssTencentController {
|
||||
return Result.fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 分享腾讯云对象存储链接
|
||||
* @param: [userId, bucket, target]
|
||||
@@ -179,6 +200,7 @@ public class SchisandraOssTencentController {
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
return Result.ok(bean.shareTencentObject(bucket, target));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 腾讯云对象存储上传文件
|
||||
* @param: [userId, bucket, target, file]
|
||||
@@ -210,6 +232,7 @@ public class SchisandraOssTencentController {
|
||||
}
|
||||
return Result.ok(bean.upLoadParts(is, target, file.getOriginalFilename()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 腾讯云对象存储下载文件
|
||||
* @param: [userId, bucket, target]
|
||||
@@ -224,6 +247,7 @@ public class SchisandraOssTencentController {
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
return Result.ok(bean.downloadTencent(bucket, target));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 腾讯云对象存储移动文件
|
||||
* @param: [userId, sourceBucket, targetBucket, targetName, SourceName]
|
||||
@@ -231,6 +255,7 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/7/1 16:02
|
||||
*/
|
||||
@Caching(cacheable = @Cacheable(value = "TencentBucketDir", key = "#userId+#targetBucket+#targetName"), evict = @CacheEvict(value = "MinioListDir", key = "#userId+#sourceBucket+#SourceName"))
|
||||
@PostMapping("moveFile")
|
||||
public Result<String> moveTencent(@RequestParam String userId, @RequestParam String sourceBucket, @RequestParam String targetBucket, @RequestParam String targetName, @RequestParam String SourceName) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -241,6 +266,7 @@ public class SchisandraOssTencentController {
|
||||
}
|
||||
return Result.ok(copyResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 腾讯云对象存储复制文件
|
||||
* @param: [userId, sourceBucket, targetBucket, targetName, SourceName]
|
||||
@@ -248,6 +274,7 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/7/1 16:02
|
||||
*/
|
||||
@Cacheable(value = "TencentBucketDir", key = "#userId+#targetBucket+#targetName")
|
||||
@PostMapping("copyFile")
|
||||
public Result<String> copyTencent(@RequestParam String userId, @RequestParam String sourceBucket, @RequestParam String targetBucket, @RequestParam String targetName, @RequestParam String SourceName) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -258,6 +285,7 @@ public class SchisandraOssTencentController {
|
||||
}
|
||||
return Result.ok(copyResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 腾讯云对象存储删除文件
|
||||
* @param: [userId, bucketName, target]
|
||||
@@ -265,6 +293,7 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/7/1 16:02
|
||||
*/
|
||||
@Cacheable()
|
||||
@PostMapping("deleteFile")
|
||||
public Result<String> deleteTencent(@RequestParam String userId, @RequestParam String bucketName, @RequestParam List<DeleteObjectsRequest.KeyVersion> target) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
|
@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||
import cn.hutool.core.lang.hash.Hash;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -13,6 +14,11 @@ import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.common.utils.HttpHeaders;
|
||||
import com.aliyun.oss.model.*;
|
||||
|
||||
import com.jd.platform.async.executor.Async;
|
||||
import com.jd.platform.async.worker.WorkResult;
|
||||
import com.jd.platform.async.wrapper.WorkerWrapper;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.ali.model.AliOssConfig;
|
||||
@@ -22,6 +28,7 @@ import com.schisandra.oss.application.oss.model.FileOssInfo;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||
import io.minio.ListObjectsArgs;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -29,12 +36,16 @@ import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* https://help.aliyun.com/product/31815.html
|
||||
@@ -55,12 +66,6 @@ public class AliOssClient implements StandardOssClient {
|
||||
private OSS oss;
|
||||
private AliOssConfig aliOssConfig;
|
||||
|
||||
|
||||
public String getAliPreviewUrl(String fileName) {
|
||||
URL presignedUrl = oss.generatePresignedUrl(getBucketName(), fileName, new Date());
|
||||
return String.valueOf(presignedUrl);
|
||||
}
|
||||
|
||||
public String getAliBucketSize(String bucket) {
|
||||
ObjectListing objectListing = oss.listObjects(bucket, "");
|
||||
long x = 0L;
|
||||
@@ -176,7 +181,8 @@ public class AliOssClient implements StandardOssClient {
|
||||
try{
|
||||
if (oss.doesBucketExist(bucketName)){
|
||||
VoidResult voidResult = oss.deleteBucket(bucketName);
|
||||
} else {
|
||||
}
|
||||
else{
|
||||
return "bucket does not exist";
|
||||
}
|
||||
}catch(Exception e){
|
||||
@@ -228,9 +234,40 @@ public class AliOssClient implements StandardOssClient {
|
||||
}
|
||||
return getInfo(targetName);
|
||||
}
|
||||
public HashMap<String,InputStream> downLoadMany(List<String> listObjectsArgs) throws ExecutionException, InterruptedException {
|
||||
HashMap<String,InputStream> list = new HashMap<>();
|
||||
List<WorkerWrapper> wrappers=new ArrayList<>();
|
||||
listObjectsArgs.forEach(args -> {
|
||||
String bucketName = getBucketName();
|
||||
String key = getKey(args, false);
|
||||
ObjectListing objectListing=oss .listObjects(bucketName,args);
|
||||
List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
|
||||
sums.forEach(r -> {
|
||||
try {
|
||||
WorkerWrapper wrapper1 = new WorkerWrapper.Builder<String, InputStream>().worker((String dirName, Map<String, WorkerWrapper> allWrappers) -> {
|
||||
try {
|
||||
list.put(dirName,oss.getObject(bucketName, r.getKey()).getObjectContent());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}).param(r.getKey().toString()).id(r.getETag()).callback((boolean success, String param, WorkResult<InputStream> re)->{
|
||||
}).build();
|
||||
wrappers.add(wrapper1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Async.beginWork(3500L,new ThreadPoolExecutor(10, 100, 5L,
|
||||
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()), wrappers);
|
||||
return list;
|
||||
|
||||
}
|
||||
@Override
|
||||
public void downLoad(OutputStream os, String targetName) {
|
||||
|
||||
String bucketName = getBucketName();
|
||||
String key = getKey(targetName, false);
|
||||
OSSObject ossObject = oss.getObject(bucketName, key);
|
||||
|
Reference in New Issue
Block a user