feat:(REQ-3560) 获取下载文件加上文件大小

This commit is contained in:
xudawei 2025-04-10 14:20:22 +08:00
parent 215845e73a
commit 89a2ce5a5d
4 changed files with 31 additions and 0 deletions

View File

@ -7,6 +7,8 @@ import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@ -149,4 +151,21 @@ public class File extends Model<File> {
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;
}
}

View File

@ -29,4 +29,9 @@ public class ApiSignUrlDownloadResponse {
*/
private String fileName;
/**
* 文件大小
*/
private Long fileSize;
}

View File

@ -30,4 +30,9 @@ public class SignUrlDownloadResponse {
*/
private String fileName;
/**
* 文件大小
*/
private Long fileSize;
}

View File

@ -981,6 +981,7 @@ public class FileServiceImpl implements FileService {
.signUrl(this.fileManager.buildPublicXImageProcess(url, style))
.fileKey(item.getFileUuid())
.fileName(item.getFileName())
.fileSize(item.fetchFileSize())
.build();
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);
@ -988,6 +989,7 @@ public class FileServiceImpl implements FileService {
.signUrl(UrlUtil.httpToHttps(signUrl))
.fileKey(item.getFileUuid())
.fileName(item.getFileName())
.fileSize(item.fetchFileSize())
.build();
default:
BizException.error(CodeEnum.CHANNEL_TYPE_NOT_EXIST);