feat: 各种存储桶的配置
This commit is contained in:
@@ -0,0 +1,309 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.jinshan;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.io.file.FileNameUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.ksyun.ks3.dto.*;
|
||||||
|
import com.ksyun.ks3.service.Ks3;
|
||||||
|
import com.ksyun.ks3.service.request.CompleteMultipartUploadRequest;
|
||||||
|
import com.ksyun.ks3.service.request.GetObjectRequest;
|
||||||
|
import com.ksyun.ks3.service.request.InitiateMultipartUploadRequest;
|
||||||
|
import com.ksyun.ks3.service.request.UploadPartRequest;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.jinshan.model.JinShanOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.model.DirectoryOssInfo;
|
||||||
|
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.model.download.DownloadCheckPoint;
|
||||||
|
import com.schisandra.oss.application.oss.model.download.DownloadObjectStat;
|
||||||
|
import com.schisandra.oss.application.oss.model.upload.*;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: jinshan oss client
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:01
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class JinShanOssClient implements StandardOssClient {
|
||||||
|
|
||||||
|
public static final String KS3_OBJECT_NAME = "ks3";
|
||||||
|
|
||||||
|
private Ks3 ks3;
|
||||||
|
private JinShanOssConfig jinShanOssConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||||
|
String bucket = getBucket();
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
if (isOverride || !ks3.objectExists(bucket, key)) {
|
||||||
|
ks3.putObject(bucket, key, is, null);
|
||||||
|
}
|
||||||
|
return getInfo(targetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoadCheckPoint(File file, String targetName) {
|
||||||
|
return uploadFile(file, targetName, jinShanOssConfig.getSliceConfig(), OssConstant.OssType.JINSHAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeUpload(UpLoadCheckPoint upLoadCheckPoint, List<UpLoadPartEntityTag> partEntityTags) {
|
||||||
|
List<PartETag> eTags = partEntityTags.stream().sorted(Comparator.comparingInt(UpLoadPartEntityTag::getPartNumber))
|
||||||
|
.map(partEntityTag -> {
|
||||||
|
PartETag p = new PartETag();
|
||||||
|
p.seteTag(partEntityTag.getETag());
|
||||||
|
p.setPartNumber(partEntityTag.getPartNumber());
|
||||||
|
return p;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
CompleteMultipartUploadRequest completeMultipartUploadRequest =
|
||||||
|
new CompleteMultipartUploadRequest(upLoadCheckPoint.getBucket(), upLoadCheckPoint.getKey(), upLoadCheckPoint.getUploadId(), eTags);
|
||||||
|
ks3.completeMultipartUpload(completeMultipartUploadRequest);
|
||||||
|
FileUtil.del(upLoadCheckPoint.getCheckpointFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareUpload(UpLoadCheckPoint uploadCheckPoint, File upLoadFile, String targetName, String checkpointFile, SliceConfig slice) {
|
||||||
|
String bucket = getBucket();
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
uploadCheckPoint.setMagic(UpLoadCheckPoint.UPLOAD_MAGIC);
|
||||||
|
uploadCheckPoint.setUploadFile(upLoadFile.getPath());
|
||||||
|
uploadCheckPoint.setKey(key);
|
||||||
|
uploadCheckPoint.setBucket(bucket);
|
||||||
|
uploadCheckPoint.setCheckpointFile(checkpointFile);
|
||||||
|
uploadCheckPoint.setUploadFileStat(UpLoadFileStat.getFileStat(uploadCheckPoint.getUploadFile()));
|
||||||
|
|
||||||
|
long partSize = slice.getPartSize();
|
||||||
|
long fileLength = upLoadFile.length();
|
||||||
|
int parts = (int) (fileLength / partSize);
|
||||||
|
if (fileLength % partSize > 0) {
|
||||||
|
parts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadCheckPoint.setUploadParts(splitUploadFile(uploadCheckPoint.getUploadFileStat().getSize(), partSize));
|
||||||
|
uploadCheckPoint.setPartEntityTags(new ArrayList<>());
|
||||||
|
uploadCheckPoint.setOriginPartSize(parts);
|
||||||
|
|
||||||
|
InitiateMultipartUploadResult initiateMultipartUploadResult =
|
||||||
|
ks3.initiateMultipartUpload(new InitiateMultipartUploadRequest(bucket, key));
|
||||||
|
|
||||||
|
uploadCheckPoint.setUploadId(initiateMultipartUploadResult.getUploadId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UpLoadPartResult uploadPart(UpLoadCheckPoint upLoadCheckPoint, int partNum, InputStream inputStream) {
|
||||||
|
UploadPart uploadPart = upLoadCheckPoint.getUploadParts().get(partNum);
|
||||||
|
long partSize = uploadPart.getSize();
|
||||||
|
UpLoadPartResult partResult = new UpLoadPartResult(partNum + 1, uploadPart.getOffset(), partSize);
|
||||||
|
|
||||||
|
try {
|
||||||
|
inputStream.skip(uploadPart.getOffset());
|
||||||
|
|
||||||
|
UploadPartRequest uploadPartRequest = new UploadPartRequest(upLoadCheckPoint.getBucket(), upLoadCheckPoint.getKey());
|
||||||
|
uploadPartRequest.setUploadId(upLoadCheckPoint.getUploadId());
|
||||||
|
uploadPartRequest.setInputStream(inputStream);
|
||||||
|
uploadPartRequest.setPartSize(partSize);
|
||||||
|
uploadPartRequest.setPartNumber(partNum + 1);
|
||||||
|
PartETag eTag = ks3.uploadPart(uploadPartRequest);
|
||||||
|
|
||||||
|
partResult.setNumber(eTag.getPartNumber());
|
||||||
|
partResult.setEntityTag(new UpLoadPartEntityTag().setETag(eTag.geteTag()).setPartNumber(eTag.getPartNumber()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
partResult.setFailed(true);
|
||||||
|
partResult.setException(e);
|
||||||
|
} finally {
|
||||||
|
IoUtil.close(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return partResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoad(OutputStream os, String targetName) {
|
||||||
|
GetObjectResult objectResult = ks3.getObject(getBucket(), getKey(targetName, false));
|
||||||
|
IoUtil.copy(objectResult.getObject().getObjectContent(), os);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoadCheckPoint(File localFile, String targetName) {
|
||||||
|
downLoadFile(localFile, targetName, jinShanOssConfig.getSliceConfig(), OssConstant.OssType.JINSHAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DownloadObjectStat getDownloadObjectStat(String targetName) {
|
||||||
|
GetObjectResult objectResult = ks3.getObject(getBucket(), getKey(targetName, false));
|
||||||
|
ObjectMetadata objectMetadata = objectResult.getObject().getObjectMetadata();
|
||||||
|
DateTime date = DateUtil.date(objectMetadata.getLastModified());
|
||||||
|
long contentLength = objectMetadata.getContentLength();
|
||||||
|
String eTag = objectMetadata.getETag();
|
||||||
|
return new DownloadObjectStat().setSize(contentLength).setLastModified(date).setDigest(eTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareDownload(DownloadCheckPoint downloadCheckPoint, File localFile, String targetName, String checkpointFile) {
|
||||||
|
downloadCheckPoint.setMagic(DownloadCheckPoint.DOWNLOAD_MAGIC);
|
||||||
|
downloadCheckPoint.setDownloadFile(localFile.getPath());
|
||||||
|
downloadCheckPoint.setBucketName(getBucket());
|
||||||
|
downloadCheckPoint.setKey(getKey(targetName, false));
|
||||||
|
downloadCheckPoint.setCheckPointFile(checkpointFile);
|
||||||
|
|
||||||
|
downloadCheckPoint.setObjectStat(getDownloadObjectStat(targetName));
|
||||||
|
|
||||||
|
long downloadSize;
|
||||||
|
if (downloadCheckPoint.getObjectStat().getSize() > 0) {
|
||||||
|
Long partSize = jinShanOssConfig.getSliceConfig().getPartSize();
|
||||||
|
long[] slice = getDownloadSlice(new long[0], downloadCheckPoint.getObjectStat().getSize());
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadFile(slice[0], slice[1], partSize));
|
||||||
|
downloadSize = slice[1];
|
||||||
|
} else {
|
||||||
|
downloadSize = 0;
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadOneFile());
|
||||||
|
}
|
||||||
|
downloadCheckPoint.setOriginPartSize(downloadCheckPoint.getDownloadParts().size());
|
||||||
|
createDownloadTemp(downloadCheckPoint.getTempDownloadFile(), downloadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream downloadPart(String key, long start, long end) {
|
||||||
|
GetObjectRequest request = new GetObjectRequest(getBucket(), key);
|
||||||
|
request.setRange(start, end);
|
||||||
|
GetObjectResult object = ks3.getObject(request);
|
||||||
|
return object.getObject().getObjectContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String targetName) {
|
||||||
|
ks3.deleteObject(getBucket(), getKey(targetName, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
String bucket = getBucket();
|
||||||
|
String newTargetName = getKey(targetName, false);
|
||||||
|
if (isOverride || !ks3.objectExists(bucket, newTargetName)) {
|
||||||
|
ks3.copyObject(bucket, newTargetName, bucket, getKey(sourceName, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
OssInfo ossInfo = getBaseInfo(key);
|
||||||
|
ossInfo.setName(StrUtil.equals(targetName, StrUtil.SLASH) ? targetName : FileNameUtil.getName(targetName));
|
||||||
|
ossInfo.setPath(OssPathUtil.replaceKey(targetName, ossInfo.getName(), true));
|
||||||
|
|
||||||
|
if (isRecursion && isDirectory(key)) {
|
||||||
|
String prefix = OssPathUtil.convertPath(key, false);
|
||||||
|
ObjectListing listObjects = ks3.listObjects(getBucket(), prefix.endsWith(StrUtil.SLASH) ? prefix : prefix + StrUtil.SLASH);
|
||||||
|
|
||||||
|
List<OssInfo> fileOssInfos = new ArrayList<>();
|
||||||
|
List<OssInfo> directoryInfos = new ArrayList<>();
|
||||||
|
if (ObjectUtil.isNotEmpty(listObjects.getObjectSummaries())) {
|
||||||
|
for (Ks3ObjectSummary ks3ObjectSummary : listObjects.getObjectSummaries()) {
|
||||||
|
if (FileNameUtil.getName(ks3ObjectSummary.getKey()).equals(FileNameUtil.getName(key))) {
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.date(ks3ObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setCreateTime(DateUtil.date(ks3ObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLength(Convert.toStr(ks3ObjectSummary.getSize()));
|
||||||
|
} else {
|
||||||
|
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(ks3ObjectSummary.getKey(), getBasePath(), false), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotEmpty(listObjects.getCommonPrefixes())) {
|
||||||
|
for (String commonPrefix : listObjects.getCommonPrefixes()) {
|
||||||
|
String target = OssPathUtil.replaceKey(commonPrefix, getBasePath(), false);
|
||||||
|
if (isDirectory(commonPrefix)) {
|
||||||
|
directoryInfos.add(getInfo(target, true));
|
||||||
|
} else {
|
||||||
|
fileOssInfos.add(getInfo(target, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(directoryInfos) && directoryInfos.get(0) instanceof DirectoryOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean isExist(String targetName) {
|
||||||
|
return ks3.objectExists(getBucket(), getKey(targetName, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBasePath() {
|
||||||
|
return jinShanOssConfig.getBasePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getClientObject() {
|
||||||
|
return new HashMap<String, Object>() {
|
||||||
|
{
|
||||||
|
put(KS3_OBJECT_NAME, getKs3());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getBucket() {
|
||||||
|
String bucketName = jinShanOssConfig.getBucketName();
|
||||||
|
if (!ks3.bucketExists(bucketName)) {
|
||||||
|
ks3.createBucket(bucketName);
|
||||||
|
}
|
||||||
|
return bucketName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OssInfo getBaseInfo(String key) {
|
||||||
|
OssInfo ossInfo;
|
||||||
|
|
||||||
|
if (isFile(key)) {
|
||||||
|
ossInfo = new FileOssInfo();
|
||||||
|
try {
|
||||||
|
GetObjectResult objectResult = ks3.getObject(getBucket(), key);
|
||||||
|
ObjectMetadata objectMetadata = objectResult.getObject().getObjectMetadata();
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setCreateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLength(Convert.toStr(objectMetadata.getContentLength()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取{}文件属性失败", key, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ossInfo = new DirectoryOssInfo();
|
||||||
|
}
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,91 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.jinshan;
|
||||||
|
|
||||||
|
import cn.hutool.core.text.CharPool;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import com.ksyun.ks3.http.Region;
|
||||||
|
import com.ksyun.ks3.service.Ks3;
|
||||||
|
import com.ksyun.ks3.service.Ks3Client;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.convert.SchisandraOssJdDTOConverter;
|
||||||
|
import com.schisandra.oss.application.convert.SchisandraOssJinshanDTOConverter;
|
||||||
|
import com.schisandra.oss.application.dto.SchisandraOssJinshanDTO;
|
||||||
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.jd.model.JdOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.core.jinshan.model.JinShanOssClientConfig;
|
||||||
|
import com.schisandra.oss.application.oss.core.jinshan.model.JinShanOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.core.jinshan.model.Ks3ClientConfig;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssJdBO;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssJinshanBO;
|
||||||
|
import com.schisandra.oss.domain.service.SchisandraOssJinshanDomainService;
|
||||||
|
import com.schisandra.oss.infra.basic.dao.SchisandraOssJinshanDao;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssJinshan;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.SpringBootConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:jinshan oss配置信息
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 11:26
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class JinShanOssConfiguration {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraOssJinshanDomainService schisandraOssJinshanDomainService;
|
||||||
|
|
||||||
|
|
||||||
|
public StandardOssClient jinShanOssClient(String userId) {
|
||||||
|
SchisandraOssJinshanBO schisandraOssJinshan=schisandraOssJinshanDomainService.getJinshanOssConfig(userId);
|
||||||
|
SchisandraOssJinshanDTO schisandraOssJinshanDTO= SchisandraOssJinshanDTOConverter.INSTANCE.convertBOToDTO(schisandraOssJinshan);
|
||||||
|
if (ObjectUtil.isEmpty(schisandraOssJinshanDTO)) {
|
||||||
|
log.error("jinshan oss配置信息获取失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String accessKeyId = schisandraOssJinshanDTO.getAccessKeyId();
|
||||||
|
String accessKeySecret = schisandraOssJinshanDTO.getAccessKeySecret();
|
||||||
|
String endpoint = schisandraOssJinshanDTO.getEndpoint();
|
||||||
|
Region region = Region.valueOf(schisandraOssJinshanDTO.getRegion());
|
||||||
|
String securityToken = schisandraOssJinshanDTO.getSecurityToken();
|
||||||
|
JinShanOssConfig jinshanConfig = new JinShanOssConfig();
|
||||||
|
jinshanConfig.setAccessKeyId(accessKeyId);
|
||||||
|
jinshanConfig.setAccessKeySecret(accessKeySecret);
|
||||||
|
jinshanConfig.setEndpoint(endpoint);
|
||||||
|
jinshanConfig.setRegion(region);
|
||||||
|
jinshanConfig.setSecurityToken(securityToken);
|
||||||
|
return jinShanOssClient(jinshanConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StandardOssClient jinShanOssClient(JinShanOssConfig jinShanOssConfig) {
|
||||||
|
return new JinShanOssClient(ks3(jinShanOssConfig), jinShanOssConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ks3 ks3(JinShanOssConfig ossConfig) {
|
||||||
|
JinShanOssClientConfig jinShanOssClientConfig = Optional.ofNullable(ossConfig.getClientConfig()).orElse(new JinShanOssClientConfig());
|
||||||
|
|
||||||
|
Ks3ClientConfig clientConfig = jinShanOssClientConfig.toClientConfig();
|
||||||
|
clientConfig.setHttpClientConfig(jinShanOssClientConfig.toHttpClientConfig());
|
||||||
|
clientConfig.setEndpoint(ossConfig.getEndpoint());
|
||||||
|
clientConfig.setRegion(ossConfig.getRegion());
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotEmpty(ossConfig.getSecurityToken())) {
|
||||||
|
return new Ks3Client(ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret(), ossConfig.getSecurityToken(), clientConfig);
|
||||||
|
} else {
|
||||||
|
return new Ks3Client(ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret(), clientConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,55 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.jinshan.model;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.ksyun.ks3.http.HttpClientConfig;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class JinShanOssClientConfig extends HttpClientConfig {
|
||||||
|
/**
|
||||||
|
* http或者https
|
||||||
|
*/
|
||||||
|
private Ks3ClientConfig.PROTOCOL protocol = Ks3ClientConfig.PROTOCOL.http;
|
||||||
|
/**
|
||||||
|
* 签名版本
|
||||||
|
*/
|
||||||
|
private Ks3ClientConfig.SignerVersion version = Ks3ClientConfig.SignerVersion.V2;
|
||||||
|
/**
|
||||||
|
* 是否使用path style access方式访问
|
||||||
|
*/
|
||||||
|
private boolean pathStyleAccess = false;
|
||||||
|
/**
|
||||||
|
* 允许客户端发送匿名请求
|
||||||
|
*/
|
||||||
|
private boolean allowAnonymous = true;
|
||||||
|
/**
|
||||||
|
* 当服务端返回307时是否自动跳转,
|
||||||
|
* 主要发生在用Region A的endpoint请求Region B的endpoint
|
||||||
|
*/
|
||||||
|
private boolean flowRedirect = true;
|
||||||
|
/**
|
||||||
|
* 是否使用绑定的域名作为endpoint
|
||||||
|
*/
|
||||||
|
private boolean domainMode = false;
|
||||||
|
/**
|
||||||
|
* 签名类
|
||||||
|
*/
|
||||||
|
private String signerClass = "com.ksyun.ks3.signer.DefaultSigner";
|
||||||
|
private boolean useGzip = false;
|
||||||
|
|
||||||
|
public Ks3ClientConfig toClientConfig() {
|
||||||
|
Ks3ClientConfig clientConfig = new Ks3ClientConfig();
|
||||||
|
BeanUtil.copyProperties(this, clientConfig);
|
||||||
|
return clientConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpClientConfig toHttpClientConfig() {
|
||||||
|
HttpClientConfig httpClientConfig = new HttpClientConfig();
|
||||||
|
BeanUtil.copyProperties(this, httpClientConfig);
|
||||||
|
return httpClientConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.jinshan.model;
|
||||||
|
|
||||||
|
import com.ksyun.ks3.http.Region;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class JinShanOssConfig {
|
||||||
|
private String accessKeyId;
|
||||||
|
private String accessKeySecret;
|
||||||
|
private String bucketName;
|
||||||
|
private String endpoint;
|
||||||
|
/**
|
||||||
|
* 服务地址,参考{@linkplain http://ks3.ksyun.com/doc/api/index.html Doc} </br>
|
||||||
|
* 中国(杭州):kss.ksyun.com</br>
|
||||||
|
* 中国(杭州)cdn:kssws.ks-cdn.com</br>
|
||||||
|
* 美国(圣克拉拉):ks3-us-west-1.ksyun.com</br>
|
||||||
|
* 中国(北京):ks3-cn-beijing.ksyun.com</br>
|
||||||
|
* 中国(香港):ks3-cn-hk-1.ksyun.com</br>
|
||||||
|
* 中国(上海):ks3-cn-shanghai.ksyun.com</br>
|
||||||
|
*/
|
||||||
|
private Region region = null;
|
||||||
|
private String securityToken;
|
||||||
|
private String basePath;
|
||||||
|
|
||||||
|
private JinShanOssClientConfig clientConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断点续传参数
|
||||||
|
*/
|
||||||
|
private SliceConfig sliceConfig = new SliceConfig();
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
this.sliceConfig.init();
|
||||||
|
basePath = OssPathUtil.valid(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.jinshan.model;
|
||||||
|
|
||||||
|
|
||||||
|
public class Ks3ClientConfig extends com.ksyun.ks3.service.Ks3ClientConfig {
|
||||||
|
|
||||||
|
private SignerVersion version = SignerVersion.V2;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SignerVersion getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVersion(SignerVersion version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,369 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qingyun;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.io.file.FileNameUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.qingstor.sdk.exception.QSException;
|
||||||
|
import com.qingstor.sdk.service.Bucket;
|
||||||
|
import com.qingstor.sdk.service.QingStor;
|
||||||
|
import com.qingstor.sdk.service.Types;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.qingyun.model.QingYunOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.exception.OssException;
|
||||||
|
import com.schisandra.oss.application.oss.model.DirectoryOssInfo;
|
||||||
|
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.model.download.DownloadCheckPoint;
|
||||||
|
import com.schisandra.oss.application.oss.model.download.DownloadObjectStat;
|
||||||
|
import com.schisandra.oss.application.oss.model.upload.*;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.*;
|
||||||
|
/**
|
||||||
|
* @description: qingyun oss client
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:02
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class QingYunOssClient implements StandardOssClient {
|
||||||
|
|
||||||
|
public static final String QINGSTORE_OBJECT_NAME = "qingStor";
|
||||||
|
public static final String BUCKET_OBJECT_NAME = "bucketClient";
|
||||||
|
|
||||||
|
private QingStor qingStor;
|
||||||
|
private Bucket bucketClient;
|
||||||
|
private QingYunOssConfig qingYunOssConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
if (isOverride || !isExist(targetName)) {
|
||||||
|
Bucket.PutObjectInput input = new Bucket.PutObjectInput();
|
||||||
|
input.setBodyInputStream(is);
|
||||||
|
try {
|
||||||
|
bucketClient.putObject(key, input);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getInfo(targetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoadCheckPoint(File file, String targetName) {
|
||||||
|
return uploadFile(file, targetName, qingYunOssConfig.getSliceConfig(), OssConstant.OssType.QINGYUN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeUpload(UpLoadCheckPoint upLoadCheckPoint, List<UpLoadPartEntityTag> partEntityTags) {
|
||||||
|
try {
|
||||||
|
String uploadId = upLoadCheckPoint.getUploadId();
|
||||||
|
String key = upLoadCheckPoint.getKey();
|
||||||
|
|
||||||
|
Bucket.ListMultipartInput listMultipartInput = new Bucket.ListMultipartInput();
|
||||||
|
listMultipartInput.setUploadID(uploadId);
|
||||||
|
Bucket.ListMultipartOutput output = bucketClient.listMultipart(key, listMultipartInput);
|
||||||
|
List<Types.ObjectPartModel> objectParts = output.getObjectParts();
|
||||||
|
|
||||||
|
Bucket.CompleteMultipartUploadInput multipartUploadInput = new Bucket.CompleteMultipartUploadInput();
|
||||||
|
multipartUploadInput.setUploadID(uploadId);
|
||||||
|
multipartUploadInput.setObjectParts(objectParts);
|
||||||
|
|
||||||
|
bucketClient.completeMultipartUpload(key, multipartUploadInput);
|
||||||
|
FileUtil.del(upLoadCheckPoint.getCheckpointFile());
|
||||||
|
} catch (QSException e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareUpload(UpLoadCheckPoint uploadCheckPoint, File upLoadFile, String targetName, String checkpointFile, SliceConfig slice) {
|
||||||
|
String bucket = getBucket();
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
uploadCheckPoint.setMagic(UpLoadCheckPoint.UPLOAD_MAGIC);
|
||||||
|
uploadCheckPoint.setUploadFile(upLoadFile.getPath());
|
||||||
|
uploadCheckPoint.setKey(key);
|
||||||
|
uploadCheckPoint.setBucket(bucket);
|
||||||
|
uploadCheckPoint.setCheckpointFile(checkpointFile);
|
||||||
|
uploadCheckPoint.setUploadFileStat(UpLoadFileStat.getFileStat(uploadCheckPoint.getUploadFile()));
|
||||||
|
|
||||||
|
long partSize = slice.getPartSize();
|
||||||
|
long fileLength = upLoadFile.length();
|
||||||
|
int parts = (int) (fileLength / partSize);
|
||||||
|
if (fileLength % partSize > 0) {
|
||||||
|
parts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadCheckPoint.setUploadParts(splitUploadFile(uploadCheckPoint.getUploadFileStat().getSize(), partSize));
|
||||||
|
uploadCheckPoint.setPartEntityTags(new ArrayList<>());
|
||||||
|
uploadCheckPoint.setOriginPartSize(parts);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Bucket.InitiateMultipartUploadInput input = new Bucket.InitiateMultipartUploadInput();
|
||||||
|
Bucket.InitiateMultipartUploadOutput multipartUploadOutput = bucketClient.initiateMultipartUpload(key, input);
|
||||||
|
uploadCheckPoint.setUploadId(multipartUploadOutput.getUploadID());
|
||||||
|
} catch (QSException e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UpLoadPartResult uploadPart(UpLoadCheckPoint upLoadCheckPoint, int partNum, InputStream inputStream) {
|
||||||
|
UploadPart uploadPart = upLoadCheckPoint.getUploadParts().get(partNum);
|
||||||
|
long partSize = uploadPart.getSize();
|
||||||
|
UpLoadPartResult partResult = new UpLoadPartResult(partNum + 1, uploadPart.getOffset(), partSize);
|
||||||
|
|
||||||
|
try {
|
||||||
|
inputStream.skip(uploadPart.getOffset());
|
||||||
|
|
||||||
|
Bucket.UploadMultipartInput input = new Bucket.UploadMultipartInput();
|
||||||
|
input.setPartNumber(partNum + 1);
|
||||||
|
input.setFileOffset(uploadPart.getOffset());
|
||||||
|
input.setUploadID(upLoadCheckPoint.getUploadId());
|
||||||
|
input.setBodyInputStream(inputStream);
|
||||||
|
Bucket.UploadMultipartOutput multipartOutput = bucketClient.uploadMultipart(upLoadCheckPoint.getKey(), input);
|
||||||
|
|
||||||
|
partResult.setNumber(partNum + 1);
|
||||||
|
partResult.setEntityTag(new UpLoadPartEntityTag().setETag(multipartOutput.getETag()).setPartNumber(partNum));
|
||||||
|
} catch (Exception e) {
|
||||||
|
partResult.setFailed(true);
|
||||||
|
partResult.setException(e);
|
||||||
|
} finally {
|
||||||
|
IoUtil.close(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return partResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoad(OutputStream os, String targetName) {
|
||||||
|
try {
|
||||||
|
Bucket.GetObjectInput input = new Bucket.GetObjectInput();
|
||||||
|
Bucket.GetObjectOutput object = bucketClient.getObject(getKey(targetName, false), input);
|
||||||
|
IoUtil.copy(object.getBodyInputStream(), os);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoadCheckPoint(File localFile, String targetName) {
|
||||||
|
downLoadFile(localFile, targetName, qingYunOssConfig.getSliceConfig(), OssConstant.OssType.QINGYUN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DownloadObjectStat getDownloadObjectStat(String targetName) {
|
||||||
|
try {
|
||||||
|
Bucket.GetObjectInput input = new Bucket.GetObjectInput();
|
||||||
|
Bucket.GetObjectOutput object = bucketClient.getObject(getKey(targetName, false), input);
|
||||||
|
DateTime date = DateUtil.date(Date.parse(object.getLastModified()));
|
||||||
|
long contentLength = object.getContentLength();
|
||||||
|
String eTag = object.getETag();
|
||||||
|
return new DownloadObjectStat().setSize(contentLength).setLastModified(date).setDigest(eTag);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareDownload(DownloadCheckPoint downloadCheckPoint, File localFile, String targetName, String checkpointFile) {
|
||||||
|
downloadCheckPoint.setMagic(DownloadCheckPoint.DOWNLOAD_MAGIC);
|
||||||
|
downloadCheckPoint.setDownloadFile(localFile.getPath());
|
||||||
|
downloadCheckPoint.setBucketName(getBucket());
|
||||||
|
downloadCheckPoint.setKey(getKey(targetName, false));
|
||||||
|
downloadCheckPoint.setCheckPointFile(checkpointFile);
|
||||||
|
|
||||||
|
downloadCheckPoint.setObjectStat(getDownloadObjectStat(targetName));
|
||||||
|
|
||||||
|
long downloadSize;
|
||||||
|
if (downloadCheckPoint.getObjectStat().getSize() > 0) {
|
||||||
|
Long partSize = qingYunOssConfig.getSliceConfig().getPartSize();
|
||||||
|
long[] slice = getDownloadSlice(new long[0], downloadCheckPoint.getObjectStat().getSize());
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadFile(slice[0], slice[1], partSize));
|
||||||
|
downloadSize = slice[1];
|
||||||
|
} else {
|
||||||
|
downloadSize = 0;
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadOneFile());
|
||||||
|
}
|
||||||
|
downloadCheckPoint.setOriginPartSize(downloadCheckPoint.getDownloadParts().size());
|
||||||
|
createDownloadTemp(downloadCheckPoint.getTempDownloadFile(), downloadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream downloadPart(String key, long start, long end) {
|
||||||
|
try {
|
||||||
|
Bucket.GetObjectInput putObjectInput = new Bucket.GetObjectInput();
|
||||||
|
putObjectInput.setRange("bytes=" + start + "-" + end);
|
||||||
|
Bucket.GetObjectOutput object = bucketClient.getObject(key, putObjectInput);
|
||||||
|
return object.getBodyInputStream();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String targetName) {
|
||||||
|
try {
|
||||||
|
bucketClient.deleteObject(getKey(targetName, false));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
String bucket = getBucket();
|
||||||
|
String newSourceName = getKey(sourceName, false);
|
||||||
|
String newTargetName = getKey(targetName, false);
|
||||||
|
if (isOverride || !isExist(targetName)) {
|
||||||
|
try {
|
||||||
|
Bucket.PutObjectInput input = new Bucket.PutObjectInput();
|
||||||
|
input.setXQSCopySource(StrUtil.SLASH + bucket + StrUtil.SLASH + newSourceName);
|
||||||
|
bucketClient.putObject(newTargetName, input);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void move(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
String bucket = getBucket();
|
||||||
|
String newSourceName = getKey(sourceName, false);
|
||||||
|
String newTargetName = getKey(targetName, false);
|
||||||
|
if (isOverride || !isExist(targetName)) {
|
||||||
|
try {
|
||||||
|
Bucket.PutObjectInput input = new Bucket.PutObjectInput();
|
||||||
|
input.setXQSMoveSource(StrUtil.SLASH + bucket + StrUtil.SLASH + newSourceName);
|
||||||
|
bucketClient.putObject(newTargetName, input);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
OssInfo ossInfo = getBaseInfo(key);
|
||||||
|
ossInfo.setName(StrUtil.equals(targetName, StrUtil.SLASH) ? targetName : FileNameUtil.getName(targetName));
|
||||||
|
ossInfo.setPath(OssPathUtil.replaceKey(targetName, ossInfo.getName(), true));
|
||||||
|
|
||||||
|
if (isRecursion && isDirectory(key)) {
|
||||||
|
List<OssInfo> fileOssInfos = new ArrayList<>();
|
||||||
|
List<OssInfo> directoryInfos = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String prefix = OssPathUtil.convertPath(key, false);
|
||||||
|
Bucket.ListObjectsInput input = new Bucket.ListObjectsInput();
|
||||||
|
input.setPrefix(prefix.endsWith(StrUtil.SLASH) ? prefix : prefix + StrUtil.SLASH);
|
||||||
|
input.setDelimiter(StrUtil.SLASH);
|
||||||
|
Bucket.ListObjectsOutput listObjects = bucketClient.listObjects(input);
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotEmpty(listObjects.getKeys())) {
|
||||||
|
for (Types.KeyModel keyModel : listObjects.getKeys()) {
|
||||||
|
if (FileNameUtil.getName(keyModel.getKey()).equals(FileNameUtil.getName(key))) {
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.parse(keyModel.getCreated()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setCreateTime(DateUtil.parse(keyModel.getCreated()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLength(Convert.toStr(keyModel.getSize()));
|
||||||
|
} else {
|
||||||
|
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(keyModel.getKey(), getBasePath(), false), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotEmpty(listObjects.getCommonPrefixes())) {
|
||||||
|
for (String commonPrefix : listObjects.getCommonPrefixes()) {
|
||||||
|
String target = OssPathUtil.replaceKey(commonPrefix, getBasePath(), false);
|
||||||
|
if (isDirectory(commonPrefix)) {
|
||||||
|
directoryInfos.add(getInfo(target, true));
|
||||||
|
} else {
|
||||||
|
fileOssInfos.add(getInfo(target, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(directoryInfos) && directoryInfos.get(0) instanceof DirectoryOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean isExist(String targetName) {
|
||||||
|
OssInfo info = getInfo(targetName);
|
||||||
|
return ObjectUtil.isNotEmpty(info.getLength()) && Convert.toLong(info.getLength()) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBasePath() {
|
||||||
|
return qingYunOssConfig.getBasePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getClientObject() {
|
||||||
|
return new HashMap<String, Object>() {
|
||||||
|
{
|
||||||
|
put(QINGSTORE_OBJECT_NAME, getQingStor());
|
||||||
|
put(BUCKET_OBJECT_NAME, getBucketClient());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getBucket() {
|
||||||
|
return qingYunOssConfig.getBucketName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OssInfo getBaseInfo(String key) {
|
||||||
|
OssInfo ossInfo;
|
||||||
|
|
||||||
|
if (isFile(key)) {
|
||||||
|
ossInfo = new FileOssInfo();
|
||||||
|
try {
|
||||||
|
Bucket.GetObjectOutput object = bucketClient.getObject(key, new Bucket.GetObjectInput());
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.date(Date.parse(object.getLastModified())).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setCreateTime(DateUtil.date(Date.parse(object.getLastModified())).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLength(Convert.toStr(object.getContentLength()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取{}文件属性失败", key, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ossInfo = new DirectoryOssInfo();
|
||||||
|
}
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,93 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qingyun;
|
||||||
|
|
||||||
|
import cn.hutool.core.text.CharPool;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import com.aliyun.oss.OSSClient;
|
||||||
|
import com.qingstor.sdk.config.EnvContext;
|
||||||
|
import com.qingstor.sdk.service.Bucket;
|
||||||
|
import com.qingstor.sdk.service.QingStor;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.convert.SchisandraOssJdDTOConverter;
|
||||||
|
import com.schisandra.oss.application.convert.SchisandraOssQingyunDTOConverter;
|
||||||
|
import com.schisandra.oss.application.dto.SchisandraOssJdDTO;
|
||||||
|
import com.schisandra.oss.application.dto.SchisandraOssQingyunDTO;
|
||||||
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.jd.model.JdOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.core.qingyun.model.QingYunOssClientConfig;
|
||||||
|
import com.schisandra.oss.application.oss.core.qingyun.model.QingYunOssConfig;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssJdBO;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssQingyunBO;
|
||||||
|
import com.schisandra.oss.domain.service.SchisandraOssQingyunDomainService;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssQingyun;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.SpringBootConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: qingyun oss配置
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 11:27
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class QingYunOssConfiguration {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraOssQingyunDomainService schisandraOssQingyunDomainService;
|
||||||
|
|
||||||
|
public StandardOssClient qingYunOssClient(String userId) {
|
||||||
|
SchisandraOssQingyunBO schisandraOssQingyunBO = schisandraOssQingyunDomainService.getQingyunOssConfig(userId);
|
||||||
|
SchisandraOssQingyunDTO schisandraOssQingyunDTO = SchisandraOssQingyunDTOConverter.INSTANCE.convertBOToDTO(schisandraOssQingyunBO);
|
||||||
|
if (ObjectUtil.isEmpty(schisandraOssQingyunDTO)) {
|
||||||
|
log.error("Qingyun oss配置信息获取失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String endpoint = schisandraOssQingyunDTO.getEndpoint();
|
||||||
|
String accessKey = schisandraOssQingyunDTO.getAccessKey();
|
||||||
|
String accessSecret = schisandraOssQingyunDTO.getAccessSecret();
|
||||||
|
String zone = schisandraOssQingyunDTO.getZone();
|
||||||
|
|
||||||
|
QingYunOssConfig qingYunOssConfig = new QingYunOssConfig();
|
||||||
|
qingYunOssConfig.setEndpoint(endpoint);
|
||||||
|
qingYunOssConfig.setAccessKey(accessKey);
|
||||||
|
qingYunOssConfig.setAccessSecret(accessSecret);
|
||||||
|
qingYunOssConfig.setZone(zone);
|
||||||
|
return qingYunOssClient(qingYunOssConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StandardOssClient qingYunOssClient(QingYunOssConfig qingYunOssConfig) {
|
||||||
|
QingStor qingStor = qingStor(qingYunOssConfig);
|
||||||
|
Bucket bucket = qingStor.getBucket(qingYunOssConfig.getBucketName(), qingYunOssConfig.getZone());
|
||||||
|
return new QingYunOssClient(qingStor, bucket, qingYunOssConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QingStor qingStor(QingYunOssConfig qingYunOssConfig) {
|
||||||
|
EnvContext env = new EnvContext(qingYunOssConfig.getAccessKey(), qingYunOssConfig.getAccessSecret());
|
||||||
|
QingYunOssClientConfig clientConfig = Optional.ofNullable(qingYunOssConfig.getClientConfig()).orElse(new QingYunOssClientConfig());
|
||||||
|
env.setHttpConfig(clientConfig.toClientConfig());
|
||||||
|
String endpoint = qingYunOssConfig.getEndpoint();
|
||||||
|
if (ObjectUtil.isNotEmpty(endpoint)) {
|
||||||
|
env.setEndpoint(endpoint);
|
||||||
|
}
|
||||||
|
env.setCnameSupport(clientConfig.isCnameSupport());
|
||||||
|
String additionalUserAgent = clientConfig.getAdditionalUserAgent();
|
||||||
|
if (ObjectUtil.isNotEmpty(additionalUserAgent)) {
|
||||||
|
env.setAdditionalUserAgent(additionalUserAgent);
|
||||||
|
}
|
||||||
|
env.setVirtualHostEnabled(clientConfig.isVirtualHostEnabled());
|
||||||
|
return new QingStor(env);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qingyun.constant;
|
||||||
|
|
||||||
|
|
||||||
|
public class QingYunOssConstant {
|
||||||
|
public static final String DEFAULT_ENDPOINT = "https://qingstor.com";
|
||||||
|
}
|
@@ -0,0 +1,44 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qingyun.model;
|
||||||
|
|
||||||
|
import com.qingstor.sdk.config.EnvContext;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class QingYunOssClientConfig {
|
||||||
|
/**
|
||||||
|
* 是否支持CNAME作为Endpoint,默认不支持CNAME。
|
||||||
|
*/
|
||||||
|
private boolean cnameSupport = false;
|
||||||
|
/**
|
||||||
|
* 附加的用户代理
|
||||||
|
*/
|
||||||
|
private String additionalUserAgent;
|
||||||
|
/**
|
||||||
|
* 是否启用虚拟Host
|
||||||
|
*/
|
||||||
|
private boolean virtualHostEnabled = false;
|
||||||
|
/**
|
||||||
|
* 读超时时间
|
||||||
|
*/
|
||||||
|
private int readTimeout = 100;
|
||||||
|
/**
|
||||||
|
* 写超时时间
|
||||||
|
*/
|
||||||
|
private int writeTimeout = 100;
|
||||||
|
/**
|
||||||
|
* 连接超时时间
|
||||||
|
*/
|
||||||
|
private int connectionTimeout = 60;
|
||||||
|
|
||||||
|
public EnvContext.HttpConfig toClientConfig() {
|
||||||
|
EnvContext.HttpConfig httpConfig = new EnvContext.HttpConfig();
|
||||||
|
httpConfig.setConnectionTimeout(connectionTimeout);
|
||||||
|
httpConfig.setReadTimeout(readTimeout);
|
||||||
|
httpConfig.setWriteTimeout(writeTimeout);
|
||||||
|
return httpConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qingyun.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.core.qingyun.constant.QingYunOssConstant;
|
||||||
|
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QingYunOssConfig {
|
||||||
|
|
||||||
|
private String endpoint = QingYunOssConstant.DEFAULT_ENDPOINT;
|
||||||
|
private String accessKey;
|
||||||
|
private String accessSecret;
|
||||||
|
|
||||||
|
private String bucketName;
|
||||||
|
private String zone;
|
||||||
|
private String basePath;
|
||||||
|
|
||||||
|
private QingYunOssClientConfig clientConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断点续传参数
|
||||||
|
*/
|
||||||
|
private SliceConfig sliceConfig = new SliceConfig();
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
this.sliceConfig.init();
|
||||||
|
basePath = OssPathUtil.valid(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,305 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qiniu;
|
||||||
|
|
||||||
|
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.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.model.FileInfo;
|
||||||
|
import com.qiniu.storage.model.FileListing;
|
||||||
|
import com.qiniu.storage.persistent.FileRecorder;
|
||||||
|
import com.qiniu.util.Auth;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.qiniu.model.QiNiuOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.exception.OssException;
|
||||||
|
import com.schisandra.oss.application.oss.model.DirectoryOssInfo;
|
||||||
|
import com.schisandra.oss.application.oss.model.FileOssInfo;
|
||||||
|
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||||
|
import com.schisandra.oss.application.oss.model.download.DownloadCheckPoint;
|
||||||
|
import com.schisandra.oss.application.oss.model.download.DownloadObjectStat;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: qiniu oss client
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:00
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class QiNiuOssClient implements StandardOssClient {
|
||||||
|
|
||||||
|
public static final String AUTH_OBJECT_NAME = "auth";
|
||||||
|
public static final String UPLOAD_OBJECT_NAME = "uploadManager";
|
||||||
|
public static final String BUCKET_OBJECT_NAME = "bucketManager";
|
||||||
|
|
||||||
|
private Auth auth;
|
||||||
|
private UploadManager uploadManager;
|
||||||
|
private BucketManager bucketManager;
|
||||||
|
private QiNiuOssConfig qiNiuOssConfig;
|
||||||
|
private Configuration configuration;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||||
|
try {
|
||||||
|
uploadManager.put(is, getKey(targetName, false), getUpToken(), null, null);
|
||||||
|
} catch (QiniuException e) {
|
||||||
|
String errorMsg = String.format("%s上传失败", targetName);
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OssException(errorMsg, e);
|
||||||
|
}
|
||||||
|
return getInfo(targetName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoadCheckPoint(File file, String targetName) {
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileRecorder fileRecorder = new FileRecorder(file.getParent());
|
||||||
|
UploadManager uploadManager = new UploadManager(configuration, fileRecorder);
|
||||||
|
|
||||||
|
uploadManager.put(file.getPath(), key, getUpToken());
|
||||||
|
} catch (Exception e) {
|
||||||
|
String errorMsg = String.format("%s上传失败", targetName);
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OssException(errorMsg, e);
|
||||||
|
}
|
||||||
|
return getInfo(targetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoad(OutputStream os, String targetName) {
|
||||||
|
DownloadUrl downloadUrl = new DownloadUrl("qiniu.com", false, getKey(targetName, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoadCheckPoint(File localFile, String targetName) {
|
||||||
|
downLoadFile(localFile, targetName, qiNiuOssConfig.getSliceConfig(), OssConstant.OssType.QINIU);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DownloadObjectStat getDownloadObjectStat(String targetName) {
|
||||||
|
try {
|
||||||
|
FileInfo fileInfo = bucketManager.stat(getBucket(), getKey(targetName, false));
|
||||||
|
return new DownloadObjectStat().setSize(fileInfo.fsize)
|
||||||
|
.setLastModified(DateUtil.date(fileInfo.putTime / 10000))
|
||||||
|
.setDigest(fileInfo.md5);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareDownload(DownloadCheckPoint downloadCheckPoint, File localFile, String targetName, String checkpointFile) {
|
||||||
|
downloadCheckPoint.setMagic(DownloadCheckPoint.DOWNLOAD_MAGIC);
|
||||||
|
downloadCheckPoint.setDownloadFile(localFile.getPath());
|
||||||
|
downloadCheckPoint.setBucketName(getBucket());
|
||||||
|
downloadCheckPoint.setKey(getKey(targetName, false));
|
||||||
|
downloadCheckPoint.setCheckPointFile(checkpointFile);
|
||||||
|
|
||||||
|
downloadCheckPoint.setObjectStat(getDownloadObjectStat(targetName));
|
||||||
|
|
||||||
|
long downloadSize;
|
||||||
|
if (downloadCheckPoint.getObjectStat().getSize() > 0) {
|
||||||
|
Long partSize = qiNiuOssConfig.getSliceConfig().getPartSize();
|
||||||
|
long[] slice = getDownloadSlice(new long[0], downloadCheckPoint.getObjectStat().getSize());
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadFile(slice[0], slice[1], partSize));
|
||||||
|
downloadSize = slice[1];
|
||||||
|
} else {
|
||||||
|
//download whole file
|
||||||
|
downloadSize = 0;
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadOneFile());
|
||||||
|
}
|
||||||
|
downloadCheckPoint.setOriginPartSize(downloadCheckPoint.getDownloadParts().size());
|
||||||
|
createDownloadTemp(downloadCheckPoint.getTempDownloadFile(), downloadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream downloadPart(String key, long start, long end) {
|
||||||
|
try {
|
||||||
|
DownloadUrl downloadUrl = new DownloadUrl("qiniu.com", false, key);
|
||||||
|
String url = downloadUrl.buildURL();
|
||||||
|
HttpResponse response = HttpUtil.createGet(url)
|
||||||
|
.timeout(-1)
|
||||||
|
.header("Range", "bytes=" + start + "-" + end)
|
||||||
|
.execute();
|
||||||
|
log.debug("start={}, end={}", start, end);
|
||||||
|
return new ByteArrayInputStream(response.bodyBytes());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String targetName) {
|
||||||
|
try {
|
||||||
|
bucketManager.delete(getBucket(), getKey(targetName, false));
|
||||||
|
} catch (QiniuException e) {
|
||||||
|
String errorMsg = String.format("%s删除失败", targetName);
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OssException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
try {
|
||||||
|
bucketManager.copy(getBucket(), getKey(sourceName, false), getBucket(), getKey(targetName, false), isOverride);
|
||||||
|
} catch (QiniuException e) {
|
||||||
|
String errorMsg = String.format("%s复制失败", targetName);
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OssException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void move(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
try {
|
||||||
|
bucketManager.move(getBucket(), getKey(sourceName, false), getBucket(), getKey(targetName, false), isOverride);
|
||||||
|
} catch (QiniuException e) {
|
||||||
|
String errorMsg = String.format("%s移动到%s失败", sourceName, targetName);
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OssException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rename(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
try {
|
||||||
|
bucketManager.rename(getBucket(), getKey(sourceName, false), getKey(targetName, false), isOverride);
|
||||||
|
} catch (QiniuException e) {
|
||||||
|
String errorMsg = String.format("%s重命名为%s失败", sourceName, targetName);
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OssException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
OssInfo ossInfo = getBaseInfo(targetName);
|
||||||
|
if (isRecursion && isDirectory(key)) {
|
||||||
|
FileListing listFiles = bucketManager.listFiles(getBucket(), key, "", 1000, StrUtil.SLASH);
|
||||||
|
|
||||||
|
System.out.println(listFiles);
|
||||||
|
List<OssInfo> fileOssInfos = new ArrayList<>();
|
||||||
|
List<OssInfo> directoryInfos = new ArrayList<>();
|
||||||
|
if (ObjectUtil.isNotEmpty(listFiles.items)) {
|
||||||
|
for (FileInfo fileInfo : listFiles.items) {
|
||||||
|
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(fileInfo.key, getBasePath(), false), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotEmpty(listFiles.commonPrefixes)) {
|
||||||
|
for (String commonPrefix : listFiles.commonPrefixes) {
|
||||||
|
String target = OssPathUtil.replaceKey(commonPrefix, getBasePath(), true);
|
||||||
|
directoryInfos.add(getInfo(target, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(directoryInfos) && directoryInfos.get(0) instanceof DirectoryOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBasePath() {
|
||||||
|
return qiNiuOssConfig.getBasePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getClientObject() {
|
||||||
|
return new HashMap<String, Object>() {
|
||||||
|
{
|
||||||
|
put(AUTH_OBJECT_NAME, getAuth());
|
||||||
|
put(UPLOAD_OBJECT_NAME, getUploadManager());
|
||||||
|
put(BUCKET_OBJECT_NAME, getBucketManager());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getUpToken() {
|
||||||
|
return auth.uploadToken(getBucket());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getBucket() {
|
||||||
|
String bucketName = qiNiuOssConfig.getBucketName();
|
||||||
|
try {
|
||||||
|
if (ObjectUtil.isEmpty(bucketManager.getBucketInfo(bucketName))) {
|
||||||
|
bucketManager.createBucket(bucketName, qiNiuOssConfig.getClientConfig().getRegion().getRegion());
|
||||||
|
}
|
||||||
|
} catch (QiniuException e) {
|
||||||
|
log.error("创建Bucket失败", e);
|
||||||
|
}
|
||||||
|
return bucketName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OssInfo getBaseInfo(String targetName) {
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
OssInfo ossInfo;
|
||||||
|
if (isFile(targetName)) {
|
||||||
|
ossInfo = new FileOssInfo();
|
||||||
|
try {
|
||||||
|
FileInfo fileInfo = bucketManager.stat(getBucket(), key);
|
||||||
|
String putTime = DateUtil.date(fileInfo.putTime / 10000).toString(DatePattern.NORM_DATETIME_PATTERN);
|
||||||
|
ossInfo.setLength(Convert.toStr(fileInfo.fsize));
|
||||||
|
ossInfo.setCreateTime(putTime);
|
||||||
|
ossInfo.setLastUpdateTime(putTime);
|
||||||
|
} catch (QiniuException e) {
|
||||||
|
String errorMsg = String.format("获取%s信息失败", targetName);
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OssException(errorMsg, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ossInfo = new DirectoryOssInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
ossInfo.setName(StrUtil.equals(targetName, StrUtil.SLASH) ? targetName : FileNameUtil.getName(targetName));
|
||||||
|
ossInfo.setPath(OssPathUtil.replaceKey(targetName, ossInfo.getName(), true));
|
||||||
|
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,91 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qiniu;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.qiniu.storage.BucketManager;
|
||||||
|
import com.qiniu.storage.Configuration;
|
||||||
|
import com.qiniu.storage.UploadManager;
|
||||||
|
import com.qiniu.util.Auth;
|
||||||
|
import com.schisandra.oss.application.convert.SchisandraOssQiniuDTOConverter;
|
||||||
|
import com.schisandra.oss.application.dto.SchisandraOssQiniuDTO;
|
||||||
|
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.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: qiniu oss 配置类
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 11:59
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class 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配置信息获取失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String accessKey = schisandraOssQiniuDTO.getAccessKey();
|
||||||
|
String secretKey = schisandraOssQiniuDTO.getSecretKey();
|
||||||
|
QiNiuOssConfig qiNiuOssConfig = new QiNiuOssConfig();
|
||||||
|
qiNiuOssConfig.setAccessKey(accessKey);
|
||||||
|
qiNiuOssConfig.setSecretKey(secretKey);
|
||||||
|
return qiNiuOssClient(qiNiuOssConfig);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private StandardOssClient qiNiuOssClient(QiNiuOssConfig qiNiuOssConfig) {
|
||||||
|
Auth auth = auth(qiNiuOssConfig);
|
||||||
|
Configuration configuration = configuration(qiNiuOssConfig);
|
||||||
|
UploadManager uploadManager = uploadManager(configuration);
|
||||||
|
BucketManager bucketManager = bucketManager(auth, configuration);
|
||||||
|
return qiNiuOssClient(auth, uploadManager, bucketManager, qiNiuOssConfig, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StandardOssClient qiNiuOssClient(Auth auth, UploadManager uploadManager, BucketManager bucketManager,
|
||||||
|
QiNiuOssConfig qiNiuOssConfig, Configuration configuration) {
|
||||||
|
return new QiNiuOssClient(auth, uploadManager, bucketManager, qiNiuOssConfig, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Auth auth(QiNiuOssConfig qiNiuOssConfig) {
|
||||||
|
return Auth.create(qiNiuOssConfig.getAccessKey(), qiNiuOssConfig.getSecretKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public UploadManager uploadManager(Configuration configuration) {
|
||||||
|
return new UploadManager(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BucketManager bucketManager(Auth auth, Configuration configuration) {
|
||||||
|
return new BucketManager(auth, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Configuration configuration(QiNiuOssConfig qiNiuOssConfig) {
|
||||||
|
Configuration configuration = Optional.ofNullable(qiNiuOssConfig.getClientConfig()).orElse(new QiNiuOssClientConfig()).toClientConfig();
|
||||||
|
SliceConfig sliceConfig = qiNiuOssConfig.getSliceConfig();
|
||||||
|
configuration.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;
|
||||||
|
configuration.resumableUploadMaxConcurrentTaskCount = sliceConfig.getTaskNum();
|
||||||
|
configuration.resumableUploadAPIV2BlockSize = sliceConfig.getPartSize().intValue();
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,54 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qiniu.constant;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import com.qiniu.storage.Region;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
|
||||||
|
public enum QiNiuRegion {
|
||||||
|
/**
|
||||||
|
* 华东区域
|
||||||
|
*/
|
||||||
|
HUADONG("huadong"),
|
||||||
|
/**
|
||||||
|
* 华北区域
|
||||||
|
*/
|
||||||
|
HUABEI("huabei"),
|
||||||
|
/**
|
||||||
|
* 华南区域
|
||||||
|
*/
|
||||||
|
HUANAN("huanan"),
|
||||||
|
/**
|
||||||
|
* 北美区域
|
||||||
|
*/
|
||||||
|
BEIMEI("beimei"),
|
||||||
|
/**
|
||||||
|
* 新加坡区域
|
||||||
|
*/
|
||||||
|
XINJIAPO("xinjiapo"),
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
AUTOREGION("autoRegion");
|
||||||
|
|
||||||
|
private final String region;
|
||||||
|
|
||||||
|
QiNiuRegion(String region) {
|
||||||
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRegion() {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region buildRegion() {
|
||||||
|
Method method = ReflectUtil.getMethodByName(Region.class, this.region);
|
||||||
|
return ReflectUtil.invokeStatic(method);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,88 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qiniu.model;
|
||||||
|
|
||||||
|
import com.qiniu.common.Constants;
|
||||||
|
import com.qiniu.storage.Configuration;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.core.qiniu.constant.QiNiuRegion;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class QiNiuOssClientConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用的Region
|
||||||
|
*/
|
||||||
|
public QiNiuRegion region = QiNiuRegion.AUTOREGION;
|
||||||
|
/**
|
||||||
|
* 空间相关上传管理操作是否使用 https , 默认 是
|
||||||
|
*/
|
||||||
|
public boolean useHttpsDomains = true;
|
||||||
|
/**
|
||||||
|
* 空间相关上传管理操作是否使用代理加速上传,默认 是
|
||||||
|
*/
|
||||||
|
public boolean accUpHostFirst = true;
|
||||||
|
/**
|
||||||
|
* 使用 AutoRegion 时,如果从区域信息得到上传 host 失败,使用默认的上传域名上传,默认 是
|
||||||
|
* upload.qiniup.com, upload-z1.qiniup.com, upload-z2.qiniup.com,
|
||||||
|
* upload-na0.qiniup.com, upload-as0.qiniup.com
|
||||||
|
*/
|
||||||
|
public boolean useDefaultUpHostIfNone = true;
|
||||||
|
/**
|
||||||
|
* 如果文件大小大于此值则使用断点上传, 否则使用Form上传
|
||||||
|
*/
|
||||||
|
public int putThreshold = Constants.BLOCK_SIZE;
|
||||||
|
/**
|
||||||
|
* 连接超时时间 单位秒(默认10s)
|
||||||
|
*/
|
||||||
|
public int connectTimeout = Constants.CONNECT_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* 写超时时间 单位秒(默认 0 , 不超时)
|
||||||
|
*/
|
||||||
|
public int writeTimeout = Constants.WRITE_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* 回复超时时间 单位秒(默认30s)
|
||||||
|
*/
|
||||||
|
public int readTimeout = Constants.READ_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* 底层HTTP库所有的并发执行的请求数量
|
||||||
|
*/
|
||||||
|
public int dispatcherMaxRequests = Constants.DISPATCHER_MAX_REQUESTS;
|
||||||
|
/**
|
||||||
|
* 底层HTTP库对每个独立的Host进行并发请求的数量
|
||||||
|
*/
|
||||||
|
public int dispatcherMaxRequestsPerHost = Constants.DISPATCHER_MAX_REQUESTS_PER_HOST;
|
||||||
|
/**
|
||||||
|
* 底层HTTP库中复用连接对象的最大空闲数量
|
||||||
|
*/
|
||||||
|
public int connectionPoolMaxIdleCount = Constants.CONNECTION_POOL_MAX_IDLE_COUNT;
|
||||||
|
/**
|
||||||
|
* 底层HTTP库中复用连接对象的回收周期(单位分钟)
|
||||||
|
*/
|
||||||
|
public int connectionPoolMaxIdleMinutes = Constants.CONNECTION_POOL_MAX_IDLE_MINUTES;
|
||||||
|
/**
|
||||||
|
* 上传失败重试次数
|
||||||
|
*/
|
||||||
|
public int retryMax = 5;
|
||||||
|
|
||||||
|
public Configuration toClientConfig() {
|
||||||
|
Configuration configuration = new Configuration();
|
||||||
|
configuration.region = this.region.buildRegion();
|
||||||
|
configuration.useHttpsDomains = useHttpsDomains;
|
||||||
|
configuration.accUpHostFirst = accUpHostFirst;
|
||||||
|
configuration.useDefaultUpHostIfNone = useDefaultUpHostIfNone;
|
||||||
|
configuration.putThreshold = putThreshold;
|
||||||
|
configuration.connectTimeout = connectTimeout;
|
||||||
|
configuration.writeTimeout = writeTimeout;
|
||||||
|
configuration.readTimeout = readTimeout;
|
||||||
|
configuration.dispatcherMaxRequests = dispatcherMaxRequests;
|
||||||
|
configuration.dispatcherMaxRequestsPerHost = dispatcherMaxRequestsPerHost;
|
||||||
|
configuration.connectionPoolMaxIdleCount = connectionPoolMaxIdleCount;
|
||||||
|
configuration.connectionPoolMaxIdleMinutes = connectionPoolMaxIdleMinutes;
|
||||||
|
configuration.retryMax = retryMax;
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,26 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.qiniu.model;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QiNiuOssConfig {
|
||||||
|
|
||||||
|
private String basePath;
|
||||||
|
private String accessKey;
|
||||||
|
private String secretKey;
|
||||||
|
private String bucketName;
|
||||||
|
private QiNiuOssClientConfig clientConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断点续传参数
|
||||||
|
*/
|
||||||
|
private SliceConfig sliceConfig = new SliceConfig();
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
this.sliceConfig.init();
|
||||||
|
basePath = OssPathUtil.valid(basePath);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,295 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.tencent;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.io.file.FileNameUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.qcloud.cos.COSClient;
|
||||||
|
import com.qcloud.cos.model.*;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.tencent.model.TencentOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.model.DirectoryOssInfo;
|
||||||
|
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.model.download.DownloadCheckPoint;
|
||||||
|
import com.schisandra.oss.application.oss.model.download.DownloadObjectStat;
|
||||||
|
import com.schisandra.oss.application.oss.model.upload.*;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class TencentOssClient implements StandardOssClient {
|
||||||
|
|
||||||
|
public static final String COS_OBJECT_NAME = "cosClient";
|
||||||
|
|
||||||
|
private COSClient cosClient;
|
||||||
|
private TencentOssConfig tencentOssConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||||
|
String bucketName = getBucket();
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
if (isOverride || !cosClient.doesObjectExist(bucketName, key)) {
|
||||||
|
cosClient.putObject(bucketName, key, is, new ObjectMetadata());
|
||||||
|
}
|
||||||
|
return getInfo(targetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoadCheckPoint(File file, String targetName) {
|
||||||
|
uploadFile(file, targetName, tencentOssConfig.getSliceConfig(), OssConstant.OssType.TENCENT);
|
||||||
|
return getInfo(targetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeUpload(UpLoadCheckPoint upLoadCheckPoint, List<UpLoadPartEntityTag> partEntityTags) {
|
||||||
|
List<PartETag> eTags = partEntityTags.stream().sorted(Comparator.comparingInt(UpLoadPartEntityTag::getPartNumber))
|
||||||
|
.map(partEntityTag -> new PartETag(partEntityTag.getPartNumber(), partEntityTag.getETag())).collect(Collectors.toList());
|
||||||
|
|
||||||
|
CompleteMultipartUploadRequest completeMultipartUploadRequest =
|
||||||
|
new CompleteMultipartUploadRequest(upLoadCheckPoint.getBucket(), upLoadCheckPoint.getKey(), upLoadCheckPoint.getUploadId(), eTags);
|
||||||
|
cosClient.completeMultipartUpload(completeMultipartUploadRequest);
|
||||||
|
|
||||||
|
FileUtil.del(upLoadCheckPoint.getCheckpointFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareUpload(UpLoadCheckPoint uploadCheckPoint, File upLoadFile, String targetName, String checkpointFile, SliceConfig slice) {
|
||||||
|
String bucket = getBucket();
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
uploadCheckPoint.setMagic(UpLoadCheckPoint.UPLOAD_MAGIC);
|
||||||
|
uploadCheckPoint.setUploadFile(upLoadFile.getPath());
|
||||||
|
uploadCheckPoint.setKey(key);
|
||||||
|
uploadCheckPoint.setBucket(bucket);
|
||||||
|
uploadCheckPoint.setCheckpointFile(checkpointFile);
|
||||||
|
uploadCheckPoint.setUploadFileStat(UpLoadFileStat.getFileStat(uploadCheckPoint.getUploadFile()));
|
||||||
|
|
||||||
|
long partSize = slice.getPartSize();
|
||||||
|
long fileLength = upLoadFile.length();
|
||||||
|
int parts = (int) (fileLength / partSize);
|
||||||
|
if (fileLength % partSize > 0) {
|
||||||
|
parts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadCheckPoint.setUploadParts(splitUploadFile(uploadCheckPoint.getUploadFileStat().getSize(), partSize));
|
||||||
|
uploadCheckPoint.setPartEntityTags(new ArrayList<>());
|
||||||
|
uploadCheckPoint.setOriginPartSize(parts);
|
||||||
|
|
||||||
|
InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucket, key);
|
||||||
|
InitiateMultipartUploadResult result = cosClient.initiateMultipartUpload(request);
|
||||||
|
|
||||||
|
uploadCheckPoint.setUploadId(result.getUploadId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UpLoadPartResult uploadPart(UpLoadCheckPoint upLoadCheckPoint, int partNum, InputStream inputStream) {
|
||||||
|
UpLoadPartResult partResult = null;
|
||||||
|
UploadPart uploadPart = upLoadCheckPoint.getUploadParts().get(partNum);
|
||||||
|
long partSize = uploadPart.getSize();
|
||||||
|
partResult = new UpLoadPartResult(partNum + 1, uploadPart.getOffset(), partSize);
|
||||||
|
try {
|
||||||
|
inputStream.skip(uploadPart.getOffset());
|
||||||
|
|
||||||
|
UploadPartRequest uploadPartRequest = new UploadPartRequest();
|
||||||
|
uploadPartRequest.setBucketName(upLoadCheckPoint.getBucket());
|
||||||
|
uploadPartRequest.setKey(upLoadCheckPoint.getKey());
|
||||||
|
uploadPartRequest.setUploadId(upLoadCheckPoint.getUploadId());
|
||||||
|
uploadPartRequest.setInputStream(inputStream);
|
||||||
|
uploadPartRequest.setPartSize(partSize);
|
||||||
|
uploadPartRequest.setPartNumber(uploadPart.getNumber());
|
||||||
|
|
||||||
|
UploadPartResult uploadPartResponse = cosClient.uploadPart(uploadPartRequest);
|
||||||
|
|
||||||
|
partResult.setNumber(uploadPartResponse.getPartNumber());
|
||||||
|
partResult.setEntityTag(new UpLoadPartEntityTag().setETag(uploadPartResponse.getETag())
|
||||||
|
.setPartNumber(uploadPartResponse.getPartNumber()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
partResult.setFailed(true);
|
||||||
|
partResult.setException(e);
|
||||||
|
} finally {
|
||||||
|
IoUtil.close(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return partResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoad(OutputStream os, String targetName) {
|
||||||
|
COSObject cosObject = cosClient.getObject(getBucket(), getKey(targetName, false));
|
||||||
|
IoUtil.copy(cosObject.getObjectContent(), os);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoadCheckPoint(File localFile, String targetName) {
|
||||||
|
downLoadFile(localFile, targetName, tencentOssConfig.getSliceConfig(), OssConstant.OssType.TENCENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DownloadObjectStat getDownloadObjectStat(String targetName) {
|
||||||
|
ObjectMetadata objectMetadata = cosClient.getObjectMetadata(getBucket(), getKey(targetName, false));
|
||||||
|
DateTime date = DateUtil.date(objectMetadata.getLastModified());
|
||||||
|
long contentLength = objectMetadata.getContentLength();
|
||||||
|
String eTag = objectMetadata.getETag();
|
||||||
|
return new DownloadObjectStat().setSize(contentLength).setLastModified(date).setDigest(eTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareDownload(DownloadCheckPoint downloadCheckPoint, File localFile, String targetName, String checkpointFile) {
|
||||||
|
downloadCheckPoint.setMagic(DownloadCheckPoint.DOWNLOAD_MAGIC);
|
||||||
|
downloadCheckPoint.setDownloadFile(localFile.getPath());
|
||||||
|
downloadCheckPoint.setBucketName(getBucket());
|
||||||
|
downloadCheckPoint.setKey(getKey(targetName, false));
|
||||||
|
downloadCheckPoint.setCheckPointFile(checkpointFile);
|
||||||
|
|
||||||
|
downloadCheckPoint.setObjectStat(getDownloadObjectStat(targetName));
|
||||||
|
|
||||||
|
long downloadSize;
|
||||||
|
if (downloadCheckPoint.getObjectStat().getSize() > 0) {
|
||||||
|
Long partSize = tencentOssConfig.getSliceConfig().getPartSize();
|
||||||
|
long[] slice = getDownloadSlice(new long[0], downloadCheckPoint.getObjectStat().getSize());
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadFile(slice[0], slice[1], partSize));
|
||||||
|
downloadSize = slice[1];
|
||||||
|
} else {
|
||||||
|
//download whole file
|
||||||
|
downloadSize = 0;
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadOneFile());
|
||||||
|
}
|
||||||
|
downloadCheckPoint.setOriginPartSize(downloadCheckPoint.getDownloadParts().size());
|
||||||
|
createDownloadTemp(downloadCheckPoint.getTempDownloadFile(), downloadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream downloadPart(String key, long start, long end) {
|
||||||
|
GetObjectRequest request = new GetObjectRequest(getBucket(), key);
|
||||||
|
request.setRange(start, end);
|
||||||
|
COSObject object = cosClient.getObject(request);
|
||||||
|
return object.getObjectContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String targetName) {
|
||||||
|
cosClient.deleteObject(getBucket(), getKey(targetName, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
String bucketName = getBucket();
|
||||||
|
String targetKey = getKey(targetName, false);
|
||||||
|
if (isOverride || !cosClient.doesObjectExist(bucketName, targetKey)) {
|
||||||
|
cosClient.copyObject(getBucket(), getKey(sourceName, false), getBucket(), targetKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
OssInfo ossInfo = getBaseInfo(key);
|
||||||
|
ossInfo.setName(StrUtil.equals(targetName, StrUtil.SLASH) ? targetName : FileNameUtil.getName(targetName));
|
||||||
|
ossInfo.setPath(OssPathUtil.replaceKey(targetName, ossInfo.getName(), true));
|
||||||
|
|
||||||
|
if (isRecursion && isDirectory(key)) {
|
||||||
|
String prefix = OssPathUtil.convertPath(key, false);
|
||||||
|
ObjectListing listObjects = cosClient.listObjects(getBucket(), prefix.endsWith(StrUtil.SLASH) ? prefix : prefix + StrUtil.SLASH);
|
||||||
|
|
||||||
|
List<OssInfo> fileOssInfos = new ArrayList<>();
|
||||||
|
List<OssInfo> directoryInfos = new ArrayList<>();
|
||||||
|
for (COSObjectSummary cosObjectSummary : listObjects.getObjectSummaries()) {
|
||||||
|
if (FileNameUtil.getName(cosObjectSummary.getKey()).equals(FileNameUtil.getName(key))) {
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.date(cosObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setCreateTime(DateUtil.date(cosObjectSummary.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLength(Convert.toStr(cosObjectSummary.getSize()));
|
||||||
|
} else {
|
||||||
|
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(cosObjectSummary.getKey(), getBasePath(), false), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String commonPrefix : listObjects.getCommonPrefixes()) {
|
||||||
|
String target = OssPathUtil.replaceKey(commonPrefix, getBasePath(), false);
|
||||||
|
if (isDirectory(commonPrefix)) {
|
||||||
|
directoryInfos.add(getInfo(target, true));
|
||||||
|
} else {
|
||||||
|
fileOssInfos.add(getInfo(target, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(directoryInfos) && directoryInfos.get(0) instanceof DirectoryOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean isExist(String targetName) {
|
||||||
|
return cosClient.doesObjectExist(getBucket(), getKey(targetName, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBasePath() {
|
||||||
|
return tencentOssConfig.getBasePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getClientObject() {
|
||||||
|
return new HashMap<String, Object>() {
|
||||||
|
{
|
||||||
|
put(COS_OBJECT_NAME, getCosClient());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getBucket() {
|
||||||
|
String bucketName = tencentOssConfig.getBucketName();
|
||||||
|
if (!cosClient.doesBucketExist(bucketName)) {
|
||||||
|
cosClient.createBucket(bucketName);
|
||||||
|
}
|
||||||
|
return bucketName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OssInfo getBaseInfo(String key) {
|
||||||
|
OssInfo ossInfo;
|
||||||
|
|
||||||
|
if (isFile(key)) {
|
||||||
|
ossInfo = new FileOssInfo();
|
||||||
|
try {
|
||||||
|
ObjectMetadata objectMetadata = cosClient.getObjectMetadata(getBucket(), key);
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setCreateTime(DateUtil.date(objectMetadata.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLength(Convert.toStr(objectMetadata.getContentLength()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取{}文件属性失败", key, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ossInfo = new DirectoryOssInfo();
|
||||||
|
}
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,71 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.tencent;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.qcloud.cos.COSClient;
|
||||||
|
import com.qcloud.cos.ClientConfig;
|
||||||
|
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||||
|
import com.qcloud.cos.auth.COSCredentials;
|
||||||
|
import com.schisandra.oss.application.convert.SchisandraOssTencentDTOConverter;
|
||||||
|
import com.schisandra.oss.application.dto.SchisandraOssTencentDTO;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.tencent.model.TencentOssClientConfig;
|
||||||
|
import com.schisandra.oss.application.oss.core.tencent.model.TencentOssConfig;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
|
||||||
|
import com.schisandra.oss.domain.service.SchisandraOssTencentDomainService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zlg
|
||||||
|
* @description:腾讯云对象存储配置
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @date: 2024/6/25 14:03
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class TencentOssConfiguration {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraOssTencentDomainService schisandraOssTencentDomainService;
|
||||||
|
|
||||||
|
|
||||||
|
public StandardOssClient tencentOssClient(String userId) {
|
||||||
|
SchisandraOssTencentBO schisandraOssTencentBO = schisandraOssTencentDomainService.getTencentOssConfig(userId);
|
||||||
|
SchisandraOssTencentDTO schisandraOssTencentDTO = SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTO(schisandraOssTencentBO);
|
||||||
|
if (ObjectUtil.isEmpty(schisandraOssTencentDTO)) {
|
||||||
|
log.error("Tencent oss配置信息获取失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String secretId = schisandraOssTencentDTO.getSecretId();
|
||||||
|
String secretKey = schisandraOssTencentDTO.getSecretKey();
|
||||||
|
TencentOssConfig tencentOssConfig = new TencentOssConfig();
|
||||||
|
tencentOssConfig.setSecretId(secretId);
|
||||||
|
tencentOssConfig.setSecretKey(secretKey);
|
||||||
|
return tencentOssClient(tencentOssConfig);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private StandardOssClient tencentOssClient(TencentOssConfig tencentOssConfig) {
|
||||||
|
TencentOssClientConfig clientConfig = Optional.ofNullable(tencentOssConfig.getClientConfig()).orElse(new TencentOssClientConfig());
|
||||||
|
COSCredentials cosCredentials = cosCredentials(tencentOssConfig);
|
||||||
|
COSClient cosClient = cosClient(cosCredentials, clientConfig.toClientConfig());
|
||||||
|
return tencentOssClient(cosClient, tencentOssConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StandardOssClient tencentOssClient(COSClient cosClient, TencentOssConfig tencentOssConfig) {
|
||||||
|
return new TencentOssClient(cosClient, tencentOssConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public COSCredentials cosCredentials(TencentOssConfig tencentOssConfig) {
|
||||||
|
return new BasicCOSCredentials(tencentOssConfig.getSecretId(), tencentOssConfig.getSecretKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public COSClient cosClient(COSCredentials cred, ClientConfig clientConfig) {
|
||||||
|
return new COSClient(cred, clientConfig);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,50 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.tencent.constant;
|
||||||
|
|
||||||
|
import com.qcloud.cos.utils.VersionInfoUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 腾讯云OSS常量类
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:03
|
||||||
|
*/
|
||||||
|
public class TencentOssConstant {
|
||||||
|
/**
|
||||||
|
* 默认的获取连接的超时时间, 单位ms
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = -1;
|
||||||
|
/**
|
||||||
|
* 默认连接超时, 单位ms
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_CONNECTION_TIMEOUT = 30 * 1000;
|
||||||
|
/**
|
||||||
|
* 默认的SOCKET读取超时时间, 单位ms
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_SOCKET_TIMEOUT = 30 * 1000;
|
||||||
|
/**
|
||||||
|
* 默认的维护最大HTTP连接数
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_MAX_CONNECTIONS_COUNT = 1024;
|
||||||
|
/**
|
||||||
|
* 空闲连接最长存活时间
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_IDLE_CONNECTION_ALIVE = 60 * 1000;
|
||||||
|
/**
|
||||||
|
* 多次签名的默认过期时间,单位秒
|
||||||
|
*/
|
||||||
|
public static final long DEFAULT_SIGN_EXPIRED = 3600;
|
||||||
|
/**
|
||||||
|
* 默认的user_agent标识
|
||||||
|
*/
|
||||||
|
public static final String DEFAULT_USER_AGENT = VersionInfoUtils.getUserAgent();
|
||||||
|
/**
|
||||||
|
* Read Limit
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_READ_LIMIT = (2 << 17) + 1;
|
||||||
|
/**
|
||||||
|
* 发生异常时的最大重试次数
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_RETRY_TIMES = 3;
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,99 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.tencent.model;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.qcloud.cos.ClientConfig;
|
||||||
|
import com.qcloud.cos.http.HttpProtocol;
|
||||||
|
import com.qcloud.cos.region.Region;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import static com.schisandra.oss.application.oss.core.tencent.constant.TencentOssConstant.*;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class TencentOssClientConfig {
|
||||||
|
/**
|
||||||
|
* 地域
|
||||||
|
*/
|
||||||
|
private String region;
|
||||||
|
/**
|
||||||
|
* 连接OSS所采用的协议(HTTP或HTTPS),默认为HTTPS。
|
||||||
|
*/
|
||||||
|
private HttpProtocol httpProtocol = HttpProtocol.https;
|
||||||
|
/**
|
||||||
|
* 域名后缀
|
||||||
|
*/
|
||||||
|
private String endPointSuffix = null;
|
||||||
|
/**
|
||||||
|
* http proxy代理,如果使用http proxy代理,需要设置IP与端口
|
||||||
|
*/
|
||||||
|
private String httpProxyIp = null;
|
||||||
|
/**
|
||||||
|
* 代理服务器端口
|
||||||
|
*/
|
||||||
|
private int httpProxyPort = 0;
|
||||||
|
/**
|
||||||
|
* 代理服务器验证的用户名。
|
||||||
|
*/
|
||||||
|
private String proxyUsername = null;
|
||||||
|
/**
|
||||||
|
* 代理服务器验证的密码。
|
||||||
|
*/
|
||||||
|
private String proxyPassword = null;
|
||||||
|
/**
|
||||||
|
* 是否使用基本身份验证
|
||||||
|
*/
|
||||||
|
private boolean useBasicAuth = false;
|
||||||
|
/**
|
||||||
|
* 多次签名的过期时间,单位秒
|
||||||
|
*/
|
||||||
|
private long signExpired = DEFAULT_SIGN_EXPIRED;
|
||||||
|
/**
|
||||||
|
* 获取连接的超时时间, 单位ms
|
||||||
|
*/
|
||||||
|
private int connectionRequestTimeout = DEFAULT_CONNECTION_REQUEST_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* 默认连接超时, 单位ms
|
||||||
|
*/
|
||||||
|
private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* SOCKET读取超时时间, 单位ms
|
||||||
|
*/
|
||||||
|
private int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* 最大HTTP连接数
|
||||||
|
*/
|
||||||
|
private int maxConnectionsCount = DEFAULT_MAX_CONNECTIONS_COUNT;
|
||||||
|
/**
|
||||||
|
* 空闲连接存活时间
|
||||||
|
*/
|
||||||
|
private int idleConnectionAlive = DEFAULT_IDLE_CONNECTION_ALIVE;
|
||||||
|
/**
|
||||||
|
* user_agent标识
|
||||||
|
*/
|
||||||
|
private String userAgent = DEFAULT_USER_AGENT;
|
||||||
|
/**
|
||||||
|
* 读取限制
|
||||||
|
*/
|
||||||
|
private int readLimit = DEFAULT_READ_LIMIT;
|
||||||
|
/**
|
||||||
|
* 数据万象特殊请求配置
|
||||||
|
*/
|
||||||
|
private boolean ciSpecialRequest = false;
|
||||||
|
/**
|
||||||
|
* 请求失败后最大的重试次数。默认3次。
|
||||||
|
**/
|
||||||
|
private int maxErrorRetry = DEFAULT_RETRY_TIMES;
|
||||||
|
|
||||||
|
public ClientConfig toClientConfig() {
|
||||||
|
ClientConfig clientConfig = new ClientConfig();
|
||||||
|
BeanUtil.copyProperties(this, clientConfig, new CopyOptions().setIgnoreNullValue(true).setIgnoreProperties("region"));
|
||||||
|
if (ObjectUtil.isNotEmpty(region)) {
|
||||||
|
clientConfig.setRegion(new Region(region));
|
||||||
|
}
|
||||||
|
return clientConfig;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.tencent.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TencentOssConfig {
|
||||||
|
|
||||||
|
private String basePath;
|
||||||
|
private String bucketName;
|
||||||
|
private String secretId;
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
private TencentOssClientConfig clientConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断点续传参数
|
||||||
|
*/
|
||||||
|
private SliceConfig sliceConfig = new SliceConfig();
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
this.sliceConfig.init();
|
||||||
|
basePath = OssPathUtil.valid(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,343 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.ucloud;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.io.file.FileNameUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.ucloud.ufile.UfileClient;
|
||||||
|
import cn.ucloud.ufile.api.object.ObjectApiBuilder;
|
||||||
|
import cn.ucloud.ufile.api.object.multi.MultiUploadInfo;
|
||||||
|
import cn.ucloud.ufile.api.object.multi.MultiUploadPartState;
|
||||||
|
import cn.ucloud.ufile.bean.DownloadFileBean;
|
||||||
|
import cn.ucloud.ufile.bean.ObjectInfoBean;
|
||||||
|
import cn.ucloud.ufile.bean.ObjectListBean;
|
||||||
|
import cn.ucloud.ufile.bean.ObjectProfile;
|
||||||
|
import cn.ucloud.ufile.exception.UfileClientException;
|
||||||
|
import cn.ucloud.ufile.util.StorageType;
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.ucloud.model.UCloudOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.exception.OssException;
|
||||||
|
import com.schisandra.oss.application.oss.model.DirectoryOssInfo;
|
||||||
|
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.model.download.DownloadCheckPoint;
|
||||||
|
import com.schisandra.oss.application.oss.model.download.DownloadObjectStat;
|
||||||
|
import com.schisandra.oss.application.oss.model.upload.*;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:UCloud OSS 客户端
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:20
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UCloudOssClient implements StandardOssClient {
|
||||||
|
|
||||||
|
public static final String OBJECT_OBJECT_NAME = "objectApiBuilder";
|
||||||
|
|
||||||
|
private UfileClient ufileClient;
|
||||||
|
private ObjectApiBuilder objectApiBuilder;
|
||||||
|
private UCloudOssConfig uCloudOssConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||||
|
String bucketName = getBucket();
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
if (isOverride || !isExist(targetName)) {
|
||||||
|
try {
|
||||||
|
objectApiBuilder.putObject(is, 0, "")
|
||||||
|
.nameAs(key)
|
||||||
|
.toBucket(bucketName)
|
||||||
|
.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getInfo(targetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoadCheckPoint(File file, String targetName) {
|
||||||
|
uploadFile(file, targetName, uCloudOssConfig.getSliceConfig(), OssConstant.OssType.UCLOUD);
|
||||||
|
return getInfo(targetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeUpload(UpLoadCheckPoint upLoadCheckPoint, List<UpLoadPartEntityTag> partEntityTags) {
|
||||||
|
List<MultiUploadPartState> partStates = partEntityTags.stream().sorted(Comparator.comparingInt(UpLoadPartEntityTag::getPartNumber))
|
||||||
|
.map(partEntityTag -> {
|
||||||
|
MultiUploadPartState multiUploadPartState = new MultiUploadPartState();
|
||||||
|
// TODO
|
||||||
|
return multiUploadPartState;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
MultiUploadInfo multiUploadInfo = new MultiUploadInfo();
|
||||||
|
objectApiBuilder.finishMultiUpload(multiUploadInfo, partStates);
|
||||||
|
|
||||||
|
FileUtil.del(upLoadCheckPoint.getCheckpointFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareUpload(UpLoadCheckPoint uploadCheckPoint, File upLoadFile, String targetName, String checkpointFile, SliceConfig slice) {
|
||||||
|
String bucket = getBucket();
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
uploadCheckPoint.setMagic(UpLoadCheckPoint.UPLOAD_MAGIC);
|
||||||
|
uploadCheckPoint.setUploadFile(upLoadFile.getPath());
|
||||||
|
uploadCheckPoint.setKey(key);
|
||||||
|
uploadCheckPoint.setBucket(bucket);
|
||||||
|
uploadCheckPoint.setCheckpointFile(checkpointFile);
|
||||||
|
uploadCheckPoint.setUploadFileStat(UpLoadFileStat.getFileStat(uploadCheckPoint.getUploadFile()));
|
||||||
|
|
||||||
|
long partSize = slice.getPartSize();
|
||||||
|
long fileLength = upLoadFile.length();
|
||||||
|
int parts = (int) (fileLength / partSize);
|
||||||
|
if (fileLength % partSize > 0) {
|
||||||
|
parts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadCheckPoint.setUploadParts(splitUploadFile(uploadCheckPoint.getUploadFileStat().getSize(), partSize));
|
||||||
|
uploadCheckPoint.setPartEntityTags(new ArrayList<>());
|
||||||
|
uploadCheckPoint.setOriginPartSize(parts);
|
||||||
|
|
||||||
|
try {
|
||||||
|
MultiUploadInfo multiUploadInfo = objectApiBuilder.initMultiUpload(key, "", bucket).withStorageType(StorageType.STANDARD).execute();
|
||||||
|
uploadCheckPoint.setUploadId(multiUploadInfo.getUploadId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UpLoadPartResult uploadPart(UpLoadCheckPoint upLoadCheckPoint, int partNum, InputStream inputStream) {
|
||||||
|
UploadPart uploadPart = upLoadCheckPoint.getUploadParts().get(partNum);
|
||||||
|
long partSize = uploadPart.getSize();
|
||||||
|
UpLoadPartResult partResult = new UpLoadPartResult(partNum + 1, uploadPart.getOffset(), partSize);
|
||||||
|
try {
|
||||||
|
inputStream.skip(uploadPart.getOffset());
|
||||||
|
|
||||||
|
MultiUploadInfo multiUploadInfo = new MultiUploadInfo();
|
||||||
|
MultiUploadPartState multiUploadPartState = objectApiBuilder.multiUploadPart(multiUploadInfo, null, partNum)
|
||||||
|
.from(null, Convert.toInt(uploadPart.getOffset()), Convert.toInt(partSize), partNum).execute();
|
||||||
|
|
||||||
|
partResult.setNumber(multiUploadPartState.getPartIndex());
|
||||||
|
partResult.setEntityTag(new UpLoadPartEntityTag().setETag(multiUploadPartState.geteTag())
|
||||||
|
.setPartNumber(multiUploadPartState.getPartIndex()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
partResult.setFailed(true);
|
||||||
|
partResult.setException(e);
|
||||||
|
} finally {
|
||||||
|
IoUtil.close(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return partResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoad(OutputStream os, String targetName) {
|
||||||
|
ObjectProfile objectProfile = new ObjectProfile();
|
||||||
|
objectProfile.setBucket(getBucket());
|
||||||
|
objectProfile.setKeyName(getKey(targetName, false));
|
||||||
|
try {
|
||||||
|
DownloadFileBean downloadFileBean = objectApiBuilder.downloadFile(objectProfile).execute();
|
||||||
|
IoUtil.copy(FileUtil.getInputStream(downloadFileBean.getFile()), os);
|
||||||
|
} catch (UfileClientException e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoadCheckPoint(File localFile, String targetName) {
|
||||||
|
downLoadFile(localFile, targetName, uCloudOssConfig.getSliceConfig(), OssConstant.OssType.UCLOUD);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DownloadObjectStat getDownloadObjectStat(String targetName) {
|
||||||
|
try {
|
||||||
|
ObjectProfile objectProfile = objectApiBuilder.objectProfile(getKey(targetName, false), getBucket()).execute();
|
||||||
|
DateTime date = DateUtil.parse(objectProfile.getLastModified());
|
||||||
|
long contentLength = objectProfile.getContentLength();
|
||||||
|
String eTag = objectProfile.geteTag();
|
||||||
|
return new DownloadObjectStat().setSize(contentLength).setLastModified(date).setDigest(eTag);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareDownload(DownloadCheckPoint downloadCheckPoint, File localFile, String targetName, String checkpointFile) {
|
||||||
|
downloadCheckPoint.setMagic(DownloadCheckPoint.DOWNLOAD_MAGIC);
|
||||||
|
downloadCheckPoint.setDownloadFile(localFile.getPath());
|
||||||
|
downloadCheckPoint.setBucketName(getBucket());
|
||||||
|
downloadCheckPoint.setKey(getKey(targetName, false));
|
||||||
|
downloadCheckPoint.setCheckPointFile(checkpointFile);
|
||||||
|
|
||||||
|
downloadCheckPoint.setObjectStat(getDownloadObjectStat(targetName));
|
||||||
|
|
||||||
|
long downloadSize;
|
||||||
|
if (downloadCheckPoint.getObjectStat().getSize() > 0) {
|
||||||
|
Long partSize = uCloudOssConfig.getSliceConfig().getPartSize();
|
||||||
|
long[] slice = getDownloadSlice(new long[0], downloadCheckPoint.getObjectStat().getSize());
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadFile(slice[0], slice[1], partSize));
|
||||||
|
downloadSize = slice[1];
|
||||||
|
} else {
|
||||||
|
//download whole file
|
||||||
|
downloadSize = 0;
|
||||||
|
downloadCheckPoint.setDownloadParts(splitDownloadOneFile());
|
||||||
|
}
|
||||||
|
downloadCheckPoint.setOriginPartSize(downloadCheckPoint.getDownloadParts().size());
|
||||||
|
createDownloadTemp(downloadCheckPoint.getTempDownloadFile(), downloadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream downloadPart(String key, long start, long end) {
|
||||||
|
ObjectProfile objectProfile = new ObjectProfile();
|
||||||
|
objectProfile.setBucket(getBucket());
|
||||||
|
objectProfile.setKeyName(key);
|
||||||
|
try {
|
||||||
|
DownloadFileBean downloadFileBean = objectApiBuilder.downloadFile(objectProfile).withinRange(start, end).execute();
|
||||||
|
return FileUtil.getInputStream(downloadFileBean.getFile());
|
||||||
|
} catch (UfileClientException e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String targetName) {
|
||||||
|
objectApiBuilder.deleteObject(getBucket(), getKey(targetName, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
String bucketName = getBucket();
|
||||||
|
String targetKey = getKey(targetName, false);
|
||||||
|
if (isOverride || !isExist(targetName)) {
|
||||||
|
try {
|
||||||
|
objectApiBuilder.copyObject(bucketName, getKey(sourceName, false)).copyTo(bucketName, targetKey).execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
||||||
|
String key = getKey(targetName, false);
|
||||||
|
|
||||||
|
OssInfo ossInfo = getBaseInfo(key);
|
||||||
|
ossInfo.setName(StrUtil.equals(targetName, StrUtil.SLASH) ? targetName : FileNameUtil.getName(targetName));
|
||||||
|
ossInfo.setPath(OssPathUtil.replaceKey(targetName, ossInfo.getName(), true));
|
||||||
|
|
||||||
|
if (isRecursion && isDirectory(key)) {
|
||||||
|
String prefix = OssPathUtil.convertPath(key, false);
|
||||||
|
ObjectListBean objectListBean;
|
||||||
|
try {
|
||||||
|
objectListBean = objectApiBuilder.objectList(getBucket())
|
||||||
|
.withPrefix(prefix.endsWith(StrUtil.SLASH) ? prefix : prefix + StrUtil.SLASH)
|
||||||
|
.execute();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ObjectInfoBean> objectList = objectListBean.getObjectList();
|
||||||
|
|
||||||
|
List<OssInfo> fileOssInfos = new ArrayList<>();
|
||||||
|
List<OssInfo> directoryInfos = new ArrayList<>();
|
||||||
|
for (ObjectInfoBean objectInfoBean : objectList) {
|
||||||
|
String fileName = objectInfoBean.getFileName();
|
||||||
|
if (FileNameUtil.getName(fileName).equals(FileNameUtil.getName(key))) {
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.date(objectInfoBean.getModifyTime()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setCreateTime(DateUtil.date(objectInfoBean.getCreateTime()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLength(Convert.toStr(objectInfoBean.getSize()));
|
||||||
|
} else if (isDirectory(fileName)) {
|
||||||
|
directoryInfos.add(getInfo(OssPathUtil.replaceKey(fileName, getBasePath(), false), true));
|
||||||
|
} else {
|
||||||
|
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(fileName, getBasePath(), false), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(directoryInfos) && directoryInfos.get(0) instanceof DirectoryOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean isExist(String targetName) {
|
||||||
|
try {
|
||||||
|
ObjectProfile objectProfile = objectApiBuilder.objectProfile(getKey(targetName, false), getBucket()).execute();
|
||||||
|
return objectProfile.getContentLength() > 0;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBasePath() {
|
||||||
|
return uCloudOssConfig.getBasePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getClientObject() {
|
||||||
|
return new HashMap<String, Object>() {
|
||||||
|
{
|
||||||
|
put(OBJECT_OBJECT_NAME, getObjectApiBuilder());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getBucket() {
|
||||||
|
return uCloudOssConfig.getBucketName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OssInfo getBaseInfo(String key) {
|
||||||
|
OssInfo ossInfo;
|
||||||
|
|
||||||
|
if (isFile(key)) {
|
||||||
|
ossInfo = new FileOssInfo();
|
||||||
|
try {
|
||||||
|
ObjectProfile objectProfile = getObjectApiBuilder().objectProfile(OssPathUtil.replaceKey(key, getBasePath(), false), getBucket()).execute();
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.parse(objectProfile.getLastModified()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setCreateTime(DateUtil.parse(objectProfile.getCreateTime()).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLength(Convert.toStr(objectProfile.getContentLength()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取{}文件属性失败", key, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ossInfo = new DirectoryOssInfo();
|
||||||
|
}
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,57 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.ucloud;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.ucloud.ufile.UfileClient;
|
||||||
|
import cn.ucloud.ufile.api.object.ObjectApiBuilder;
|
||||||
|
import cn.ucloud.ufile.api.object.ObjectConfig;
|
||||||
|
import cn.ucloud.ufile.auth.ObjectAuthorization;
|
||||||
|
import cn.ucloud.ufile.auth.UfileObjectLocalAuthorization;
|
||||||
|
import com.schisandra.oss.application.convert.SchisandraOssUcloudDTOConverter;
|
||||||
|
import com.schisandra.oss.application.dto.SchisandraOssUcloudDTO;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.ucloud.model.UCloudOssClientConfig;
|
||||||
|
import com.schisandra.oss.application.oss.core.ucloud.model.UCloudOssConfig;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssUcloudBO;
|
||||||
|
import com.schisandra.oss.domain.service.SchisandraOssUcloudDomainService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class UCloudOssConfiguration {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraOssUcloudDomainService schisandraOssUcloudDomainService;
|
||||||
|
|
||||||
|
public StandardOssClient uCloudOssClient(String userId) {
|
||||||
|
SchisandraOssUcloudBO schisandraOssUcloudBO = schisandraOssUcloudDomainService.getUcloudOssConfig(userId);
|
||||||
|
SchisandraOssUcloudDTO schisandraOssUcloudDTO = SchisandraOssUcloudDTOConverter.INSTANCE.convertBOToDTO(schisandraOssUcloudBO);
|
||||||
|
if (ObjectUtil.isEmpty(schisandraOssUcloudDTO)) {
|
||||||
|
log.error("Ucloud oss配置信息获取失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String publicKey = schisandraOssUcloudDTO.getPublicKey();
|
||||||
|
String privateKey = schisandraOssUcloudDTO.getPrivateKey();
|
||||||
|
String customHost = schisandraOssUcloudDTO.getCustomHost();
|
||||||
|
UCloudOssConfig uCloudOssConfig = new UCloudOssConfig();
|
||||||
|
uCloudOssConfig.setPublicKey(publicKey);
|
||||||
|
uCloudOssConfig.setPrivateKey(privateKey);
|
||||||
|
uCloudOssConfig.setCustomHost(customHost);
|
||||||
|
return uCloudOssClient(uCloudOssConfig);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public StandardOssClient uCloudOssClient(UCloudOssConfig uCloudOssConfig) {
|
||||||
|
UCloudOssClientConfig clientConfig = Optional.ofNullable(uCloudOssConfig.getClientConfig()).orElse(new UCloudOssClientConfig());
|
||||||
|
UfileClient.Config config = new UfileClient.Config(clientConfig.toClientConfig());
|
||||||
|
ObjectAuthorization objectAuthorization = new UfileObjectLocalAuthorization(uCloudOssConfig.getPublicKey(), uCloudOssConfig.getPrivateKey());
|
||||||
|
ObjectConfig objectConfig = new ObjectConfig(uCloudOssConfig.getCustomHost());
|
||||||
|
UfileClient ufileClient = UfileClient.configure(config);
|
||||||
|
ObjectApiBuilder objectApiBuilder = new ObjectApiBuilder(ufileClient, objectAuthorization, objectConfig);
|
||||||
|
return new UCloudOssClient(ufileClient, objectApiBuilder, uCloudOssConfig);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,45 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.ucloud.model;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.ucloud.ufile.http.HttpClient;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static cn.ucloud.ufile.http.HttpClient.Config.*;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UCloudOssClientConfig {
|
||||||
|
/**
|
||||||
|
* 连接超时时间
|
||||||
|
*/
|
||||||
|
private long timeoutConnect = DEFAULT_CONNECT_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* 读超时时间
|
||||||
|
*/
|
||||||
|
private long timeoutRead = DEFAULT_WRITE_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* 写超时时间
|
||||||
|
*/
|
||||||
|
private long timeoutWrite = DEFAULT_READ_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* okhttp最大空闲连接数(5)
|
||||||
|
*/
|
||||||
|
private int maxIdleConnections = DEFAULT_MAX_IDLE_CONNECTIONS;
|
||||||
|
/**
|
||||||
|
* okhttp活动链接存货时间(5分钟)
|
||||||
|
*/
|
||||||
|
private long keepAliveDuration = DEFAULT_KEEP_ALIVE_DURATION_MINUTES;
|
||||||
|
/**
|
||||||
|
* okhttp活动链接存货时间单位, (分钟)
|
||||||
|
*/
|
||||||
|
private TimeUnit keepAliveTimeUnit = DEFAULT_KEEP_ALIVE_DURATION_TIME_UNIT;
|
||||||
|
|
||||||
|
public HttpClient.Config toClientConfig() {
|
||||||
|
HttpClient.Config config = new HttpClient.Config();
|
||||||
|
BeanUtil.copyProperties(this, config);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,30 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.ucloud.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UCloudOssConfig {
|
||||||
|
|
||||||
|
private String basePath;
|
||||||
|
private String bucketName;
|
||||||
|
private String publicKey;
|
||||||
|
private String privateKey;
|
||||||
|
private String customHost;
|
||||||
|
|
||||||
|
private UCloudOssClientConfig clientConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断点续传参数
|
||||||
|
*/
|
||||||
|
private SliceConfig sliceConfig = new SliceConfig();
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
this.sliceConfig.init();
|
||||||
|
basePath = OssPathUtil.valid(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,236 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.up;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.io.LineHandler;
|
||||||
|
import cn.hutool.core.io.file.FileNameUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.up.constant.UpConstant;
|
||||||
|
import com.schisandra.oss.application.oss.core.up.model.UpOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.exception.OssException;
|
||||||
|
import com.schisandra.oss.application.oss.model.DirectoryOssInfo;
|
||||||
|
import com.schisandra.oss.application.oss.model.FileOssInfo;
|
||||||
|
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import com.upyun.ParallelUploader;
|
||||||
|
import com.upyun.RestManager;
|
||||||
|
import com.upyun.UpException;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import okhttp3.Headers;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:40
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UpOssClient implements StandardOssClient {
|
||||||
|
|
||||||
|
public static final String REST_OBJECT_NAME = "restManager";
|
||||||
|
public static final String PARALLEL_OBJECT_NAME = "parallelUploader";
|
||||||
|
|
||||||
|
private RestManager restManager;
|
||||||
|
private ParallelUploader parallelUploader;
|
||||||
|
private UpOssConfig upOssConfig;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||||
|
try {
|
||||||
|
restManager.writeFile(getKey(targetName, true), is, null);
|
||||||
|
} catch (IOException | UpException e) {
|
||||||
|
log.error("{}上传失败", targetName, e);
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
return getInfo(targetName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo upLoadCheckPoint(File file, String targetName) {
|
||||||
|
try {
|
||||||
|
parallelUploader.upload(file.getPath(), getKey(targetName, true), null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
return getInfo(targetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoad(OutputStream os, String targetName) {
|
||||||
|
try {
|
||||||
|
Response response = restManager.readFile(getKey(targetName, true));
|
||||||
|
IoUtil.copy(response.body().byteStream(), os);
|
||||||
|
} catch (IOException | UpException e) {
|
||||||
|
log.error("{}下载失败", targetName, e);
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoadCheckPoint(File localFile, String targetName) {
|
||||||
|
log.warn("又拍云不支持断点续传下载,将使用普通下载");
|
||||||
|
try (OutputStream os = new FileOutputStream(localFile)) {
|
||||||
|
downLoad(os, targetName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("{}下载失败", targetName, e);
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String targetName) {
|
||||||
|
try {
|
||||||
|
restManager.deleteFile(getKey(targetName, true), null);
|
||||||
|
} catch (IOException | UpException e) {
|
||||||
|
log.error("{}删除失败", targetName, e);
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void copy(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
try {
|
||||||
|
restManager.copyFile(getKey(targetName, true), getKey(sourceName, true), null);
|
||||||
|
} catch (IOException | UpException e) {
|
||||||
|
log.error("{}复制到{}失败", sourceName, targetName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void move(String sourceName, String targetName, Boolean isOverride) {
|
||||||
|
String newSourceName = getKey(sourceName, true);
|
||||||
|
String newTargetName = getKey(targetName, true);
|
||||||
|
try {
|
||||||
|
if (isFile(newSourceName)) {
|
||||||
|
restManager.moveFile(targetName, sourceName, null);
|
||||||
|
} else {
|
||||||
|
restManager.mkDir(newTargetName);
|
||||||
|
restManager.rmDir(newSourceName);
|
||||||
|
}
|
||||||
|
} catch (IOException | UpException e) {
|
||||||
|
log.error("{}移动到{}失败", sourceName, targetName, e);
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
||||||
|
String key = getKey(targetName, true);
|
||||||
|
try {
|
||||||
|
OssInfo ossInfo = getBaseInfo(key);
|
||||||
|
ossInfo.setName(StrUtil.equals(targetName, StrUtil.SLASH) ? targetName : FileNameUtil.getName(targetName));
|
||||||
|
ossInfo.setPath(OssPathUtil.replaceKey(targetName, ossInfo.getName(), true));
|
||||||
|
if (isRecursion && isDirectory(key)) {
|
||||||
|
List<OssInfo> fileOssInfos = new ArrayList<>();
|
||||||
|
List<OssInfo> directoryInfos = new ArrayList<>();
|
||||||
|
Response response = restManager.readDirIter(key, null);
|
||||||
|
IoUtil.readUtf8Lines(response.body().byteStream(), (LineHandler) line -> {
|
||||||
|
List<String> fields = StrUtil.split(line, "\t"); // vim.png N 164026 1638536314
|
||||||
|
if (UpConstant.FILE_TYPE.equals(fields.get(1))) {
|
||||||
|
fileOssInfos.add(getInfo(OssPathUtil.replaceKey(key + StrUtil.SLASH + fields.get(0), getBasePath(), true), true));
|
||||||
|
} else {
|
||||||
|
directoryInfos.add(getInfo(OssPathUtil.replaceKey(key + StrUtil.SLASH + fields.get(0), getBasePath(), true), true));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (ObjectUtil.isNotEmpty(fileOssInfos) && fileOssInfos.get(0) instanceof FileOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotEmpty(directoryInfos) && directoryInfos.get(0) instanceof DirectoryOssInfo) {
|
||||||
|
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ossInfo;
|
||||||
|
} catch (IOException | UpException e) {
|
||||||
|
log.error("获取{}基本信息失败", targetName, e);
|
||||||
|
throw new OssException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean isExist(String targetName) {
|
||||||
|
String key = getKey(targetName, true);
|
||||||
|
try {
|
||||||
|
if (isFile(targetName)) {
|
||||||
|
Response response = restManager.getFileInfo(key);
|
||||||
|
String fileSize = response.header(RestManager.PARAMS.X_UPYUN_FILE_SIZE.getValue(), "0");
|
||||||
|
return Convert.toInt(fileSize) > 0;
|
||||||
|
} else {
|
||||||
|
DirectoryOssInfo ossInfo = getDirectoryOssInfo(key);
|
||||||
|
return Convert.toInt(ossInfo.getLength()) > 0;
|
||||||
|
}
|
||||||
|
} catch (IOException | UpException e) {
|
||||||
|
log.error("判断{}是否存在失败", targetName, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBasePath() {
|
||||||
|
return upOssConfig.getBasePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getClientObject() {
|
||||||
|
return new HashMap<String, Object>() {
|
||||||
|
{
|
||||||
|
put(REST_OBJECT_NAME, getRestManager());
|
||||||
|
put(PARALLEL_OBJECT_NAME, getParallelUploader());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private OssInfo getBaseInfo(String key) throws UpException, IOException {
|
||||||
|
OssInfo ossInfo;
|
||||||
|
if (isFile(key)) {
|
||||||
|
ossInfo = new FileOssInfo();
|
||||||
|
Response fileInfo = restManager.getFileInfo(key);
|
||||||
|
Headers headers = fileInfo.headers();
|
||||||
|
ossInfo.setLength(headers.get(RestManager.PARAMS.X_UPYUN_FILE_SIZE.getValue()));
|
||||||
|
ossInfo.setCreateTime(DateUtil.date(headers.getDate(RestManager.PARAMS.X_UPYUN_FILE_DATE.getValue())).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.date(headers.getDate(RestManager.PARAMS.X_UPYUN_FILE_DATE.getValue())).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
} else {
|
||||||
|
ossInfo = getDirectoryOssInfo(key);
|
||||||
|
}
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DirectoryOssInfo getDirectoryOssInfo(String key) throws UpException, IOException {
|
||||||
|
String name = FileNameUtil.getName(key);
|
||||||
|
String newKey = OssPathUtil.replaceKey(key, name, true);
|
||||||
|
|
||||||
|
Response response = restManager.readDirIter(newKey, null);
|
||||||
|
|
||||||
|
DirectoryOssInfo ossInfo = new DirectoryOssInfo();
|
||||||
|
IoUtil.readUtf8Lines(response.body().byteStream(), (LineHandler) line -> {
|
||||||
|
List<String> fields = StrUtil.split(line, "\t"); // test Y 164026 1638536314
|
||||||
|
if (name.equals(fields.get(0))) {
|
||||||
|
ossInfo.setName(fields.get(0));
|
||||||
|
ossInfo.setPath(OssPathUtil.replaceKey(newKey, getBasePath(), true));
|
||||||
|
ossInfo.setLength(fields.get(2));
|
||||||
|
ossInfo.setCreateTime(DateUtil.date(Convert.toLong(fields.get(3)) * 1000).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
ossInfo.setLastUpdateTime(DateUtil.date(Convert.toLong(fields.get(3)) * 1000).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ossInfo;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,98 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.up;
|
||||||
|
|
||||||
|
import cn.hutool.core.text.CharPool;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import com.schisandra.oss.application.convert.SchisandraOssUcloudDTOConverter;
|
||||||
|
import com.schisandra.oss.application.convert.SchisandraOssUpDTOConverter;
|
||||||
|
import com.schisandra.oss.application.dto.SchisandraOssUcloudDTO;
|
||||||
|
import com.schisandra.oss.application.dto.SchisandraOssUpDTO;
|
||||||
|
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||||
|
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||||
|
import com.schisandra.oss.application.oss.core.up.model.UpOssClientConfig;
|
||||||
|
import com.schisandra.oss.application.oss.core.up.model.UpOssConfig;
|
||||||
|
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssUcloudBO;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssUpBO;
|
||||||
|
import com.schisandra.oss.domain.service.SchisandraOssUcloudDomainService;
|
||||||
|
import com.schisandra.oss.domain.service.SchisandraOssUpDomainService;
|
||||||
|
import com.upyun.ParallelUploader;
|
||||||
|
import com.upyun.RestManager;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.SpringBootConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:41
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class UpOssConfiguration {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SchisandraOssUpDomainService schisandraOssUpDomainService;
|
||||||
|
|
||||||
|
|
||||||
|
public StandardOssClient upOssClient(String userId) {
|
||||||
|
SchisandraOssUpBO schisandraOssUpBO = schisandraOssUpDomainService.getUpOssConfig(userId);
|
||||||
|
SchisandraOssUpDTO schisandraOssUpDTO = SchisandraOssUpDTOConverter.INSTANCE.convertBOToDTO(schisandraOssUpBO);
|
||||||
|
if (ObjectUtil.isEmpty(schisandraOssUpDTO)) {
|
||||||
|
log.error("Up oss配置信息获取失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String userName = schisandraOssUpDTO.getUserName();
|
||||||
|
String password = schisandraOssUpDTO.getPassword();
|
||||||
|
UpOssConfig upOssConfig = new UpOssConfig();
|
||||||
|
upOssConfig.setUserName(userName);
|
||||||
|
upOssConfig.setPassword(password);
|
||||||
|
return upOssClient(upOssConfig);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private StandardOssClient upOssClient(UpOssConfig upOssConfig) {
|
||||||
|
RestManager restManager = restManager(upOssConfig);
|
||||||
|
ParallelUploader parallelUploader = parallelUploader(upOssConfig);
|
||||||
|
return upOssClient(restManager, parallelUploader, upOssConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StandardOssClient upOssClient(RestManager restManager, ParallelUploader parallelUploader, UpOssConfig upOssConfig) {
|
||||||
|
return new UpOssClient(restManager, parallelUploader, upOssConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RestManager restManager(UpOssConfig upOssConfig) {
|
||||||
|
RestManager restManager = new RestManager(upOssConfig.getBucketName(), upOssConfig.getUserName(), upOssConfig.getPassword());
|
||||||
|
UpOssClientConfig clientConfig = Optional.ofNullable(upOssConfig.getClientConfig()).orElse(new UpOssClientConfig());
|
||||||
|
// 手动设置超时时间:默认为30秒
|
||||||
|
restManager.setTimeout(clientConfig.getTimeout());
|
||||||
|
// 选择最优的接入点
|
||||||
|
restManager.setApiDomain(clientConfig.getApiDomain().toString());
|
||||||
|
return restManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParallelUploader parallelUploader(UpOssConfig upOssConfig) {
|
||||||
|
ParallelUploader parallelUploader = new ParallelUploader(upOssConfig.getBucketName(), upOssConfig.getUserName(), upOssConfig.getPassword());
|
||||||
|
|
||||||
|
SliceConfig sliceConfig = upOssConfig.getSliceConfig();
|
||||||
|
parallelUploader.setParallel(sliceConfig.getTaskNum());
|
||||||
|
parallelUploader.setCheckMD5(true);
|
||||||
|
UpOssClientConfig clientConfig = Optional.ofNullable(upOssConfig.getClientConfig()).orElse(new UpOssClientConfig());
|
||||||
|
parallelUploader.setTimeout(clientConfig.getTimeout());
|
||||||
|
return parallelUploader;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,44 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.up.constant;
|
||||||
|
|
||||||
|
import com.upyun.RestManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:API域名
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:39
|
||||||
|
*/
|
||||||
|
public enum ApiDomain {
|
||||||
|
/**
|
||||||
|
* 根据网络条件自动选择接入点:v0.api.upyun.com
|
||||||
|
*/
|
||||||
|
ED_AUTO(RestManager.ED_AUTO),
|
||||||
|
/**
|
||||||
|
* 电信接入点:v1.api.upyun.com
|
||||||
|
*/
|
||||||
|
ED_TELECOM(RestManager.ED_TELECOM),
|
||||||
|
/**
|
||||||
|
* 联通网通接入点:v2.api.upyun.com
|
||||||
|
*/
|
||||||
|
ED_CNC(RestManager.ED_CNC),
|
||||||
|
/**
|
||||||
|
* 移动铁通接入点:v3.api.upyun.com
|
||||||
|
*/
|
||||||
|
ED_CTT(RestManager.ED_CTT);
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
ApiDomain(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.up.constant;
|
||||||
|
|
||||||
|
public class UpConstant {
|
||||||
|
public static final String FILE_TYPE = "N";
|
||||||
|
public static final String DIRECTORY_TYPE = "Y";
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.up.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.core.up.constant.ApiDomain;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:上传客户端配置
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:40
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UpOssClientConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认的超时时间:30秒
|
||||||
|
*/
|
||||||
|
private int timeout = 30;
|
||||||
|
/**
|
||||||
|
* 默认为自动识别接入点
|
||||||
|
*/
|
||||||
|
private ApiDomain apiDomain = ApiDomain.ED_AUTO;
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,35 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.up.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.oss.application.oss.model.SliceConfig;
|
||||||
|
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:上传配置
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:40
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UpOssConfig {
|
||||||
|
|
||||||
|
private String basePath;
|
||||||
|
private String bucketName;
|
||||||
|
private String userName;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private UpOssClientConfig clientConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断点续传参数
|
||||||
|
*/
|
||||||
|
private SliceConfig sliceConfig = new SliceConfig();
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
this.sliceConfig.init();
|
||||||
|
basePath = OssPathUtil.valid(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
|||||||
|
/**
|
@@ -0,0 +1,81 @@
|
|||||||
|
package com.schisandra.oss.application.oss.core.wangyi.model;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.netease.cloud.ClientConfiguration;
|
||||||
|
import com.netease.cloud.Protocol;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import static com.netease.cloud.ClientConfiguration.*;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class WangYiOssClientConfig {
|
||||||
|
/**
|
||||||
|
* 连接超时时间
|
||||||
|
*/
|
||||||
|
private int connectionTimeout = 50 * 1000;
|
||||||
|
/**
|
||||||
|
* 最大连接池大小。
|
||||||
|
*/
|
||||||
|
private int maxConnections = DEFAULT_MAX_CONNECTIONS;
|
||||||
|
/**
|
||||||
|
* 最大失败重试次数
|
||||||
|
*/
|
||||||
|
private int maxErrorRetry = DEFAULT_MAX_RETRIES;
|
||||||
|
/**
|
||||||
|
* 是否使用子域名
|
||||||
|
*/
|
||||||
|
private boolean isSubDomain = true;
|
||||||
|
/**
|
||||||
|
* 连接OSS所采用的协议(HTTP或HTTPS),默认为HTTP。
|
||||||
|
*/
|
||||||
|
private Protocol protocol = Protocol.HTTP;
|
||||||
|
/**
|
||||||
|
* 代理服务器的域,该域可以执行NTLM认证
|
||||||
|
*/
|
||||||
|
private String proxyDomain;
|
||||||
|
/**
|
||||||
|
* 代理服务器主机地址
|
||||||
|
*/
|
||||||
|
private String proxyHost;
|
||||||
|
/**
|
||||||
|
* 代理服务器验证的密码
|
||||||
|
*/
|
||||||
|
private String proxyPassword;
|
||||||
|
/**
|
||||||
|
* 代理服务器端口
|
||||||
|
*/
|
||||||
|
private int proxyPort = -1;
|
||||||
|
/**
|
||||||
|
* 代理服务器验证的用户名
|
||||||
|
*/
|
||||||
|
private String proxyUsername;
|
||||||
|
/**
|
||||||
|
* 代理主机的NTLM身份验证服务器
|
||||||
|
*/
|
||||||
|
private String proxyWorkstation;
|
||||||
|
/**
|
||||||
|
* Socket层传输数据的超时时间(单位:毫秒)。默认为50000毫秒。
|
||||||
|
*/
|
||||||
|
private int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
|
||||||
|
/**
|
||||||
|
* 用户代理,指HTTP的User-Agent头
|
||||||
|
*/
|
||||||
|
private String userAgent = DEFAULT_USER_AGENT;
|
||||||
|
/**
|
||||||
|
* Socket接收缓冲区的大小提示(以字节为单位)。
|
||||||
|
*/
|
||||||
|
private int socketReceiveBufferSizeHint = 0;
|
||||||
|
/**
|
||||||
|
* Socket发送缓冲区的大小提示(以字节为单位)。
|
||||||
|
*/
|
||||||
|
private int socketSendBufferSizeHint = 0;
|
||||||
|
|
||||||
|
public ClientConfiguration toClientConfig() {
|
||||||
|
ClientConfiguration clientConfiguration = new ClientConfiguration();
|
||||||
|
BeanUtil.copyProperties(this, clientConfiguration);
|
||||||
|
return clientConfiguration;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1 @@
|
|||||||
|
/**
|
@@ -57,6 +57,8 @@
|
|||||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||||
<version>2.4.2</version>
|
<version>2.4.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
@@ -149,6 +151,65 @@
|
|||||||
<artifactId>aws-java-sdk-s3</artifactId>
|
<artifactId>aws-java-sdk-s3</artifactId>
|
||||||
<version>1.12.167</version>
|
<version>1.12.167</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 金山云 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ksyun</groupId>
|
||||||
|
<artifactId>ks3-kss-java-sdk</artifactId>
|
||||||
|
<version>1.0.2</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 青云 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yunify</groupId>
|
||||||
|
<artifactId>qingstor.sdk.java</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 腾讯云存储 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.qcloud</groupId>
|
||||||
|
<artifactId>cos_api</artifactId>
|
||||||
|
<version>5.6.69</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 七牛云依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.qiniu</groupId>
|
||||||
|
<artifactId>qiniu-java-sdk</artifactId>
|
||||||
|
<version>7.9.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.qiniu</groupId>
|
||||||
|
<artifactId>happy-dns-java</artifactId>
|
||||||
|
<version>0.1.6</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- UCloud -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.ucloud.ufile</groupId>
|
||||||
|
<artifactId>ufile-client-java</artifactId>
|
||||||
|
<version>2.6.6</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 又拍云 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.upyun</groupId>
|
||||||
|
<artifactId>java-sdk</artifactId>
|
||||||
|
<version>4.2.3</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 网易数帆 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.netease.cloud</groupId>
|
||||||
|
<artifactId>nos-sdk-java-publiccloud</artifactId>
|
||||||
|
<version>1.3.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@@ -25,4 +25,13 @@ public interface SchisandraOssJinshanDomainService {
|
|||||||
*/
|
*/
|
||||||
Boolean delete(SchisandraOssJinshanBO schisandraOssJinshanBO);
|
Boolean delete(SchisandraOssJinshanBO schisandraOssJinshanBO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:获取 金山云对象存储配置表 信息
|
||||||
|
* @param: [userId]
|
||||||
|
* @return: com.schisandra.oss.domain.bo.SchisandraOssJinshanBO
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:35
|
||||||
|
*/
|
||||||
|
SchisandraOssJinshanBO getJinshanOssConfig(String userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -24,5 +24,12 @@ public interface SchisandraOssQingyunDomainService {
|
|||||||
* 删除 青云对象存储配置表 信息
|
* 删除 青云对象存储配置表 信息
|
||||||
*/
|
*/
|
||||||
Boolean delete(SchisandraOssQingyunBO schisandraOssQingyunBO);
|
Boolean delete(SchisandraOssQingyunBO schisandraOssQingyunBO);
|
||||||
|
/**
|
||||||
|
* @description: 获取 青云对象存储配置表 信息
|
||||||
|
* @param: [ossConfigId]
|
||||||
|
* @return: com.schisandra.oss.domain.bo.SchisandraOssQingyunBO
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:35
|
||||||
|
*/
|
||||||
|
SchisandraOssQingyunBO getQingyunOssConfig(String ossConfigId);
|
||||||
}
|
}
|
||||||
|
@@ -24,5 +24,12 @@ public interface SchisandraOssQiniuDomainService {
|
|||||||
* 删除 七牛云对象存储配置表 信息
|
* 删除 七牛云对象存储配置表 信息
|
||||||
*/
|
*/
|
||||||
Boolean delete(SchisandraOssQiniuBO schisandraOssQiniuBO);
|
Boolean delete(SchisandraOssQiniuBO schisandraOssQiniuBO);
|
||||||
|
/**
|
||||||
|
* @description: 获取七牛云对象存储配置表信息
|
||||||
|
* @param: [userId]
|
||||||
|
* @return: com.schisandra.oss.domain.bo.SchisandraOssQiniuBO
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:34
|
||||||
|
*/
|
||||||
|
SchisandraOssQiniuBO getQiniuOssConfig(String userId);
|
||||||
}
|
}
|
||||||
|
@@ -24,5 +24,12 @@ public interface SchisandraOssTencentDomainService {
|
|||||||
* 删除 腾讯云对象存储配置表 信息
|
* 删除 腾讯云对象存储配置表 信息
|
||||||
*/
|
*/
|
||||||
Boolean delete(SchisandraOssTencentBO schisandraOssTencentBO);
|
Boolean delete(SchisandraOssTencentBO schisandraOssTencentBO);
|
||||||
|
/**
|
||||||
|
* @description: 获取腾讯云对象存储配置表 信息
|
||||||
|
* @param: [id]
|
||||||
|
* @return: com.schisandra.oss.domain.bo.SchisandraOssTencentBO
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:34
|
||||||
|
*/
|
||||||
|
SchisandraOssTencentBO getTencentOssConfig(String id);
|
||||||
}
|
}
|
||||||
|
@@ -25,4 +25,12 @@ public interface SchisandraOssUcloudDomainService {
|
|||||||
*/
|
*/
|
||||||
Boolean delete(SchisandraOssUcloudBO schisandraOssUcloudBO);
|
Boolean delete(SchisandraOssUcloudBO schisandraOssUcloudBO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取ucloud对象存储配置表信息
|
||||||
|
* @param: [userId]
|
||||||
|
* @return: com.schisandra.oss.domain.bo.SchisandraOssUcloudBO
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:34
|
||||||
|
*/
|
||||||
|
SchisandraOssUcloudBO getUcloudOssConfig(String userId);
|
||||||
}
|
}
|
||||||
|
@@ -25,4 +25,5 @@ public interface SchisandraOssUpDomainService {
|
|||||||
*/
|
*/
|
||||||
Boolean delete(SchisandraOssUpBO schisandraOssUpBO);
|
Boolean delete(SchisandraOssUpBO schisandraOssUpBO);
|
||||||
|
|
||||||
|
SchisandraOssUpBO getUpOssConfig(String userId);
|
||||||
}
|
}
|
||||||
|
@@ -25,4 +25,13 @@ public interface SchisandraOssWangyiDomainService {
|
|||||||
*/
|
*/
|
||||||
Boolean delete(SchisandraOssWangyiBO schisandraOssWangyiBO);
|
Boolean delete(SchisandraOssWangyiBO schisandraOssWangyiBO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:获取网易数帆对象存储配置表 信息
|
||||||
|
* @param: [userId]
|
||||||
|
* @return: com.schisandra.oss.domain.bo.SchisandraOssWangyiBO
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 15:03
|
||||||
|
*/
|
||||||
|
SchisandraOssWangyiBO getWangyiOssConfig(String userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
package com.schisandra.oss.domain.service.impl;
|
package com.schisandra.oss.domain.service.impl;
|
||||||
|
|
||||||
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssJdBO;
|
||||||
|
import com.schisandra.oss.domain.convert.SchisandraOssJdBOConverter;
|
||||||
import com.schisandra.oss.domain.convert.SchisandraOssJinshanBOConverter;
|
import com.schisandra.oss.domain.convert.SchisandraOssJinshanBOConverter;
|
||||||
import com.schisandra.oss.domain.bo.SchisandraOssJinshanBO;
|
import com.schisandra.oss.domain.bo.SchisandraOssJinshanBO;
|
||||||
import com.schisandra.oss.domain.service.SchisandraOssJinshanDomainService;
|
import com.schisandra.oss.domain.service.SchisandraOssJinshanDomainService;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssJd;
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssJinshan;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssJinshan;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssJinshanService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssJinshanService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -45,4 +48,11 @@ public class SchisandraOssJinshanDomainServiceImpl implements SchisandraOssJinsh
|
|||||||
return schisandraOssJinshanService.update(schisandraOssJinshan) > 0;
|
return schisandraOssJinshanService.update(schisandraOssJinshan) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssJinshanBO getJinshanOssConfig(String userId) {
|
||||||
|
SchisandraOssJinshan schisandraOssJinshan = schisandraOssJinshanService.getJinshanOssConfig(userId);
|
||||||
|
SchisandraOssJinshanBO schisandraOssJinshanBO = SchisandraOssJinshanBOConverter.INSTANCE.convertEntityToBO(schisandraOssJinshan);
|
||||||
|
return schisandraOssJinshanBO;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
package com.schisandra.oss.domain.service.impl;
|
package com.schisandra.oss.domain.service.impl;
|
||||||
|
|
||||||
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssJinshanBO;
|
||||||
|
import com.schisandra.oss.domain.convert.SchisandraOssJinshanBOConverter;
|
||||||
import com.schisandra.oss.domain.convert.SchisandraOssQingyunBOConverter;
|
import com.schisandra.oss.domain.convert.SchisandraOssQingyunBOConverter;
|
||||||
import com.schisandra.oss.domain.bo.SchisandraOssQingyunBO;
|
import com.schisandra.oss.domain.bo.SchisandraOssQingyunBO;
|
||||||
import com.schisandra.oss.domain.service.SchisandraOssQingyunDomainService;
|
import com.schisandra.oss.domain.service.SchisandraOssQingyunDomainService;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssJinshan;
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssQingyun;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssQingyun;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssQingyunService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssQingyunService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -45,4 +48,11 @@ public class SchisandraOssQingyunDomainServiceImpl implements SchisandraOssQingy
|
|||||||
return schisandraOssQingyunService.update(schisandraOssQingyun) > 0;
|
return schisandraOssQingyunService.update(schisandraOssQingyun) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssQingyunBO getQingyunOssConfig(String userId) {
|
||||||
|
SchisandraOssQingyun schisandraOssQingyun = schisandraOssQingyunService.getQingyunOssConfig(userId);
|
||||||
|
SchisandraOssQingyunBO schisandraOssQingyunBO = SchisandraOssQingyunBOConverter.INSTANCE.convertEntityToBO(schisandraOssQingyun);
|
||||||
|
return schisandraOssQingyunBO;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
package com.schisandra.oss.domain.service.impl;
|
package com.schisandra.oss.domain.service.impl;
|
||||||
|
|
||||||
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssJdBO;
|
||||||
|
import com.schisandra.oss.domain.convert.SchisandraOssJdBOConverter;
|
||||||
import com.schisandra.oss.domain.convert.SchisandraOssQiniuBOConverter;
|
import com.schisandra.oss.domain.convert.SchisandraOssQiniuBOConverter;
|
||||||
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
|
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
|
||||||
import com.schisandra.oss.domain.service.SchisandraOssQiniuDomainService;
|
import com.schisandra.oss.domain.service.SchisandraOssQiniuDomainService;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssJd;
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssQiniu;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssQiniu;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssQiniuService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssQiniuService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -45,4 +48,11 @@ public class SchisandraOssQiniuDomainServiceImpl implements SchisandraOssQiniuDo
|
|||||||
return schisandraOssQiniuService.update(schisandraOssQiniu) > 0;
|
return schisandraOssQiniuService.update(schisandraOssQiniu) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssQiniuBO getQiniuOssConfig(String userId) {
|
||||||
|
SchisandraOssQiniu schisandraOssQiniu = schisandraOssQiniuService.getQiniuOssConfig(userId);
|
||||||
|
SchisandraOssQiniuBO schisandraOssQiniuBO = SchisandraOssQiniuBOConverter.INSTANCE.convertEntityToBO(schisandraOssQiniu);
|
||||||
|
return schisandraOssQiniuBO;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
package com.schisandra.oss.domain.service.impl;
|
package com.schisandra.oss.domain.service.impl;
|
||||||
|
|
||||||
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
|
||||||
|
import com.schisandra.oss.domain.convert.SchisandraOssQiniuBOConverter;
|
||||||
import com.schisandra.oss.domain.convert.SchisandraOssTencentBOConverter;
|
import com.schisandra.oss.domain.convert.SchisandraOssTencentBOConverter;
|
||||||
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
|
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
|
||||||
import com.schisandra.oss.domain.service.SchisandraOssTencentDomainService;
|
import com.schisandra.oss.domain.service.SchisandraOssTencentDomainService;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssQiniu;
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssTencent;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssTencent;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssTencentService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssTencentService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -45,4 +48,12 @@ public class SchisandraOssTencentDomainServiceImpl implements SchisandraOssTence
|
|||||||
return schisandraOssTencentService.update(schisandraOssTencent) > 0;
|
return schisandraOssTencentService.update(schisandraOssTencent) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssTencentBO getTencentOssConfig(String userId) {
|
||||||
|
SchisandraOssTencent schisandraOssTencent = schisandraOssTencentService.getTencentOssConfig(userId);
|
||||||
|
SchisandraOssTencentBO schisandraOssTencentBO = SchisandraOssTencentBOConverter.INSTANCE.convertEntityToBO(schisandraOssTencent);
|
||||||
|
return schisandraOssTencentBO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
package com.schisandra.oss.domain.service.impl;
|
package com.schisandra.oss.domain.service.impl;
|
||||||
|
|
||||||
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
||||||
|
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
|
||||||
|
import com.schisandra.oss.domain.convert.SchisandraOssTencentBOConverter;
|
||||||
import com.schisandra.oss.domain.convert.SchisandraOssUcloudBOConverter;
|
import com.schisandra.oss.domain.convert.SchisandraOssUcloudBOConverter;
|
||||||
import com.schisandra.oss.domain.bo.SchisandraOssUcloudBO;
|
import com.schisandra.oss.domain.bo.SchisandraOssUcloudBO;
|
||||||
import com.schisandra.oss.domain.service.SchisandraOssUcloudDomainService;
|
import com.schisandra.oss.domain.service.SchisandraOssUcloudDomainService;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssTencent;
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssUcloud;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssUcloud;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssUcloudService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssUcloudService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -45,4 +48,11 @@ public class SchisandraOssUcloudDomainServiceImpl implements SchisandraOssUcloud
|
|||||||
return schisandraOssUcloudService.update(schisandraOssUcloud) > 0;
|
return schisandraOssUcloudService.update(schisandraOssUcloud) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssUcloudBO getUcloudOssConfig(String userId) {
|
||||||
|
SchisandraOssUcloud schisandraOssUcloud = schisandraOssUcloudService.getUcloudOssConfig(userId);
|
||||||
|
SchisandraOssUcloudBO schisandraOssUcloudBO = SchisandraOssUcloudBOConverter.INSTANCE.convertEntityToBO(schisandraOssUcloud);
|
||||||
|
return schisandraOssUcloudBO;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -45,4 +45,10 @@ public class SchisandraOssUpDomainServiceImpl implements SchisandraOssUpDomainSe
|
|||||||
return schisandraOssUpService.update(schisandraOssUp) > 0;
|
return schisandraOssUpService.update(schisandraOssUp) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssUpBO getUpOssConfig(String userId) {
|
||||||
|
SchisandraOssUp schisandraOssUp=schisandraOssUpService.getUpOssConfig(userId);
|
||||||
|
return SchisandraOssUpBOConverter.INSTANCE.convertEntityToBO(schisandraOssUp);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -45,4 +45,10 @@ public class SchisandraOssWangyiDomainServiceImpl implements SchisandraOssWangyi
|
|||||||
return schisandraOssWangyiService.update(schisandraOssWangyi) > 0;
|
return schisandraOssWangyiService.update(schisandraOssWangyi) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssWangyiBO getWangyiOssConfig(String userId) {
|
||||||
|
SchisandraOssWangyi schisandraOssWangyi=schisandraOssWangyiService.getWangyiOssConfig(userId);
|
||||||
|
return SchisandraOssWangyiBOConverter.INSTANCE.convertEntityToBO(schisandraOssWangyi);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.schisandra.oss.infra.basic.service;
|
package com.schisandra.oss.infra.basic.service;
|
||||||
|
|
||||||
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssJd;
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssJinshan;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssJinshan;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,4 +44,5 @@ public interface SchisandraOssJinshanService {
|
|||||||
boolean deleteById(Long id);
|
boolean deleteById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
SchisandraOssJinshan getJinshanOssConfig(String userId);
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,13 @@ public interface SchisandraOssQingyunService {
|
|||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
boolean deleteById(Long id);
|
boolean deleteById(Long id);
|
||||||
|
/**
|
||||||
|
* @description: 获取用户配置信息
|
||||||
|
* @param: [userId]
|
||||||
|
* @return: com.schisandra.oss.infra.basic.entity.SchisandraOssQingyun
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:33
|
||||||
|
*/
|
||||||
|
SchisandraOssQingyun getQingyunOssConfig(String userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -42,5 +42,13 @@ public interface SchisandraOssQiniuService {
|
|||||||
*/
|
*/
|
||||||
boolean deleteById(Long id);
|
boolean deleteById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:根据用户ID查询七牛云对象存储配置表
|
||||||
|
* @param: [userId]
|
||||||
|
* @return: com.schisandra.oss.infra.basic.entity.SchisandraOssQiniu
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:33
|
||||||
|
*/
|
||||||
|
SchisandraOssQiniu getQiniuOssConfig(String userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -42,5 +42,13 @@ public interface SchisandraOssTencentService {
|
|||||||
*/
|
*/
|
||||||
boolean deleteById(Long id);
|
boolean deleteById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:获取腾讯云对象存储配置表
|
||||||
|
* @param: [userId]
|
||||||
|
* @return: com.schisandra.oss.infra.basic.entity.SchisandraOssTencent
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:33
|
||||||
|
*/
|
||||||
|
SchisandraOssTencent getTencentOssConfig(String userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,13 @@ public interface SchisandraOssUcloudService {
|
|||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
boolean deleteById(Long id);
|
boolean deleteById(Long id);
|
||||||
|
/**
|
||||||
|
* @description:根据用户id获取ucloud配置信息
|
||||||
|
* @param: [userId]
|
||||||
|
* @return: com.schisandra.oss.infra.basic.entity.SchisandraOssUcloud
|
||||||
|
* @author zlg
|
||||||
|
* @date: 2024/6/25 14:33
|
||||||
|
*/
|
||||||
|
SchisandraOssUcloud getUcloudOssConfig(String userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -42,5 +42,5 @@ public interface SchisandraOssUpService {
|
|||||||
*/
|
*/
|
||||||
boolean deleteById(Long id);
|
boolean deleteById(Long id);
|
||||||
|
|
||||||
|
SchisandraOssUp getUpOssConfig(String userId);
|
||||||
}
|
}
|
||||||
|
@@ -42,5 +42,5 @@ public interface SchisandraOssWangyiService {
|
|||||||
*/
|
*/
|
||||||
boolean deleteById(Long id);
|
boolean deleteById(Long id);
|
||||||
|
|
||||||
|
SchisandraOssWangyi getWangyiOssConfig(String userId);
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,8 @@ package com.schisandra.oss.infra.basic.service.impl;
|
|||||||
|
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssJinshan;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssJinshan;
|
||||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssJinshanDao;
|
import com.schisandra.oss.infra.basic.dao.SchisandraOssJinshanDao;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssJdTableDef;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssJinshanTableDef;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssJinshanService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssJinshanService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -63,5 +65,10 @@ public class SchisandraOssJinshanServiceImpl implements SchisandraOssJinshanServ
|
|||||||
return this.schisandraOssJinshanDao.deleteById(id) > 0;
|
return this.schisandraOssJinshanDao.deleteById(id) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssJinshan getJinshanOssConfig(String userId) {
|
||||||
|
return schisandraOssJinshanDao.selectOneByCondition(SchisandraOssJinshanTableDef.SCHISANDRA_OSS_JINSHAN.USER_ID.eq(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ package com.schisandra.oss.infra.basic.service.impl;
|
|||||||
|
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssQingyun;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssQingyun;
|
||||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssQingyunDao;
|
import com.schisandra.oss.infra.basic.dao.SchisandraOssQingyunDao;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssQingyunTableDef;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssQingyunService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssQingyunService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -63,5 +64,10 @@ public class SchisandraOssQingyunServiceImpl implements SchisandraOssQingyunServ
|
|||||||
return this.schisandraOssQingyunDao.deleteById(id) > 0;
|
return this.schisandraOssQingyunDao.deleteById(id) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssQingyun getQingyunOssConfig(String userId) {
|
||||||
|
return schisandraOssQingyunDao.selectOneByCondition(SchisandraOssQingyunTableDef.SCHISANDRA_OSS_QINGYUN.USER_ID.eq(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ package com.schisandra.oss.infra.basic.service.impl;
|
|||||||
|
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssQiniu;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssQiniu;
|
||||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssQiniuDao;
|
import com.schisandra.oss.infra.basic.dao.SchisandraOssQiniuDao;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssQiniuTableDef;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssQiniuService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssQiniuService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -63,5 +64,11 @@ public class SchisandraOssQiniuServiceImpl implements SchisandraOssQiniuService
|
|||||||
return this.schisandraOssQiniuDao.deleteById(id) > 0;
|
return this.schisandraOssQiniuDao.deleteById(id) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssQiniu getQiniuOssConfig(String userId) {
|
||||||
|
return schisandraOssQiniuDao.selectOneByCondition(SchisandraOssQiniuTableDef.SCHISANDRA_OSS_QINIU.USER_ID.eq(userId));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,8 @@ package com.schisandra.oss.infra.basic.service.impl;
|
|||||||
|
|
||||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssTencentDao;
|
import com.schisandra.oss.infra.basic.dao.SchisandraOssTencentDao;
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssTencent;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssTencent;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssQiniuTableDef;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssTencentTableDef;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssTencentService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssTencentService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -63,5 +65,10 @@ public class SchisandraOssTencentServiceImpl implements SchisandraOssTencentServ
|
|||||||
return this.schisandraOssTencentDao.deleteById(id) > 0;
|
return this.schisandraOssTencentDao.deleteById(id) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssTencent getTencentOssConfig(String userId) {
|
||||||
|
return schisandraOssTencentDao.selectOneByCondition(SchisandraOssTencentTableDef.SCHISANDRA_OSS_TENCENT.USER_ID.eq(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,8 @@ package com.schisandra.oss.infra.basic.service.impl;
|
|||||||
|
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssUcloud;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssUcloud;
|
||||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssUcloudDao;
|
import com.schisandra.oss.infra.basic.dao.SchisandraOssUcloudDao;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssTencentTableDef;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssUcloudTableDef;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssUcloudService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssUcloudService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -64,4 +66,10 @@ public class SchisandraOssUcloudServiceImpl implements SchisandraOssUcloudServic
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssUcloud getUcloudOssConfig(String userId) {
|
||||||
|
return schisandraOssUcloudDao.selectOneByCondition(SchisandraOssUcloudTableDef.SCHISANDRA_OSS_UCLOUD.USER_ID.eq(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ package com.schisandra.oss.infra.basic.service.impl;
|
|||||||
|
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssUp;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssUp;
|
||||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssUpDao;
|
import com.schisandra.oss.infra.basic.dao.SchisandraOssUpDao;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssUpTableDef;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssUpService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssUpService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -63,5 +64,12 @@ public class SchisandraOssUpServiceImpl implements SchisandraOssUpService {
|
|||||||
return this.schisandraOssUpDao.deleteById(id) > 0;
|
return this.schisandraOssUpDao.deleteById(id) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssUp getUpOssConfig(String userId) {
|
||||||
|
return schisandraOssUpDao.selectOneByCondition(SchisandraOssUpTableDef
|
||||||
|
.SCHISANDRA_OSS_UP.USER_ID.eq(userId));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ package com.schisandra.oss.infra.basic.service.impl;
|
|||||||
|
|
||||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssWangyi;
|
import com.schisandra.oss.infra.basic.entity.SchisandraOssWangyi;
|
||||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssWangyiDao;
|
import com.schisandra.oss.infra.basic.dao.SchisandraOssWangyiDao;
|
||||||
|
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssWangyiTableDef;
|
||||||
import com.schisandra.oss.infra.basic.service.SchisandraOssWangyiService;
|
import com.schisandra.oss.infra.basic.service.SchisandraOssWangyiService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -63,5 +64,10 @@ public class SchisandraOssWangyiServiceImpl implements SchisandraOssWangyiServic
|
|||||||
return this.schisandraOssWangyiDao.deleteById(id) > 0;
|
return this.schisandraOssWangyiDao.deleteById(id) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchisandraOssWangyi getWangyiOssConfig(String userId) {
|
||||||
|
return this.schisandraOssWangyiDao.selectOneByCondition(SchisandraOssWangyiTableDef.SCHISANDRA_OSS_WANGYI.USER_ID.eq(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user