feat:七牛相关内容
This commit is contained in:
@@ -91,5 +91,12 @@
|
||||
<artifactId>schisandra-cloud-storage-asyncTool</artifactId>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>7.13.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -1,18 +1,21 @@
|
||||
package com.schisandra.oss.application.controller;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssFtpDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssFtpDTO;
|
||||
import com.schisandra.oss.application.oss.core.ftp.FtpOssClient;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssFtpBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssFtpDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* ftp存储配置表 controller
|
||||
@@ -157,4 +160,21 @@ public class SchisandraOssFtpController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 上传文件
|
||||
* @param: [schisandraOssFTPDTO]
|
||||
* @return: void
|
||||
* @date: 2024/6/26 14:34
|
||||
*/
|
||||
@PostMapping("uploadFtpFile")
|
||||
public Result<OssInfo> uploadAliFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(fileName, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
FtpOssClient bean = SpringUtil.getBean(userId);
|
||||
return Result.ok(bean.upLoad(is, fileName, true));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,18 +1,25 @@
|
||||
package com.schisandra.oss.application.controller;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssQiniuDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssQiniuDTO;
|
||||
import com.schisandra.oss.application.oss.core.qiniu.QiNiuOssClient;
|
||||
import com.schisandra.oss.application.oss.core.qiniu.QiNiuOssConfiguration;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssQiniuDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
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.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
/**
|
||||
* 七牛云对象存储配置表 controller
|
||||
@@ -27,6 +34,201 @@ public class SchisandraOssQiniuController {
|
||||
|
||||
@Resource
|
||||
private SchisandraOssQiniuDomainService schisandraOssQiniuDomainService;
|
||||
@Resource
|
||||
private QiNiuOssConfiguration qiNiuOssConfiguration;
|
||||
|
||||
/**
|
||||
* @description: 获取文件目录信息
|
||||
* @param: [target, userId, dirName]
|
||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||
* @date: 2024/6/26 13:55
|
||||
*/
|
||||
@GetMapping("listQiniuDir")
|
||||
public Result<String> listQiniuInfo(@RequestParam String userId, @RequestParam String prefix, @RequestParam String bucket) throws Exception {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.listfile(bucket, prefix));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 重命名文件
|
||||
* @param: [userId, bucket, oldFileName, newFileName]
|
||||
* @return: com.schisandra.oss.common.entity.Result
|
||||
* @author zlg
|
||||
* @date: 2024/6/27 9:41
|
||||
*/
|
||||
@PostMapping("renameQiniuFile")
|
||||
public Result renameQiniuFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFileName, @RequestParam String newFileName) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(oldFileName, "不能为空");
|
||||
Preconditions.checkNotNull(newFileName, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
bean.rename(oldFileName, newFileName);
|
||||
}catch (Exception e){
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 拷贝文件
|
||||
* @param: [userId, bucket, oldFilePath, newFilePath]
|
||||
* @return: com.schisandra.oss.common.entity.Result
|
||||
* @author zlg
|
||||
* @date: 2024/6/27 9:52
|
||||
*/
|
||||
@PostMapping("copyQiniuFile")
|
||||
public Result copyQiniuFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFilePath, @RequestParam String newFilePath) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(oldFilePath, "不能为空");
|
||||
Preconditions.checkNotNull(newFilePath, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
bean.copy(oldFilePath, newFilePath);
|
||||
}catch (Exception e){
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 下载文件
|
||||
* @param: [schisandraOssMinioDTO]
|
||||
* @return: void
|
||||
* @author sjm
|
||||
* @date: 2024/7/8 13:56
|
||||
*/
|
||||
@GetMapping("downloadQiniuFile")
|
||||
public void download_open(@RequestParam String userId,@RequestParam String endpoint, @RequestParam String filename,HttpServletResponse response) throws IOException {
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.getQiNiuOssConfig().setEndpoint(endpoint);
|
||||
ServletOutputStream output = response.getOutputStream();
|
||||
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(filename, "utf-8"));
|
||||
bean.downLoad_open(output,filename,endpoint);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 删除文件
|
||||
* @param: [schisandraOssMinioDTO]
|
||||
* @return: void
|
||||
* @date: 2024/7/8 14:34
|
||||
*/
|
||||
@PostMapping("deleteQiniuFile")
|
||||
public Result deleteQiniuFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
bean.delete(filePath);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 上传文件
|
||||
* @param: [schisandraOssMinioDTO]
|
||||
* @return: void
|
||||
* @date: 2024/7/8 14:34
|
||||
*/
|
||||
@PostMapping("uploadQiniuFile")
|
||||
public Result<OssInfo> uploadQiniuFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(fileName, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.upLoad(is, fileName, true));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 获取所有bucket
|
||||
* @param: [userId, bucket]
|
||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||
* @date: 2024/7/8 17:37
|
||||
*/
|
||||
@GetMapping("seleteBucket")
|
||||
public Result<String> seleteBucket(@RequestParam String userId) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
return Result.ok(bean.selectAllBucket());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 删除bucket
|
||||
* @param: [userId, bucket]
|
||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||
* @date: 2024/7/8 17:38
|
||||
*/
|
||||
@PostMapping("deleteBucket")
|
||||
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.deleteBucket(bucket));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建桶createbucket
|
||||
* @param userId
|
||||
* @param bucket
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("createBucket")
|
||||
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket,@RequestParam String region) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
bean.getQiNiuOssConfig().setRegion(region);
|
||||
try {
|
||||
return Result.ok(bean.createBucket(bucket,region));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: qiniu 初始化
|
||||
* @param: []
|
||||
* @return: void
|
||||
* @date: 2024/7/8 13:34
|
||||
*/
|
||||
@PostMapping("init")
|
||||
public void initQiniu(@RequestParam String userId) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SchisandraOssMinioController.init.userId:{}", userId);
|
||||
}
|
||||
Preconditions.checkNotNull(userId, "用户id不能为空!");
|
||||
|
||||
Result result = qiNiuOssConfiguration.qiNiuOssClient(userId);
|
||||
if (result != null) {
|
||||
log.info("用户: {}-> qiniu 初始化完成!", userId);
|
||||
} else {
|
||||
log.error("用户: {}-> qiniu 初始化失败!", userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 新增七牛云对象存储配置表
|
||||
|
@@ -169,5 +169,7 @@ public class SchisandraOssQiniuDTO implements Serializable {
|
||||
*/
|
||||
private String checkBucket;
|
||||
|
||||
private String endpoint;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -4,16 +4,14 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.DownloadUrl;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.*;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import com.qiniu.storage.model.FileListing;
|
||||
import com.qiniu.storage.persistent.FileRecorder;
|
||||
@@ -34,21 +32,21 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import static com.aliyuncs.utils.Base64Helper.encode;
|
||||
|
||||
/**
|
||||
* @author zlg
|
||||
* @description: qiniu oss client
|
||||
* @param:
|
||||
* @return:
|
||||
* @author zlg
|
||||
* @date: 2024/6/25 14:00
|
||||
*/
|
||||
@Slf4j
|
||||
@@ -62,11 +60,165 @@ public class QiNiuOssClient implements StandardOssClient {
|
||||
public static final String BUCKET_OBJECT_NAME = "bucketManager";
|
||||
|
||||
private Auth auth;
|
||||
|
||||
private UploadManager uploadManager;
|
||||
private BucketManager bucketManager;
|
||||
private QiNiuOssConfig qiNiuOssConfig;
|
||||
private Configuration configuration;
|
||||
|
||||
/*
|
||||
* 将时间转换为时间戳
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static long dateToStamp(String s) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = simpleDateFormat.parse(s);
|
||||
long ts = date.getTime();
|
||||
return ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 获取目录文件信息
|
||||
* @param: [bucket, prefix] delimiter 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串
|
||||
* @return: java.util.List<com.schisandra.oss.application.oss.model.OssInfo>
|
||||
* @date: 2024/6/26 13:34
|
||||
*/
|
||||
public List<OssInfo> listfile(String bucket, String prefix) {
|
||||
String delimiter = "";
|
||||
|
||||
|
||||
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, prefix, 1000, delimiter);
|
||||
List<OssInfo> infos = new ArrayList<>();
|
||||
while (fileListIterator.hasNext()){
|
||||
FileInfo[] items = fileListIterator.next();
|
||||
for (FileInfo item : items) {
|
||||
OssInfo info = new OssInfo();
|
||||
info.setPath(item.key);
|
||||
info.setLength(DataSizeUtil.format(item.fsize));
|
||||
|
||||
String[] split_path = item.key.split("/");
|
||||
String[] split_path1 = split_path[split_path.length-1].split("\\.");
|
||||
if(split_path.length >= 2 && split_path1.length >= 2){
|
||||
info.setIsDir(false);
|
||||
info.setName(split_path[split_path.length-1]);
|
||||
}else if(split_path.length >= 2){
|
||||
info.setIsDir(true);
|
||||
info.setName(split_path[split_path.length-1]);
|
||||
}else if(split_path.length < 2 && split_path1.length < 2){
|
||||
info.setIsDir(true);
|
||||
info.setName(item.key);
|
||||
}else{
|
||||
info.setIsDir(false);
|
||||
info.setName(item.key);
|
||||
}
|
||||
|
||||
info.setCreateTime(String.valueOf(item.putTime));
|
||||
System.out.println(item.key);
|
||||
infos.add(info);
|
||||
}
|
||||
}
|
||||
return infos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 七牛图片下载
|
||||
*
|
||||
* @param os targetName endpoint
|
||||
* @param endpoint
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
public void downLoad_open(OutputStream os, String targetName,String endpoint) {
|
||||
String filename = URLEncoder.encode(targetName,"UTF-8").replace("+", "%20");
|
||||
DownloadUrl downloadUrl = new DownloadUrl(endpoint, false, getKey(filename, false));
|
||||
try {
|
||||
String url = downloadUrl.buildURL();
|
||||
HttpUtil.download(url, os, false);
|
||||
} catch (QiniuException e) {
|
||||
String errorMsg = String.format("%s下载失败", targetName);
|
||||
log.error(errorMsg, e);
|
||||
throw new OssException(errorMsg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public String[] selectAllBucket() {
|
||||
String[] buckets = bucketManager.buckets();
|
||||
|
||||
return buckets;
|
||||
}
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public Integer deleteBucket(String bucketName) {
|
||||
|
||||
String path = "/drop/" + bucketName + "\n";
|
||||
String access_token = auth.sign(path);
|
||||
|
||||
|
||||
String url = "http://rs.qiniu.com/drop/" + bucketName;
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder().url(url).addHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
.addHeader("Authorization", "QBox " + access_token)
|
||||
.addHeader("Host", "uc.qiniuapi.com")
|
||||
.addHeader("X-Qiniu-Date", "20060102T150405Z").build();
|
||||
okhttp3.Response re = null;
|
||||
re = client.newCall(request).execute();
|
||||
if (re.isSuccessful() == true) {
|
||||
|
||||
System.out.println(re.code());
|
||||
System.out.println(re.toString());
|
||||
return re.code();
|
||||
} else {
|
||||
System.out.println(re.code());
|
||||
System.out.println(re.toString());
|
||||
return re.code();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* OSSClient
|
||||
* 创建桶
|
||||
*
|
||||
* @param bucketName
|
||||
* @return
|
||||
*/
|
||||
public Integer createBucket(String bucketName, String region) throws IOException {
|
||||
//mkbucketv2 此处不按照管网上的 管网上的会报401
|
||||
String path = "/mkbucketv2/" + encode(bucketName.getBytes()) + "/region/" + region + "\n";
|
||||
String access_token = auth.sign(path);
|
||||
|
||||
|
||||
String url = "http://rs.qiniu.com/mkbucketv2/" + encode(bucketName.getBytes()) + "/region/" + region;
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder().url(url).addHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
// Authorization 不以管网的 使用QBox +access_token 可以实现
|
||||
.addHeader("Authorization", "QBox " + access_token)
|
||||
.addHeader("Host", "uc.qiniuapi.com")
|
||||
.addHeader("X-Qiniu-Date", "20060102T150405Z").build();
|
||||
okhttp3.Response re = null;
|
||||
try {
|
||||
re = client.newCall(request).execute();
|
||||
if (re.isSuccessful() == true) {
|
||||
|
||||
System.out.println(re.code());
|
||||
System.out.println(re.toString());
|
||||
return re.code();
|
||||
} else {
|
||||
System.out.println(re.code());
|
||||
System.out.println(re.toString());
|
||||
return re.code();
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||
try {
|
||||
@@ -96,9 +248,10 @@ public class QiNiuOssClient implements StandardOssClient {
|
||||
return getInfo(targetName);
|
||||
}
|
||||
|
||||
//已废除
|
||||
@Override
|
||||
public void downLoad(OutputStream os, String targetName) {
|
||||
DownloadUrl downloadUrl = new DownloadUrl("qiniu.com", false, getKey(targetName, false));
|
||||
DownloadUrl downloadUrl = new DownloadUrl("", false, getKey(targetName, false));
|
||||
try {
|
||||
String url = downloadUrl.buildURL();
|
||||
HttpUtil.download(url, os, false);
|
||||
@@ -167,6 +320,8 @@ public class QiNiuOssClient implements StandardOssClient {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void delete(String targetName) {
|
||||
try {
|
||||
|
@@ -2,6 +2,7 @@ package com.schisandra.oss.application.oss.core.qiniu;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
@@ -12,14 +13,15 @@ import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.qiniu.model.QiNiuOssClientConfig;
|
||||
import com.schisandra.oss.application.oss.core.qiniu.model.QiNiuOssConfig;
|
||||
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssQiniuDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* @description: qiniu oss 配置类
|
||||
@@ -32,25 +34,46 @@ import java.util.Optional;
|
||||
@Slf4j
|
||||
public class QiNiuOssConfiguration {
|
||||
|
||||
@Resource
|
||||
QiNiuOssConfiguration qiniuOssConfiguration;
|
||||
|
||||
@Resource
|
||||
private SchisandraOssQiniuDomainService schisandraOssQiniuDomainService;
|
||||
|
||||
|
||||
public StandardOssClient qiNiuOssClient(String userId) {
|
||||
SchisandraOssQiniuBO schisandraOssQiniuBO = schisandraOssQiniuDomainService.getQiniuOssConfig(userId);
|
||||
SchisandraOssQiniuDTO schisandraOssQiniuDTO = SchisandraOssQiniuDTOConverter.INSTANCE.convertBOToDTO(schisandraOssQiniuBO);
|
||||
if (ObjectUtil.isEmpty(schisandraOssQiniuDTO)) {
|
||||
log.error("jd oss配置信息获取失败");
|
||||
public SchisandraOssQiniuDTO getSchisandraOssQiNDTO(String userId) {
|
||||
CompletableFuture<SchisandraOssQiniuDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
|
||||
SchisandraOssQiniuBO qiniuBO = schisandraOssQiniuDomainService.getQiniuOssConfig(userId);
|
||||
SchisandraOssQiniuDTO qiniuDTO = SchisandraOssQiniuDTOConverter.INSTANCE.convertBOToDTO(qiniuBO);
|
||||
return qiniuDTO;
|
||||
});
|
||||
SchisandraOssQiniuDTO qiniu = futurePrice.join();
|
||||
if (ObjectUtil.isEmpty(qiniu)) {
|
||||
log.error("qiniu配置信息获取失败");
|
||||
return null;
|
||||
}
|
||||
String accessKey = schisandraOssQiniuDTO.getAccessKey();
|
||||
String secretKey = schisandraOssQiniuDTO.getSecretKey();
|
||||
QiNiuOssConfig qiNiuOssConfig = new QiNiuOssConfig();
|
||||
qiNiuOssConfig.setAccessKey(accessKey);
|
||||
qiNiuOssConfig.setSecretKey(secretKey);
|
||||
return qiNiuOssClient(qiNiuOssConfig);
|
||||
return qiniu;
|
||||
}
|
||||
|
||||
public Result qiNiuOssClient(String userId) {
|
||||
try {
|
||||
SchisandraOssQiniuDTO qiniu = qiniuOssConfiguration.getSchisandraOssQiNDTO(userId);
|
||||
if (qiniu == null) return null;
|
||||
QiNiuOssConfig qiniuOssConfig = new QiNiuOssConfig();
|
||||
qiniuOssConfig.setBasePath(qiniu.getBasePath());
|
||||
qiniuOssConfig.setBucketName(qiniu.getBucketName());
|
||||
qiniuOssConfig.setAccessKey(qiniu.getAccessKey());
|
||||
qiniuOssConfig.setSecretKey(qiniu.getSecretKey());
|
||||
qiniuOssConfig.setRegion(qiniu.getRegion());
|
||||
qiniuOssConfig.setEndpoint(qiniu.getEndpoint());
|
||||
qiniuOssConfig.init();
|
||||
|
||||
SpringUtil.registerBean(userId, qiNiuOssClient(qiniuOssConfig));
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
log.error("QiniuOssConfiguration.qiniuOssClient:{}", e.getMessage(), e);
|
||||
return Result.fail();
|
||||
}
|
||||
}
|
||||
|
||||
private StandardOssClient qiNiuOssClient(QiNiuOssConfig qiNiuOssConfig) {
|
||||
|
@@ -13,7 +13,8 @@ public class QiNiuOssConfig {
|
||||
private String secretKey;
|
||||
private String bucketName;
|
||||
private QiNiuOssClientConfig clientConfig;
|
||||
|
||||
private String Region;
|
||||
private String endpoint;
|
||||
/**
|
||||
* 断点续传参数
|
||||
*/
|
||||
|
@@ -168,5 +168,6 @@ public class SchisandraOssQiniuBO implements Serializable {
|
||||
*/
|
||||
private String checkBucket;
|
||||
|
||||
private String endpoint;
|
||||
}
|
||||
|
||||
|
@@ -34,6 +34,7 @@
|
||||
<result column="extra_json" jdbcType="VARCHAR" property="extraJson"/>
|
||||
<result column="create_bucket" jdbcType="VARCHAR" property="createBucket"/>
|
||||
<result column="check_bucket" jdbcType="VARCHAR" property="checkBucket"/>
|
||||
<result column="endpoint" jdbcType="VARCHAR" property="endpoint"/>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user