Merge branch 'feature/REQ-2599' into 'master'
[REQ-2599]查找根据file中的桶查询原文件,而非appCode See merge request universal/infrastructure/backend/oss!155
This commit is contained in:
commit
119a11be52
@ -75,7 +75,7 @@ public class ControllerExceptionHandler {
|
|||||||
|
|
||||||
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||||
public CommonResponse handleArgumentValidException(MethodArgumentNotValidException e){
|
public CommonResponse handleArgumentValidException(MethodArgumentNotValidException e){
|
||||||
log.warn("[oss] ControllerExceptionHandler.handleArgumentValidException Exception", e.getMessage());
|
log.warn("[oss] ControllerExceptionHandler.handleArgumentValidException Exception", e);
|
||||||
BindingResult bindingResult = e.getBindingResult();
|
BindingResult bindingResult = e.getBindingResult();
|
||||||
StringBuilder errorMsg = new StringBuilder();
|
StringBuilder errorMsg = new StringBuilder();
|
||||||
for (FieldError fieldError : bindingResult.getFieldErrors()) {
|
for (FieldError fieldError : bindingResult.getFieldErrors()) {
|
||||||
|
|||||||
@ -18,12 +18,11 @@ public class ServerFileCopyToDictRequest {
|
|||||||
private String appCode;
|
private String appCode;
|
||||||
@NotBlank(message = "bizScene must not be null")
|
@NotBlank(message = "bizScene must not be null")
|
||||||
private String bizScene;
|
private String bizScene;
|
||||||
@NotBlank(message = "fileName must not be null")
|
|
||||||
|
|
||||||
@NotNull(message = "fileKey must not be null")
|
@NotNull(message = "fileKey must not be null")
|
||||||
private String fileKey;
|
private String fileKey;
|
||||||
|
|
||||||
@NotNull(message = "fileKey must not be null")
|
@NotNull(message = "targetDict must not be null")
|
||||||
private String targetDict;
|
private String targetDict;
|
||||||
|
|
||||||
private Integer channelCode;
|
private Integer channelCode;
|
||||||
|
|||||||
@ -7,18 +7,21 @@ import cn.axzo.oss.dal.entity.FileUploadConfig;
|
|||||||
import cn.axzo.oss.dal.repository.FileDao;
|
import cn.axzo.oss.dal.repository.FileDao;
|
||||||
import cn.axzo.oss.manager.api.FileManager;
|
import cn.axzo.oss.manager.api.FileManager;
|
||||||
import cn.axzo.oss.manager.api.dto.request.ServerFileCopyToDictDto;
|
import cn.axzo.oss.manager.api.dto.request.ServerFileCopyToDictDto;
|
||||||
|
import cn.axzo.oss.manager.api.dto.request.SignUrlDownloadDto;
|
||||||
import cn.axzo.oss.manager.api.dto.response.ManaGetObjectMetaResponse;
|
import cn.axzo.oss.manager.api.dto.response.ManaGetObjectMetaResponse;
|
||||||
import cn.axzo.oss.manager.api.dto.response.SignUrlDownloadResponse;
|
import cn.axzo.oss.manager.api.dto.response.SignUrlDownloadResponse;
|
||||||
import cn.axzo.oss.service.api.FileCopyToDictService;
|
import cn.axzo.oss.service.api.FileCopyToDictService;
|
||||||
import cn.axzo.oss.service.api.FileService;
|
import cn.axzo.oss.service.api.FileService;
|
||||||
import cn.hutool.core.lang.Pair;
|
import cn.hutool.core.lang.Pair;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,19 +60,32 @@ public class FileCopyToDictServiceImpl implements FileCopyToDictService {
|
|||||||
String targetFileKey = Utility.generateFileKey(fileUploadConfig.getDirectory() + "_" + dto.getTargetDict(), dto.getFileKey(), byFileUuid.getFileFormat());
|
String targetFileKey = Utility.generateFileKey(fileUploadConfig.getDirectory() + "_" + dto.getTargetDict(), dto.getFileKey(), byFileUuid.getFileFormat());
|
||||||
|
|
||||||
//3 获取下载文件url(支持:公有桶/私有桶)
|
//3 获取下载文件url(支持:公有桶/私有桶)
|
||||||
SignUrlDownloadResponse downloadResponse = this.fileManager.fetchDownloadUrl(appChannelBucket.getBucketType(), fileUploadConfig.getBucketName(), sourceFileKey
|
// SignUrlDownloadResponse downloadResponse = this.fileManager.fetchDownloadUrl(appChannelBucket.getBucketType(), fileUploadConfig.getBucketName(), sourceFileKey
|
||||||
, fileUploadConfig.getChannelCode(), SIGN_URL_DOWNLOAD_EXPIRE_SECOND, byFileUuid.getFileName(), null, false);
|
// , fileUploadConfig.getChannelCode(), SIGN_URL_DOWNLOAD_EXPIRE_SECOND, byFileUuid.getFileName(), null, false);
|
||||||
|
String downloadSignUrl = this.fetchSignUrlByFileKey(dto.getFileKey(), null);
|
||||||
|
|
||||||
//4 获取文件元信息(此时主要文件大小)
|
//4 获取文件元信息(此时主要文件大小)
|
||||||
ManaGetObjectMetaResponse objectMeta = fileService.getObjectMeta(appChannelBucket.getBucketName(), sourceFileKey, downloadResponse.getSignUrl(), appChannelBucket.getChannelCode());
|
ManaGetObjectMetaResponse objectMeta = fileService.getObjectMeta(byFileUuid.getBucketName(), sourceFileKey, downloadSignUrl, byFileUuid.getChannelCode());
|
||||||
|
|
||||||
//文件大小没有达到maxFileSize,则不用裁剪
|
//文件大小没有达到maxFileSize,则不用裁剪
|
||||||
if (Objects.nonNull(dto.getMaxFileSize()) && !Objects.equals(dto.getMaxFileSize(), 0) && !Objects.equals(objectMeta.getSize(), 0)&& objectMeta.getSize() > dto.getMaxFileSize()) {
|
if (Objects.nonNull(dto.getMaxFileSize()) && !Objects.equals(dto.getMaxFileSize(), 0) && !Objects.equals(objectMeta.getSize(), 0)&& objectMeta.getSize() > dto.getMaxFileSize()) {
|
||||||
//5 重新获取下载文件url(支持:公有桶/私有桶)
|
//5 重新获取下载文件url(支持:公有桶/私有桶)
|
||||||
downloadResponse = this.fileManager.fetchDownloadUrl(appChannelBucket.getBucketType(), fileUploadConfig.getBucketName(), sourceFileKey
|
// downloadResponse = this.fileManager.fetchDownloadUrl(appChannelBucket.getBucketType(), fileUploadConfig.getBucketName(), sourceFileKey
|
||||||
, fileUploadConfig.getChannelCode(), SIGN_URL_DOWNLOAD_EXPIRE_SECOND, byFileUuid.getFileName(), dto.getStyle(), false);
|
// , fileUploadConfig.getChannelCode(), SIGN_URL_DOWNLOAD_EXPIRE_SECOND, byFileUuid.getFileName(), dto.getStyle(), false);
|
||||||
|
downloadSignUrl = this.fetchSignUrlByFileKey(dto.getFileKey(), dto.getStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
//6 上传至指定目录
|
//6 上传至指定目录
|
||||||
this.fileManager.uploadByUrl(fileUploadConfig.getBucketName(), targetFileKey, byFileUuid.getFileName(), downloadResponse.getSignUrl(), fileUploadConfig.getChannelCode());
|
this.fileManager.uploadByUrl(fileUploadConfig.getBucketName(), targetFileKey, byFileUuid.getFileName(), downloadSignUrl, fileUploadConfig.getChannelCode());
|
||||||
|
log.info("copyToDict-end,targetFileKey:{}", targetFileKey);
|
||||||
return targetFileKey;
|
return targetFileKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String fetchSignUrlByFileKey(String fileKey, String style) {
|
||||||
|
SignUrlDownloadDto signUrlDownloadDto = new SignUrlDownloadDto();
|
||||||
|
signUrlDownloadDto.setFileKeys(Lists.newArrayList(fileKey));
|
||||||
|
signUrlDownloadDto.setStyle(style);
|
||||||
|
List<SignUrlDownloadResponse> responseList = this.fileService.signUrlDownload(signUrlDownloadDto);
|
||||||
|
return responseList.get(0).getSignUrl();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user