Merge branch 'hotfix/person_avatar_add_process_style' into 'master'
Hotfix/person avatar add process style See merge request universal/infrastructure/backend/oss!139
This commit is contained in:
commit
d432f08e4b
@ -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.ServerFileUploadRequest;
|
||||
import cn.axzo.oss.http.model.ServerFileUploadResponse;
|
||||
@ -23,16 +31,23 @@ import cn.axzo.oss.manager.api.dto.request.ServerFileDeleteDto;
|
||||
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.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
|
||||
@ -127,4 +142,41 @@ public class ServerFileController implements ServerFileServiceApi {
|
||||
ContextInfo.LiteSaasContext liteSaasContext = JSONUtil.toBean(contextInfoLiteJsonStr, ContextInfo.LiteSaasContext.class);
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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.ServerFileUploadRequest;
|
||||
import cn.axzo.oss.http.model.ServerFileUploadResponse;
|
||||
@ -82,4 +86,16 @@ 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);
|
||||
|
||||
}
|
||||
|
||||
@ -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,4 +30,9 @@ public interface AliOssService extends BaseS3Service {
|
||||
* 获取url
|
||||
*/
|
||||
String getUrl(String bucketName, String tgtFileKey);
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
SimplifiedObjectMeta getObjectMeta(String bucketName, String key);
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -359,4 +360,19 @@ public class AliOssServiceImpl implements AliOssService {
|
||||
throw new BizException(CodeEnum.DELETE_FILE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
@Override
|
||||
public SimplifiedObjectMeta getObjectMeta(String bucketName, String key) {
|
||||
try {
|
||||
log.info("aliyun getObjectMeta params, bucketName:{}, key:{}", bucketName, key);
|
||||
return aliOssClient.getClient().getSimplifiedObjectMeta(bucketName, key);
|
||||
} catch (Exception e) {
|
||||
log.error("aliyun getObjectMeta exception, bucketName:{}, key:{}", bucketName, key, e);
|
||||
return new SimplifiedObjectMeta();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -75,4 +76,9 @@ public interface FileManager {
|
||||
* 根据华为云/阿里云,授权给第三方下载
|
||||
*/
|
||||
String fetchDownloadUrl(String bucketName, String key, String channelCode);
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
ManaGetObjectMetaResponse getObjectMeta(String bucketName, String key, String channelCode);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -252,4 +254,22 @@ public class FileManagerImpl implements FileManager {
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 元数据
|
||||
*/
|
||||
@Override
|
||||
public ManaGetObjectMetaResponse getObjectMeta(String bucketName, String key, String channelCode) {
|
||||
ChannelTypeEnum typeEnum = ChannelTypeEnum.getChannelTypeByChannelCode(channelCode);
|
||||
switch (typeEnum) {
|
||||
case OBS:// 华为云
|
||||
return ManaGetObjectMetaResponse.builder().build();
|
||||
case OSS:// 阿里云
|
||||
SimplifiedObjectMeta simplifiedObjectMeta = aliOssService.getObjectMeta(bucketName, key);
|
||||
return ManaGetObjectMetaResponse.builder().bucketName(bucketName).key(key).size(simplifiedObjectMeta.getSize()).build();
|
||||
default:
|
||||
BizException.error(CodeEnum.CHANNEL_TYPE_NOT_EXIST);
|
||||
}
|
||||
return ManaGetObjectMetaResponse.builder().build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -1128,6 +1129,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, 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