Merge branch 'master' into feature/REQ-3540
This commit is contained in:
commit
02d056b5d9
@ -65,6 +65,7 @@ public enum CodeEnum implements EnumBase<Integer> {
|
|||||||
URL_BUCKET_NAME_KEY_ALL_EMPTY(508, "url-bucketName-key同时为空"),
|
URL_BUCKET_NAME_KEY_ALL_EMPTY(508, "url-bucketName-key同时为空"),
|
||||||
SIGN_URL_DOWNLOAD_FILEKEYS_EXCEEDS_MAXSIZE(509, "fileKeys exceeds the maximum size"),
|
SIGN_URL_DOWNLOAD_FILEKEYS_EXCEEDS_MAXSIZE(509, "fileKeys exceeds the maximum size"),
|
||||||
FILE_TARGET_APP_IS_EMPTY(510, "target app is empty"),
|
FILE_TARGET_APP_IS_EMPTY(510, "target app is empty"),
|
||||||
|
CHANNELCODE_DIFF(511, "云通道不同"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Integer code;
|
private final Integer code;
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import java.util.Date;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
@ -149,4 +151,21 @@ public class File extends Model<File> {
|
|||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long fetchFileSize() {
|
||||||
|
if (Objects.isNull(this.getStorageSize()) || Objects.isNull(this.getStorageUnit())) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getStorageUnit().equalsIgnoreCase("b")) {
|
||||||
|
return this.getStorageSize().longValue();
|
||||||
|
}
|
||||||
|
if (this.getStorageUnit().equalsIgnoreCase("kb")) {
|
||||||
|
return this.getStorageSize().longValue() * 1024L;
|
||||||
|
}
|
||||||
|
if (this.getStorageUnit().equalsIgnoreCase("mb")) {
|
||||||
|
return this.getStorageSize().longValue() * 1024 * 1024L;
|
||||||
|
}
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,4 +29,9 @@ public class ApiSignUrlDownloadResponse {
|
|||||||
*/
|
*/
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件大小
|
||||||
|
*/
|
||||||
|
private Long storageSize;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,37 +52,11 @@ public class ServerFileBatchCopyObjectRequest {
|
|||||||
@NotBlank(message = "唯一性标识不能为空")
|
@NotBlank(message = "唯一性标识不能为空")
|
||||||
private String fileUuid;
|
private String fileUuid;
|
||||||
|
|
||||||
/**
|
|
||||||
* 目标桶
|
|
||||||
* 如果目标桶为空,则默认取源桶
|
|
||||||
*/
|
|
||||||
private String targetBucketName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 目标目录
|
|
||||||
* 如果目标目录为空,则默认在源目录同级
|
|
||||||
*/
|
|
||||||
private String targetDict;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 目标通道
|
|
||||||
* 如果目标通道为空,则默认源通道
|
|
||||||
*/
|
|
||||||
private String targetChannelCode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件名称(包含后缀)
|
* 文件名称(包含后缀)
|
||||||
*/
|
*/
|
||||||
private String targetFileName;
|
private String targetFileName;
|
||||||
|
|
||||||
/**
|
|
||||||
* 桶名称
|
|
||||||
*/
|
|
||||||
private String srcBucketName;
|
|
||||||
/**
|
|
||||||
* 桶文件路径(目录+文件)
|
|
||||||
*/
|
|
||||||
private String srcBucketKey;
|
|
||||||
/**
|
/**
|
||||||
* 文件对象key
|
* 文件对象key
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -73,14 +73,30 @@ public class CopyObjectCloudDto {
|
|||||||
|
|
||||||
public static CopyObjectCloudDto create(FileCopyObjectDto fileCopyObjectRequest, File file, FileBusinessScene fileBusinessScene,FileBusinessScene targetFileBiz) {
|
public static CopyObjectCloudDto create(FileCopyObjectDto fileCopyObjectRequest, File file, FileBusinessScene fileBusinessScene,FileBusinessScene targetFileBiz) {
|
||||||
// 入参中有通道,则优先取入参;否则取源通道
|
// 入参中有通道,则优先取入参;否则取源通道
|
||||||
String targetChannelCode = StringUtils.isBlank(fileCopyObjectRequest.getTargetChannelCode()) ? fileBusinessScene.getChannelCode() : fileCopyObjectRequest.getTargetChannelCode();
|
String targetChannelCode = fileBusinessScene.getChannelCode();
|
||||||
String targetBucketName = StringUtils.isBlank(fileCopyObjectRequest.getTargetBucketName()) ? fileBusinessScene.getBucketName() : fileCopyObjectRequest.getTargetBucketName();
|
String targetBucketName = fileBusinessScene.getBucketName();
|
||||||
String targetBucketDict = StringUtils.isBlank(fileCopyObjectRequest.getTargetDict()) ? fileBusinessScene.getDirectory() : fileCopyObjectRequest.getTargetDict();
|
String targetBucketDict = fileBusinessScene.getDirectory();
|
||||||
String fileName = StringUtils.isBlank(fileCopyObjectRequest.getTargetFileName()) ? file.getFileName() : fileCopyObjectRequest.getTargetFileName();
|
String appCode = fileBusinessScene.getAppCode();
|
||||||
|
String appChannelBucketNo = fileBusinessScene.getAppChannelBucketNo();
|
||||||
String appCode = (Objects.isNull(targetFileBiz) || StringUtils.isBlank(targetFileBiz.getAppCode())) ? fileBusinessScene.getAppCode() : targetFileBiz.getAppCode();
|
|
||||||
String appChannelBucketNo = (Objects.isNull(targetFileBiz) || StringUtils.isBlank(targetFileBiz.getAppChannelBucketNo())) ? fileBusinessScene.getAppChannelBucketNo() : targetFileBiz.getAppChannelBucketNo();
|
|
||||||
|
|
||||||
|
if (Objects.nonNull(targetFileBiz)) {
|
||||||
|
if (StringUtils.isNotBlank(targetFileBiz.getChannelCode())) {
|
||||||
|
targetChannelCode = targetFileBiz.getChannelCode();
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(targetFileBiz.getBucketName())) {
|
||||||
|
targetBucketName = targetFileBiz.getBucketName();
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(targetFileBiz.getDirectory())) {
|
||||||
|
targetBucketDict = targetFileBiz.getDirectory();
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(targetFileBiz.getAppCode())) {
|
||||||
|
appCode = targetFileBiz.getAppCode();
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(targetFileBiz.getAppChannelBucketNo())) {
|
||||||
|
appChannelBucketNo = targetFileBiz.getAppChannelBucketNo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String fileName = StringUtils.isNotBlank(fileCopyObjectRequest.getTargetFileName()) ? fileCopyObjectRequest.getTargetFileName() : file.getFileName();
|
||||||
String uuid = Utility.getUUID();
|
String uuid = Utility.getUUID();
|
||||||
|
|
||||||
return CopyObjectCloudDto.builder()
|
return CopyObjectCloudDto.builder()
|
||||||
|
|||||||
@ -30,4 +30,9 @@ public class SignUrlDownloadResponse {
|
|||||||
*/
|
*/
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件大小
|
||||||
|
*/
|
||||||
|
private Long storageSize;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -357,13 +357,10 @@ public class FileManagerImpl implements FileManager {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean copyObjects(CopyObjectCloudDto dto) {
|
public Boolean copyObjects(CopyObjectCloudDto dto) {
|
||||||
|
//不同的通道不能复制
|
||||||
|
BizException.error(Objects.equals(dto.getSrcChannelCode(), dto.getTargetChannelCode()), CodeEnum.CHANNELCODE_DIFF);
|
||||||
// 相同的通道-对象复制
|
// 相同的通道-对象复制
|
||||||
if (dto.getSrcChannelCode().equals(dto.getTargetChannelCode())) {
|
return this.copyObjectWhenSameChannel(dto);
|
||||||
return this.copyObjectWhenSameChannel(dto);
|
|
||||||
}
|
|
||||||
// 不同的通道,通过url上传至云(通过url复制至云)
|
|
||||||
String url = this.uploadByUrl(dto.getTargetBucketName(), dto.getTargetKey(), dto.getTargetFileName(), dto.getSrcUrl(), dto.getTargetChannelCode());
|
|
||||||
return StringUtils.isBlank(url) ? false : true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -981,6 +981,7 @@ public class FileServiceImpl implements FileService {
|
|||||||
.signUrl(this.fileManager.buildPublicXImageProcess(url, style))
|
.signUrl(this.fileManager.buildPublicXImageProcess(url, style))
|
||||||
.fileKey(item.getFileUuid())
|
.fileKey(item.getFileUuid())
|
||||||
.fileName(item.getFileName())
|
.fileName(item.getFileName())
|
||||||
|
.storageSize(item.fetchFileSize())
|
||||||
.build();
|
.build();
|
||||||
case PRIVATE_BUCKET://私有桶 - 临时授权链接 例如 http://xxx.png?Expire=a&AccessKeyId=b&Signature=c&repsonse-content-disposition=d
|
case PRIVATE_BUCKET://私有桶 - 临时授权链接 例如 http://xxx.png?Expire=a&AccessKeyId=b&Signature=c&repsonse-content-disposition=d
|
||||||
String signUrl = this.fileManager.signUrlDownload(item.getBucketName(), tgtFileKey, Objects.nonNull(expire) ? expire : SIGN_URL_DOWNLOAD_EXPIRE_SECOND , item.getChannelCode(), item.getFileName(), style, hasFileName);
|
String signUrl = this.fileManager.signUrlDownload(item.getBucketName(), tgtFileKey, Objects.nonNull(expire) ? expire : SIGN_URL_DOWNLOAD_EXPIRE_SECOND , item.getChannelCode(), item.getFileName(), style, hasFileName);
|
||||||
@ -988,6 +989,7 @@ public class FileServiceImpl implements FileService {
|
|||||||
.signUrl(UrlUtil.httpToHttps(signUrl))
|
.signUrl(UrlUtil.httpToHttps(signUrl))
|
||||||
.fileKey(item.getFileUuid())
|
.fileKey(item.getFileUuid())
|
||||||
.fileName(item.getFileName())
|
.fileName(item.getFileName())
|
||||||
|
.storageSize(item.fetchFileSize())
|
||||||
.build();
|
.build();
|
||||||
default:
|
default:
|
||||||
BizException.error(CodeEnum.CHANNEL_TYPE_NOT_EXIST);
|
BizException.error(CodeEnum.CHANNEL_TYPE_NOT_EXIST);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user