refactor(项目管理): Minio存储路径优化

This commit is contained in:
song-tianyang 2023-11-16 11:40:42 +08:00 committed by 刘瑞斌
parent 4aea30d3ed
commit 976d458ac0
3 changed files with 41 additions and 8 deletions

View File

@ -216,7 +216,9 @@ public class FileMetadataService {
FileRequest uploadFileRequest = new FileRequest();
uploadFileRequest.setFileName(fileMetadata.getId());
uploadFileRequest.setProjectId(fileMetadata.getProjectId());
uploadFileRequest.setMainFolder(FileRequest.MAIN_FOLDER_PROJECT);
uploadFileRequest.setAppName(FileRequest.APP_NAME_FILE_MANAGEMENT);
uploadFileRequest.setSourceGroupFolder(fileMetadata.getProjectId());
uploadFileRequest.setStorage(StorageType.MINIO.name());
FileRepository minio = CommonBeanFactory.getBean(MinioRepository.class);
@ -280,7 +282,9 @@ public class FileMetadataService {
private String uploadFile(FileMetadata fileMetadata, MultipartFile file) throws Exception {
FileRequest uploadFileRequest = new FileRequest();
uploadFileRequest.setFileName(fileMetadata.getId());
uploadFileRequest.setProjectId(fileMetadata.getProjectId());
uploadFileRequest.setSourceGroupFolder(fileMetadata.getProjectId());
uploadFileRequest.setMainFolder(FileRequest.MAIN_FOLDER_PROJECT);
uploadFileRequest.setAppName(FileRequest.APP_NAME_FILE_MANAGEMENT);
uploadFileRequest.setStorage(StorageType.MINIO.name());
return fileService.upload(file, uploadFileRequest);
}
@ -320,7 +324,9 @@ public class FileMetadataService {
}
FileRequest fileRequest = new FileRequest();
fileRequest.setFileName(fileMetadata.getId());
fileRequest.setProjectId(fileMetadata.getProjectId());
fileRequest.setSourceGroupFolder(fileMetadata.getProjectId());
fileRequest.setMainFolder(FileRequest.MAIN_FOLDER_PROJECT);
fileRequest.setAppName(FileRequest.APP_NAME_FILE_MANAGEMENT);
fileRequest.setStorage(fileMetadata.getStorage());
//获取git文件下载

View File

@ -7,7 +7,30 @@ import lombok.Data;
@Data
public class FileRequest {
// 项目id
public static final String MAIN_FOLDER_SYSTEM = "system";
public static final String MAIN_FOLDER_PROJECT = "project";
public static final String MAIN_FOLDER_ORGANIZATION = "organization";
public static final String APP_NAME_FILE_MANAGEMENT = "fileManagement";
//主文件夹 取值systemprojectorganization
private String mainFolder;
/*
资源所属组目录
当mainFolder为system时这里可以是plugin存放插件
当mainFolder为project时这里可以是项目ID
可为空
*/
private String sourceGroupFolder;
/*
可以为空
取值参照fileManagementapi
*/
private String appName;
//项目ID
private String projectId;
// 存储类型

View File

@ -24,12 +24,16 @@ public class MinioRepository implements FileRepository {
private static final int BUFFER_SIZE = 8192;
private String getPath(FileRequest request) {
String mainFolder = StringUtils.isBlank(request.getMainFolder()) ? "default" : request.getMainFolder() + "/";
String appName = StringUtils.isBlank(request.getAppName()) ? StringUtils.EMPTY : (request.getAppName() + "/");
//如果sourceGroupFolder为空 取projectId
String sourceGroupFolder = StringUtils.isNotBlank(request.getSourceGroupFolder()) ? (request.getSourceGroupFolder() + "/") :
(StringUtils.isNotBlank(request.getProjectId()) ? (request.getProjectId() + "/") : StringUtils.EMPTY);
String resourceId = StringUtils.isBlank(request.getResourceId()) ? StringUtils.EMPTY : (request.getResourceId() + "/");
// 文件存储路径
return StringUtils.join(
request.getProjectId(),
"/",
StringUtils.isNotBlank(request.getResourceId()) ? request.getResourceId() + "/" : StringUtils.EMPTY,
request.getFileName());
"metersphere/", mainFolder, sourceGroupFolder, appName, resourceId, request.getFileName());
}
@Override