mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-10 19:00:53 +08:00
Merge branch 'dev' of https://gitee.com/continew/continew-admin into 3.4.x
This commit is contained in:
@@ -79,7 +79,7 @@ public class FileRecorderImpl implements FileRecorder {
|
||||
return null;
|
||||
}
|
||||
StorageDO storageDO = storageMapper.lambdaQuery().eq(StorageDO::getId, file.getStorageId()).one();
|
||||
return file.toFileInfo(storageDO.getCode(),storageDO.getBucketName());
|
||||
return file.toFileInfo(storageDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -22,6 +22,7 @@ import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
import org.dromara.x.file.storage.core.FileInfo;
|
||||
import top.continew.admin.system.enums.FileTypeEnum;
|
||||
import top.continew.admin.system.enums.StorageTypeEnum;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
import top.continew.starter.core.util.StrUtils;
|
||||
import top.continew.starter.extension.crud.model.entity.BaseDO;
|
||||
@@ -85,11 +86,10 @@ public class FileDO extends BaseDO {
|
||||
/**
|
||||
* 转换为 X-File-Storage 文件信息对象
|
||||
*
|
||||
* @param storageCode 存储编码
|
||||
* @param bucketName 桶名称
|
||||
* @param storageDO 存储桶信息
|
||||
* @return X-File-Storage 文件信息对象
|
||||
*/
|
||||
public FileInfo toFileInfo(String storageCode,String bucketName) {
|
||||
public FileInfo toFileInfo(StorageDO storageDO) {
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
fileInfo.setUrl(this.url);
|
||||
fileInfo.setSize(this.size);
|
||||
@@ -100,10 +100,10 @@ public class FileDO extends BaseDO {
|
||||
.blankToDefault(this.extension, this.name, ex -> this.name + StringConstants.DOT + ex));
|
||||
fileInfo.setBasePath(StringConstants.EMPTY);
|
||||
// 优化 path 处理
|
||||
fileInfo.setPath(extractRelativePath(this.url,bucketName));
|
||||
fileInfo.setPath(extractRelativePath(this.url,storageDO));
|
||||
|
||||
fileInfo.setExt(this.extension);
|
||||
fileInfo.setPlatform(storageCode);
|
||||
fileInfo.setPlatform(storageDO.getCode());
|
||||
fileInfo.setThUrl(this.thumbnailUrl);
|
||||
fileInfo.setThFilename(StrUtil.contains(this.thumbnailUrl, StringConstants.SLASH)
|
||||
? StrUtil.subAfter(this.thumbnailUrl, StringConstants.SLASH, true)
|
||||
@@ -116,14 +116,17 @@ public class FileDO extends BaseDO {
|
||||
* 将文件路径处理成资源路径
|
||||
* 例如:
|
||||
* http://domain.cn/bucketName/2024/11/27/6746ec3b2907f0de80afdd70.png => 2024/11/27/
|
||||
* http://bucketName.damain.cn/2024/11/27/6746ec3b2907f0de80afdd70.png => 2024/11/27/
|
||||
* http://bucketName.domain.cn/2024/11/27/6746ec3b2907f0de80afdd70.png => 2024/11/27/
|
||||
* @param url 文件路径
|
||||
* @param bucketName 桶名称
|
||||
* @param storageDO 存储桶信息
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
private static String extractRelativePath(String url, String bucketName) {
|
||||
private static String extractRelativePath(String url, StorageDO storageDO) {
|
||||
url = StrUtil.subBefore(url, StringConstants.SLASH, true) + StringConstants.SLASH;
|
||||
if (storageDO.getType().equals(StorageTypeEnum.LOCAL)){
|
||||
return url;
|
||||
}
|
||||
// 提取 URL 中的路径部分
|
||||
String fullPath = new URL(url).getPath();
|
||||
// 移除开头的斜杠
|
||||
@@ -131,8 +134,8 @@ public class FileDO extends BaseDO {
|
||||
? fullPath.substring(1)
|
||||
: fullPath;
|
||||
// 如果路径以 bucketName 开头,则移除 bucketName 例如: bucketName/2024/11/27/ -> 2024/11/27/
|
||||
if (relativePath.startsWith(bucketName)) {
|
||||
return StrUtil.split(relativePath, bucketName).get(1);
|
||||
if (relativePath.startsWith(storageDO.getBucketName())) {
|
||||
return StrUtil.split(relativePath, storageDO.getBucketName()).get(1);
|
||||
}
|
||||
return relativePath;
|
||||
}
|
||||
|
@@ -73,7 +73,7 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
|
||||
for (Map.Entry<Long, List<FileDO>> entry : fileListGroup.entrySet()) {
|
||||
StorageDO storage = storageService.getById(entry.getKey());
|
||||
for (FileDO file : entry.getValue()) {
|
||||
FileInfo fileInfo = file.toFileInfo(storage.getCode(),storage.getBucketName());
|
||||
FileInfo fileInfo = file.toFileInfo(storage);
|
||||
fileStorageService.delete(fileInfo);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user