|
@@ -5,24 +5,21 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.fdkankan.filestorage.Consumer;
|
|
|
import com.fdkankan.filestorage.InnerUtils;
|
|
|
-import com.fdkankan.filestorage.OssOptions;
|
|
|
+import com.fdkankan.filestorage.FileStorageTemplate;
|
|
|
import com.fdkankan.filestorage.properties.CosProperties;
|
|
|
import com.qcloud.cos.COSClient;
|
|
|
import com.qcloud.cos.model.*;
|
|
|
-import com.qcloud.cos.utils.Md5Utils;
|
|
|
import lombok.Getter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Base64Utils;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -34,19 +31,22 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@Service("CosTemplate")
|
|
|
@ConditionalOnProperty(prefix = CosProperties.PREFIX,name = "filestorage.active",havingValue = "cos")
|
|
|
-public class CosTemplate implements OssOptions {
|
|
|
+public class CosTemplate implements FileStorageTemplate {
|
|
|
|
|
|
private final COSClient cosClient;
|
|
|
- private final CosProperties ossProperties;
|
|
|
-
|
|
|
- public CosTemplate(COSClient ossClient, CosProperties ossProperties) {
|
|
|
+ private final CosProperties cosProperties;
|
|
|
+ @Override
|
|
|
+ public String getActive() {
|
|
|
+ return this.cosProperties.getActive();
|
|
|
+ }
|
|
|
+ public CosTemplate(COSClient ossClient, CosProperties cosProperties) {
|
|
|
this.cosClient = ossClient;
|
|
|
- this.ossProperties = ossProperties;
|
|
|
+ this.cosProperties = cosProperties;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String uploadFile(String pathKey, String filePath) {
|
|
|
- return uploadFile(ossProperties.getBucket(), pathKey, filePath);
|
|
|
+ return uploadFile(cosProperties.getBucket(), pathKey, filePath);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -80,7 +80,7 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public String uploadFileText(String pathKey, String content) {
|
|
|
- return uploadFileText(ossProperties.getBucket(), pathKey, content);
|
|
|
+ return uploadFileText(cosProperties.getBucket(), pathKey, content);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -91,7 +91,7 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public String uploadFileBase64Image(String pathKey, String content) {
|
|
|
- return uploadFileBase64Image(ossProperties.getBucket(), pathKey, content);
|
|
|
+ return uploadFileBase64Image(cosProperties.getBucket(), pathKey, content);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -102,7 +102,7 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public String uploadFileBytes(String pathKey, byte[] bytes) {
|
|
|
- return uploadFileBytes(ossProperties.getBucket(), pathKey, bytes);
|
|
|
+ return uploadFileBytes(cosProperties.getBucket(), pathKey, bytes);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -113,7 +113,7 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public String uploadFileStream(String pathKey, InputStream stream) {
|
|
|
- return uploadFileStream(ossProperties.getBucket(), pathKey, stream);
|
|
|
+ return uploadFileStream(cosProperties.getBucket(), pathKey, stream);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -128,7 +128,7 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public File downloadFileTmp(String pathKey) {
|
|
|
- return downloadFileTmp(ossProperties.getBucket(), pathKey);
|
|
|
+ return downloadFileTmp(cosProperties.getBucket(), pathKey);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -141,7 +141,7 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public ObjectMetadata downloadFile(String pathKey, String file) {
|
|
|
- return downloadFile(ossProperties.getBucket(), pathKey, file);
|
|
|
+ return downloadFile(cosProperties.getBucket(), pathKey, file);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -156,7 +156,7 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public ObjectMetadata downloadFile(String pathKey, Consumer<InputStream> handler) {
|
|
|
- return downloadFile(ossProperties.getBucket(), pathKey, handler);
|
|
|
+ return downloadFile(cosProperties.getBucket(), pathKey, handler);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -200,17 +200,17 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public boolean ossDownloadFileToLocal(String path, String localPath) {
|
|
|
- return ossDownloadFileToLocal(ossProperties.getBucket(),path,localPath);
|
|
|
+ return ossDownloadFileToLocal(cosProperties.getBucket(),path,localPath);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String calculateUrl(String pathKey) {
|
|
|
- return calculateUrl(ossProperties.getBucket(), pathKey);
|
|
|
+ return calculateUrl(cosProperties.getBucket(), pathKey);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String calculateUrl(String bucket, String pathKey) {
|
|
|
- String host = ossProperties.getHostByBucket(bucket);
|
|
|
+ String host = cosProperties.getHostByBucket(bucket);
|
|
|
return host + "/" + pathKey;
|
|
|
}
|
|
|
|
|
@@ -232,7 +232,7 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public Boolean copyObject(String oldPath, String newPath) {
|
|
|
- return copyObject(ossProperties.getBucket(), oldPath, ossProperties.getBucket(), newPath);
|
|
|
+ return copyObject(cosProperties.getBucket(), oldPath, cosProperties.getBucket(), newPath);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -248,7 +248,7 @@ public class CosTemplate implements OssOptions {
|
|
|
@Override
|
|
|
public void deleteObject(String keyName) {
|
|
|
if (doesObjectExist(keyName)) {
|
|
|
- deleteObject(ossProperties.getBucket(), keyName);
|
|
|
+ deleteObject(cosProperties.getBucket(), keyName);
|
|
|
} else {
|
|
|
log.warn("文件不存在,KeyName{}", keyName);
|
|
|
}
|
|
@@ -261,7 +261,7 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public List<String> getFileFolder(String keyName) {
|
|
|
- return getFileFolder(ossProperties.getBucket(), keyName);
|
|
|
+ return getFileFolder(cosProperties.getBucket(), keyName);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -311,17 +311,17 @@ public class CosTemplate implements OssOptions {
|
|
|
|
|
|
@Override
|
|
|
public boolean doesObjectExist(String keyName) {
|
|
|
- return doesObjectExist(ossProperties.getBucket(), keyName);
|
|
|
+ return doesObjectExist(cosProperties.getBucket(), keyName);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getBucket() {
|
|
|
- return ossProperties.getBucket();
|
|
|
+ return cosProperties.getBucket();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String uploadFileImage(String pathKey, String filePath) {
|
|
|
- return uploadFileImage(ossProperties.getBucket(), pathKey, filePath);
|
|
|
+ return uploadFileImage(cosProperties.getBucket(), pathKey, filePath);
|
|
|
}
|
|
|
|
|
|
@Override
|