Merge branch 'master' into feature/REQ-2409
# Conflicts: # oss-client/src/main/java/cn/axzo/oss/client/controller/ServerFileController.java # oss-http-api/src/main/java/cn/axzo/oss/http/api/ServerFileServiceApi.java # oss-integration/src/main/java/cn/axzo/oss/integration/s3/AliOssService.java # oss-integration/src/main/java/cn/axzo/oss/integration/s3/impl/AliOssServiceImpl.java # oss-manager-api/src/main/java/cn/axzo/oss/manager/api/FileManager.java # oss-manager/src/main/java/cn/axzo/oss/manager/impl/FileManagerImpl.java
This commit is contained in:
commit
36390d6c49
@ -2,17 +2,25 @@ package cn.axzo.oss.client.controller;
|
||||
|
||||
import cn.axzo.core.utils.converter.BeanConverter;
|
||||
import cn.axzo.framework.auth.domain.ContextInfo;
|
||||
import cn.axzo.oss.common.enums.ChannelTypeEnum;
|
||||
import cn.axzo.oss.common.enums.CodeEnum;
|
||||
import cn.axzo.oss.common.exception.BizException;
|
||||
import cn.axzo.oss.common.utils.BeanConvertUtil;
|
||||
import cn.axzo.oss.common.utils.UrlUtil;
|
||||
import cn.axzo.oss.http.api.ServerFileServiceApi;
|
||||
import cn.axzo.oss.http.model.ApiSignUrlDownloadRequest;
|
||||
import cn.axzo.oss.http.model.ApiSignUrlDownloadResponse;
|
||||
import cn.axzo.oss.http.model.ApiSignUrlUploadRequest;
|
||||
import cn.axzo.oss.http.model.ApiSignUrlUploadResponse;
|
||||
import cn.axzo.oss.http.model.BatchGetObjectMetaRequest;
|
||||
import cn.axzo.oss.http.model.BatchGetObjectMetaResponse;
|
||||
import cn.axzo.oss.http.model.FileInformationResponse;
|
||||
import cn.axzo.oss.http.model.FindFileKeyRequest;
|
||||
import cn.axzo.oss.http.model.FindFileKeyResponse;
|
||||
import cn.axzo.oss.http.model.FindFileUrlRequest;
|
||||
import cn.axzo.oss.http.model.FindFileUrlResponse;
|
||||
import cn.axzo.oss.http.model.GetObjectMetaRequest;
|
||||
import cn.axzo.oss.http.model.GetObjectMetaResponse;
|
||||
import cn.axzo.oss.http.model.ServerFileDeleteRequest;
|
||||
import cn.axzo.oss.http.model.ServerFileUploadByUrlRequest;
|
||||
import cn.axzo.oss.http.model.ServerFileUploadRequest;
|
||||
@ -25,17 +33,24 @@ import cn.axzo.oss.manager.api.dto.request.ServerFileUploadByUrlDto;
|
||||
import cn.axzo.oss.manager.api.dto.request.ServerFileUploadDto;
|
||||
import cn.axzo.oss.manager.api.dto.request.SignUrlDownloadDto;
|
||||
import cn.axzo.oss.manager.api.dto.request.SignUrlUploadDto;
|
||||
import cn.axzo.oss.manager.api.dto.response.ManaGetObjectMetaResponse;
|
||||
import cn.axzo.oss.service.api.FileByUrlService;
|
||||
import cn.axzo.oss.service.api.FileService;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务端文件 Controller
|
||||
@ -134,6 +149,43 @@ public class ServerFileController implements ServerFileServiceApi {
|
||||
return CommonResponse.success(BeanConverter.convert(fileService.signUrlUpload(dto, liteSaasContext), ApiSignUrlUploadResponse.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件元数据信息
|
||||
*/
|
||||
@Override
|
||||
public CommonResponse<GetObjectMetaResponse> getObjectMeta(@RequestBody GetObjectMetaRequest request) {
|
||||
if (!StringUtils.hasText(request.getUrl()) && !StringUtils.hasText(request.getBucketName()) && !StringUtils.hasText(request.getKey())) {
|
||||
throw new BizException(CodeEnum.URL_BUCKET_NAME_KEY_ALL_EMPTY);
|
||||
}
|
||||
|
||||
|
||||
String bucketName = UrlUtil.fetchBucketName(request.getBucketName(), request.getUrl());
|
||||
String bucketKey = UrlUtil.fetchBucketKey(request.getKey(), request.getUrl());
|
||||
ManaGetObjectMetaResponse response = this.fileService.getObjectMeta(bucketName
|
||||
, bucketKey, request.getUrl()
|
||||
, ChannelTypeEnum.OSS.getChannelCode());
|
||||
return CommonResponse.success(BeanConverter.convert(response, GetObjectMetaResponse.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件元数据信息-批量
|
||||
*/
|
||||
@Override
|
||||
public CommonResponse<BatchGetObjectMetaResponse> batchGetObjectMeta(@RequestBody BatchGetObjectMetaRequest request) {
|
||||
List<GetObjectMetaRequest> list = request.getList();
|
||||
if (Objects.isNull(request) || CollectionUtils.isEmpty(list)) {
|
||||
return CommonResponse.success(BatchGetObjectMetaResponse.builder().build());
|
||||
}
|
||||
List<GetObjectMetaResponse> responseList = request.getList().stream().map(item -> {
|
||||
GetObjectMetaResponse response = getObjectMeta(item).getData();
|
||||
response.setId(item.getId());
|
||||
return response;
|
||||
}).collect(Collectors.toList());
|
||||
return CommonResponse.success(BatchGetObjectMetaResponse.builder().list(responseList).build());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 通过URL上传文件
|
||||
* @param request
|
||||
|
||||
@ -60,7 +60,9 @@ public enum CodeEnum implements EnumBase<Integer> {
|
||||
UPLOAD_SIGN_URL_FAIL(503,"上传临时授权获取SIGNURL失败"),
|
||||
DOWNLOAD_SIGN_URL_FAIL(504,"下载临时授权获取SIGNURL失败"),
|
||||
FILE_APP_IS_EMPTY(505, "app is empty"),
|
||||
BUCKET_TYPE_IS_EMPTY(506, "bucketType is empty")
|
||||
BUCKET_TYPE_IS_EMPTY(506, "bucketType is empty"),
|
||||
GET_OBJECT_META_FAIL(507, "获取元文件失败"),
|
||||
URL_BUCKET_NAME_KEY_ALL_EMPTY(508, "url-bucketName-key同时为空")
|
||||
;
|
||||
|
||||
private final Integer code;
|
||||
|
||||
@ -26,6 +26,36 @@ public class UrlUtil {
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过url或者bucketName,获取桶名称
|
||||
*/
|
||||
public static String fetchBucketName(String bucketName, String url) {
|
||||
if (org.springframework.util.StringUtils.hasText(bucketName)) {
|
||||
return bucketName;
|
||||
}
|
||||
if (org.springframework.util.StringUtils.hasText(url)) {
|
||||
if (url.contains(".") && url.contains("//")) {
|
||||
return url.substring(url.indexOf("//") + 2,url.indexOf("."));
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
/**
|
||||
* 通过url或者bucketKey,获取桶文件Key
|
||||
*/
|
||||
public static String fetchBucketKey(String bucketKey, String url) {
|
||||
if (org.springframework.util.StringUtils.hasText(bucketKey)) {
|
||||
return bucketKey;
|
||||
}
|
||||
if (org.springframework.util.StringUtils.hasText(url)) {
|
||||
if (url.contains(".") && url.contains("//")) {
|
||||
String urlPathNoHttp = url.split("//")[1];
|
||||
return urlPathNoHttp.substring(urlPathNoHttp.indexOf("/") + 1);
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str = "http://axzo-test.oss-cn-chengdu.aliyuncs.com/reportCenter/reportCenter_test";
|
||||
|
||||
@ -4,11 +4,15 @@ import cn.axzo.oss.http.model.ApiSignUrlDownloadRequest;
|
||||
import cn.axzo.oss.http.model.ApiSignUrlDownloadResponse;
|
||||
import cn.axzo.oss.http.model.ApiSignUrlUploadRequest;
|
||||
import cn.axzo.oss.http.model.ApiSignUrlUploadResponse;
|
||||
import cn.axzo.oss.http.model.BatchGetObjectMetaRequest;
|
||||
import cn.axzo.oss.http.model.BatchGetObjectMetaResponse;
|
||||
import cn.axzo.oss.http.model.FileInformationResponse;
|
||||
import cn.axzo.oss.http.model.FindFileKeyRequest;
|
||||
import cn.axzo.oss.http.model.FindFileKeyResponse;
|
||||
import cn.axzo.oss.http.model.FindFileUrlRequest;
|
||||
import cn.axzo.oss.http.model.FindFileUrlResponse;
|
||||
import cn.axzo.oss.http.model.GetObjectMetaRequest;
|
||||
import cn.axzo.oss.http.model.GetObjectMetaResponse;
|
||||
import cn.axzo.oss.http.model.ServerFileDeleteRequest;
|
||||
import cn.axzo.oss.http.model.ServerFileUploadByUrlRequest;
|
||||
import cn.axzo.oss.http.model.ServerFileUploadRequest;
|
||||
@ -83,6 +87,18 @@ public interface ServerFileServiceApi {
|
||||
@RequestMapping(value = "api/signUrl/fetchUpload", method = RequestMethod.POST)
|
||||
CommonResponse<ApiSignUrlUploadResponse> signUrlFetchUpload(ApiSignUrlUploadRequest request);
|
||||
|
||||
/**
|
||||
* 文件元数据信息
|
||||
*/
|
||||
@RequestMapping(value = "api/server/getObjectMeta", method = RequestMethod.POST)
|
||||
CommonResponse<GetObjectMetaResponse> getObjectMeta(GetObjectMetaRequest request);
|
||||
|
||||
/**
|
||||
* 文件元数据信息
|
||||
*/
|
||||
@RequestMapping(value = "api/server/batchGetObjectMeta", method = RequestMethod.POST)
|
||||
CommonResponse<BatchGetObjectMetaResponse> batchGetObjectMeta(BatchGetObjectMetaRequest request);
|
||||
|
||||
/**
|
||||
* 通过URL上传文件
|
||||
* @param request
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.axzo.oss.http.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: xudawei
|
||||
* @date: 2024-03-12
|
||||
* @description: 授权给第三方下载
|
||||
**/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BatchGetObjectMetaRequest {
|
||||
|
||||
@Max(value = 1000, message = "max size:1000")
|
||||
@NotEmpty(message = "list not empty")
|
||||
private List<GetObjectMetaRequest> list;
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package cn.axzo.oss.http.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 元数据-批量
|
||||
*
|
||||
* @author xudawei
|
||||
* @since 2024-05-20
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class BatchGetObjectMetaResponse {
|
||||
|
||||
private List<GetObjectMetaResponse> list = new ArrayList<>();
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.axzo.oss.http.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author: xudawei
|
||||
* @date: 2024-03-12
|
||||
* @description: 授权给第三方下载
|
||||
**/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class GetObjectMetaRequest {
|
||||
/**
|
||||
* 桶名称
|
||||
*/
|
||||
private String bucketName;
|
||||
/**
|
||||
* 文件key
|
||||
*/
|
||||
private String key;
|
||||
/**
|
||||
* 文件url
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 唯一标识
|
||||
*/
|
||||
private String id;
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.axzo.oss.http.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*
|
||||
* @author xudawei
|
||||
* @since 2024-05-20
|
||||
*/
|
||||
@Data
|
||||
public class GetObjectMetaResponse {
|
||||
/**
|
||||
* 桶名称
|
||||
*/
|
||||
private String bucketName;
|
||||
/**
|
||||
* 文件key
|
||||
*/
|
||||
private String key;
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
private long size;
|
||||
|
||||
/**
|
||||
* url
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 唯一标识
|
||||
*/
|
||||
private String id;
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.axzo.oss.integration.s3;
|
||||
|
||||
import cn.axzo.oss.integration.s3.base.BaseS3Service;
|
||||
import com.aliyun.oss.model.SimplifiedObjectMeta;
|
||||
|
||||
/**
|
||||
* @program: oss
|
||||
@ -29,6 +30,11 @@ public interface AliOssService extends BaseS3Service {
|
||||
* 获取url
|
||||
*/
|
||||
String getUrl(String bucketName, String tgtFileKey);
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
SimplifiedObjectMeta getObjectMeta(String bucketName, String key, String url);
|
||||
|
||||
|
||||
/**
|
||||
* 通过url上传至OBS
|
||||
|
||||
@ -14,4 +14,10 @@ public interface OssClientBase {
|
||||
|
||||
String getEndpoint();
|
||||
|
||||
String getHangZhouEndpoint();
|
||||
|
||||
String getBeiJingEndpoint();
|
||||
|
||||
String getShangHaiEndpoint();
|
||||
|
||||
}
|
||||
|
||||
@ -5,10 +5,14 @@ import cn.axzo.oss.common.enums.CodeEnum;
|
||||
import cn.axzo.oss.common.exception.S3Exception;
|
||||
import cn.axzo.oss.common.utils.Utility;
|
||||
import cn.axzo.oss.integration.s3.base.OssClientBase;
|
||||
import cn.axzo.oss.integration.s3.config.AliOssBeiJingConfig;
|
||||
import cn.axzo.oss.integration.s3.config.AliOssHangZhouConfig;
|
||||
import cn.axzo.oss.integration.s3.config.AliOssShangHaiConfig;
|
||||
import cn.azxo.framework.common.utils.LogUtil;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@ -29,6 +33,15 @@ public class AliOssAppProClient implements OssClientBase {
|
||||
|
||||
private volatile static OSS instance = null;
|
||||
|
||||
@Autowired
|
||||
private AliOssHangZhouConfig aliOssHangZhouConfig;//杭州
|
||||
|
||||
@Autowired
|
||||
private AliOssBeiJingConfig aliOssBeiJingConfig;//北京
|
||||
|
||||
@Autowired
|
||||
private AliOssShangHaiConfig aliOssShangHaiConfig;//上海
|
||||
|
||||
public OSS getClient() {
|
||||
if (Utility.objIsNull(instance)) {
|
||||
throw new S3Exception(CodeEnum.S3_CLIENT_NULL.getCode(), "oss客户端未初始化");
|
||||
@ -54,4 +67,19 @@ public class AliOssAppProClient implements OssClientBase {
|
||||
return APP_PRO_ENDPOINT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHangZhouEndpoint() {
|
||||
return aliOssHangZhouConfig.getEndpoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBeiJingEndpoint() {
|
||||
return aliOssBeiJingConfig.getEndpoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShangHaiEndpoint() {
|
||||
return aliOssShangHaiConfig.getEndpoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,10 @@ import cn.axzo.oss.common.enums.CodeEnum;
|
||||
import cn.axzo.oss.common.exception.S3Exception;
|
||||
import cn.axzo.oss.common.utils.Utility;
|
||||
import cn.axzo.oss.integration.s3.base.OssClientBase;
|
||||
import cn.axzo.oss.integration.s3.config.AliOssBeiJingConfig;
|
||||
import cn.axzo.oss.integration.s3.config.AliOssConfig;
|
||||
import cn.axzo.oss.integration.s3.config.AliOssHangZhouConfig;
|
||||
import cn.axzo.oss.integration.s3.config.AliOssShangHaiConfig;
|
||||
import cn.azxo.framework.common.utils.LogUtil;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
@ -24,9 +27,21 @@ import org.springframework.stereotype.Component;
|
||||
@Slf4j
|
||||
public class AliOssClient implements OssClientBase {
|
||||
private volatile static OSS instance = null;
|
||||
private volatile static OSS hangZhouInstance = null;
|
||||
private volatile static OSS shangHaiInstance = null;
|
||||
private volatile static OSS beiJingInstance = null;
|
||||
|
||||
@Autowired
|
||||
private AliOssConfig aliOssConfig;
|
||||
private AliOssConfig aliOssConfig;//成都
|
||||
|
||||
@Autowired
|
||||
private AliOssHangZhouConfig aliOssHangZhouConfig;//杭州
|
||||
|
||||
@Autowired
|
||||
private AliOssBeiJingConfig aliOssBeiJingConfig;//北京
|
||||
|
||||
@Autowired
|
||||
private AliOssShangHaiConfig aliOssShangHaiConfig;//上海
|
||||
|
||||
public OSS getClient(){
|
||||
if (Utility.objIsNull(instance)){
|
||||
@ -35,6 +50,27 @@ public class AliOssClient implements OssClientBase {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public OSS getHangZhouClient(){
|
||||
if (Utility.objIsNull(hangZhouInstance)){
|
||||
throw new S3Exception(CodeEnum.S3_CLIENT_NULL.getCode(),"oss-hangzhou客户端未初始化");
|
||||
}
|
||||
return hangZhouInstance;
|
||||
}
|
||||
|
||||
public OSS getBeiJingClient(){
|
||||
if (Utility.objIsNull(beiJingInstance)){
|
||||
throw new S3Exception(CodeEnum.S3_CLIENT_NULL.getCode(),"oss-beijing客户端未初始化");
|
||||
}
|
||||
return beiJingInstance;
|
||||
}
|
||||
|
||||
public OSS getShangHaiClient(){
|
||||
if (Utility.objIsNull(shangHaiInstance)){
|
||||
throw new S3Exception(CodeEnum.S3_CLIENT_NULL.getCode(),"oss-shanghai客户端未初始化");
|
||||
}
|
||||
return shangHaiInstance;
|
||||
}
|
||||
|
||||
|
||||
@PostConstruct
|
||||
@Override
|
||||
@ -46,6 +82,24 @@ public class AliOssClient implements OssClientBase {
|
||||
instance = null;
|
||||
LogUtil.error("initClient error = {}", e);
|
||||
}
|
||||
try {
|
||||
hangZhouInstance = new OSSClientBuilder().build(aliOssHangZhouConfig.getEndpoint(),aliOssHangZhouConfig.getAccessKeyId(),aliOssHangZhouConfig.getSecretAccessKey());
|
||||
} catch (Exception e) {
|
||||
hangZhouInstance = null;
|
||||
LogUtil.error("initHangZhouClient error = {}", e);
|
||||
}
|
||||
try {
|
||||
beiJingInstance = new OSSClientBuilder().build(aliOssBeiJingConfig.getEndpoint(),aliOssBeiJingConfig.getAccessKeyId(),aliOssBeiJingConfig.getSecretAccessKey());
|
||||
} catch (Exception e) {
|
||||
beiJingInstance = null;
|
||||
LogUtil.error("initBeiJingClient error = {}", e);
|
||||
}
|
||||
try {
|
||||
shangHaiInstance = new OSSClientBuilder().build(aliOssShangHaiConfig.getEndpoint(),aliOssShangHaiConfig.getAccessKeyId(),aliOssShangHaiConfig.getSecretAccessKey());
|
||||
} catch (Exception e) {
|
||||
shangHaiInstance = null;
|
||||
LogUtil.error("initShangHaiClient error = {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,4 +107,19 @@ public class AliOssClient implements OssClientBase {
|
||||
return aliOssConfig.getEndpoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHangZhouEndpoint(){
|
||||
return aliOssHangZhouConfig.getEndpoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBeiJingEndpoint(){
|
||||
return aliOssBeiJingConfig.getEndpoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShangHaiEndpoint(){
|
||||
return aliOssShangHaiConfig.getEndpoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -59,4 +59,19 @@ public class HuaWeiCloudObsClient implements OssClientBase {
|
||||
public String getEndpoint() {
|
||||
return huaWeiCloudObsConfig.getEndPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHangZhouEndpoint() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBeiJingEndpoint() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShangHaiEndpoint() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package cn.axzo.oss.integration.s3.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @program: oss
|
||||
* @description: 阿里云配置-北京
|
||||
* @author: xudawei
|
||||
* @date: 2024-05-23
|
||||
**/
|
||||
@RefreshScope
|
||||
@Component
|
||||
public class AliOssBeiJingConfig {
|
||||
|
||||
@Value("${aliyun.oss.beijing.accessKeyId}")
|
||||
private String ACCESS_KEY_ID;
|
||||
|
||||
@Value("${aliyun.oss.beijing.secretAccessKey}")
|
||||
private String SECRET_ACCESS_KEY;
|
||||
|
||||
@Value("${aliyun.oss.beijing.endpoint}")
|
||||
private String ENDPOINT;
|
||||
|
||||
public String getAccessKeyId(){
|
||||
return this.ACCESS_KEY_ID;
|
||||
}
|
||||
|
||||
public String getSecretAccessKey(){
|
||||
return this.SECRET_ACCESS_KEY;
|
||||
}
|
||||
|
||||
public String getEndpoint(){
|
||||
return this.ENDPOINT;
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @program: oss
|
||||
* @description: 阿里云配置
|
||||
* @description: 阿里云配置-成都
|
||||
* @author: mr.jie
|
||||
* @date: 2021-07-29 17:57
|
||||
**/
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package cn.axzo.oss.integration.s3.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @program: oss
|
||||
* @description: 阿里云配置-杭州
|
||||
* @author: xudawei
|
||||
* @date: 2024-05-23
|
||||
**/
|
||||
@RefreshScope
|
||||
@Component
|
||||
public class AliOssHangZhouConfig {
|
||||
|
||||
@Value("${aliyun.oss.hangzhou.accessKeyId}")
|
||||
private String ACCESS_KEY_ID;
|
||||
|
||||
@Value("${aliyun.oss.hangzhou.secretAccessKey}")
|
||||
private String SECRET_ACCESS_KEY;
|
||||
|
||||
@Value("${aliyun.oss.hangzhou.endpoint}")
|
||||
private String ENDPOINT;
|
||||
|
||||
public String getAccessKeyId(){
|
||||
return this.ACCESS_KEY_ID;
|
||||
}
|
||||
|
||||
public String getSecretAccessKey(){
|
||||
return this.SECRET_ACCESS_KEY;
|
||||
}
|
||||
|
||||
public String getEndpoint(){
|
||||
return this.ENDPOINT;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package cn.axzo.oss.integration.s3.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @program: oss
|
||||
* @description: 阿里云配置-上海
|
||||
* @author: xudawei
|
||||
* @date: 2024-05-23
|
||||
**/
|
||||
@RefreshScope
|
||||
@Component
|
||||
public class AliOssShangHaiConfig {
|
||||
|
||||
@Value("${aliyun.oss.shanghai.accessKeyId}")
|
||||
private String ACCESS_KEY_ID;
|
||||
|
||||
@Value("${aliyun.oss.shanghai.secretAccessKey}")
|
||||
private String SECRET_ACCESS_KEY;
|
||||
|
||||
@Value("${aliyun.oss.shanghai.endpoint}")
|
||||
private String ENDPOINT;
|
||||
|
||||
public String getAccessKeyId(){
|
||||
return this.ACCESS_KEY_ID;
|
||||
}
|
||||
|
||||
public String getSecretAccessKey(){
|
||||
return this.SECRET_ACCESS_KEY;
|
||||
}
|
||||
|
||||
public String getEndpoint(){
|
||||
return this.ENDPOINT;
|
||||
}
|
||||
}
|
||||
@ -19,6 +19,7 @@ import com.aliyun.oss.model.OSSObject;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import com.aliyun.oss.model.PartETag;
|
||||
import com.aliyun.oss.model.ResponseHeaderOverrides;
|
||||
import com.aliyun.oss.model.SimplifiedObjectMeta;
|
||||
import com.aliyun.oss.model.UploadPartRequest;
|
||||
import com.aliyun.oss.model.UploadPartResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -304,7 +305,7 @@ public class AliOssServiceImpl implements AliOssService {
|
||||
log.info("aliyun downloadSignUrl result, bucketName:{}, key:{}, url:{}", bucketName, key, JsonUtil.obj2Str(url));
|
||||
return url.toString();
|
||||
} catch (Exception e) {
|
||||
log.error("aliyun downloadSignUrl result, bucketName:{}, key:{}", bucketName, key);
|
||||
log.warn("aliyun downloadSignUrl result, bucketName:{}, key:{}", bucketName, key);
|
||||
throw new BizException(CodeEnum.DOWNLOAD_SIGN_URL_FAIL);
|
||||
}
|
||||
}
|
||||
@ -343,7 +344,7 @@ public class AliOssServiceImpl implements AliOssService {
|
||||
log.info("aliyun uploadSignUrl result, bucketName:{}, key:{}, url:{}", bucketName, key, JsonUtil.obj2Str(url));
|
||||
return url.toString();
|
||||
} catch (Exception e) {
|
||||
log.info("aliyun uploadSignUrl exception, bucketName:{}, key:{}", bucketName, key, e);
|
||||
log.warn("aliyun uploadSignUrl exception, bucketName:{}, key:{}", bucketName, key, e);
|
||||
throw new BizException(UPLOAD_SIGN_URL_FAIL);
|
||||
}
|
||||
}
|
||||
@ -362,6 +363,36 @@ public class AliOssServiceImpl implements AliOssService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
@Override
|
||||
public SimplifiedObjectMeta getObjectMeta(String bucketName, String key, String url) {
|
||||
try {
|
||||
if (StringUtils.isNotBlank(url) && url.startsWith("http") && url.contains("aliyun")) {
|
||||
if (url.contains(aliOssClient.getHangZhouEndpoint())) {//杭州
|
||||
log.info("aliyun-hangzhou-getObjectMeta params, bucketName:{}, key:{},url:{}", bucketName, key, url);
|
||||
return aliOssClient.getHangZhouClient().getSimplifiedObjectMeta(bucketName, key);
|
||||
} else if (url.contains(aliOssClient.getBeiJingEndpoint())) {//北京
|
||||
log.info("aliyun-beijing-getObjectMeta params, bucketName:{}, key:{},url:{}", bucketName, key, url);
|
||||
return aliOssClient.getBeiJingClient().getSimplifiedObjectMeta(bucketName, key);
|
||||
} else if (url.contains(aliOssClient.getShangHaiEndpoint())) {//上海
|
||||
log.info("aliyun-shanghai-getObjectMeta params, bucketName:{}, key:{},url:{}", bucketName, key, url);
|
||||
return aliOssClient.getShangHaiClient().getSimplifiedObjectMeta(bucketName, key);
|
||||
} else if (url.contains(aliOssClient.getEndpoint())) {//成都
|
||||
log.info("aliyun-chengdu-getObjectMeta params, bucketName:{}, key:{},url:{}", bucketName, key, url);
|
||||
return aliOssClient.getClient().getSimplifiedObjectMeta(bucketName, key);
|
||||
}
|
||||
}
|
||||
log.info("aliyun-none-endpoint getObjectMeta params, bucketName:{}, key:{},url:{}", bucketName, key, url);
|
||||
return new SimplifiedObjectMeta();
|
||||
} catch (Exception e) {
|
||||
log.warn("aliyun getObjectMeta exception, bucketName:{}, key:{}", bucketName, key, e);
|
||||
return new SimplifiedObjectMeta();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过url上传至OSS
|
||||
*/
|
||||
|
||||
@ -2,6 +2,7 @@ package cn.axzo.oss.manager.api;
|
||||
|
||||
import cn.axzo.oss.manager.api.dto.PartETag;
|
||||
import cn.axzo.oss.manager.api.dto.request.MultipartUploadDto;
|
||||
import cn.axzo.oss.manager.api.dto.response.ManaGetObjectMetaResponse;
|
||||
import cn.axzo.oss.manager.api.vo.SignUrlUploadVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -76,6 +77,11 @@ public interface FileManager {
|
||||
*/
|
||||
String fetchDownloadUrl(String bucketName, String key, String channelCode);
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
ManaGetObjectMetaResponse getObjectMeta(String bucketName, String key, String url,String channelCode);
|
||||
|
||||
/**
|
||||
* 通过url上传至云
|
||||
*/
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
package cn.axzo.oss.manager.api.dto.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*
|
||||
* @author xudawei
|
||||
* @since 2024-05-20
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ManaGetObjectMetaResponse {
|
||||
/**
|
||||
* 桶名称
|
||||
*/
|
||||
private String bucketName;
|
||||
/**
|
||||
* 文件key
|
||||
*/
|
||||
private String key;
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
private long size;
|
||||
/**
|
||||
* url
|
||||
*/
|
||||
private String url;
|
||||
}
|
||||
@ -13,7 +13,9 @@ import cn.axzo.oss.integration.s3.HuaWeiCloudService;
|
||||
import cn.axzo.oss.manager.api.FileManager;
|
||||
import cn.axzo.oss.manager.api.dto.PartETag;
|
||||
import cn.axzo.oss.manager.api.dto.request.MultipartUploadDto;
|
||||
import cn.axzo.oss.manager.api.dto.response.ManaGetObjectMetaResponse;
|
||||
import cn.axzo.oss.manager.api.vo.SignUrlUploadVo;
|
||||
import com.aliyun.oss.model.SimplifiedObjectMeta;
|
||||
import com.obs.services.model.TemporarySignatureResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@ -253,6 +255,24 @@ public class FileManagerImpl implements FileManager {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
@Override
|
||||
public ManaGetObjectMetaResponse getObjectMeta(String bucketName, String key, String url,String channelCode) {
|
||||
ChannelTypeEnum typeEnum = ChannelTypeEnum.getChannelTypeByChannelCode(channelCode);
|
||||
switch (typeEnum) {
|
||||
case OBS:// 华为云
|
||||
return ManaGetObjectMetaResponse.builder().build();
|
||||
case OSS:// 阿里云
|
||||
SimplifiedObjectMeta simplifiedObjectMeta = aliOssService.getObjectMeta(bucketName, key, url);
|
||||
return ManaGetObjectMetaResponse.builder().bucketName(bucketName).key(key).size(simplifiedObjectMeta.getSize()).build();
|
||||
default:
|
||||
BizException.error(CodeEnum.CHANNEL_TYPE_NOT_EXIST);
|
||||
}
|
||||
return ManaGetObjectMetaResponse.builder().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过url上传至云
|
||||
*/
|
||||
|
||||
@ -16,6 +16,7 @@ import cn.axzo.oss.manager.api.dto.request.SignUrlUploadDto;
|
||||
import cn.axzo.oss.manager.api.dto.response.FileInformationResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.FindFileKeyResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.FindFileUrlResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.ManaGetObjectMetaResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.MultipartUploadInitResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.MultipartUploadResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.ServerFileDownloadResponse;
|
||||
@ -86,4 +87,9 @@ public interface FileService {
|
||||
* @param dto
|
||||
*/
|
||||
void deleteFile(DeleteFileDto dto);
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
ManaGetObjectMetaResponse getObjectMeta(String bucketName, String key, String url,String channelCode);
|
||||
}
|
||||
|
||||
@ -45,6 +45,7 @@ import cn.axzo.oss.manager.api.dto.request.SignUrlUploadDto;
|
||||
import cn.axzo.oss.manager.api.dto.response.FileInformationResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.FindFileKeyResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.FindFileUrlResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.ManaGetObjectMetaResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.MultipartUploadInitResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.MultipartUploadResponse;
|
||||
import cn.axzo.oss.manager.api.dto.response.ServerFileDownloadResponse;
|
||||
@ -1149,6 +1150,17 @@ public class FileServiceImpl implements FileService {
|
||||
fileManager.deleteFile(file.getBucketName(), tgtFileKey,file.getChannelCode());
|
||||
fileDao.deleteFile(dto.getFileKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
@Override
|
||||
public ManaGetObjectMetaResponse getObjectMeta(String bucketName, String key, String url, String channelCode) {
|
||||
log.info("getObjectMeta bucketName:{},key:{},channelCode:{}", bucketName, key, channelCode);
|
||||
Long start = System.currentTimeMillis();
|
||||
ManaGetObjectMetaResponse response = fileManager.getObjectMeta(bucketName, key, url, channelCode);
|
||||
response.setUrl(url);
|
||||
log.info("getObjectMeta response:{}, times:{}", JsonUtil.obj2Str(response), System.currentTimeMillis() - start);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user