refactor(系统设置): 精简MinIO文件路径参数

This commit is contained in:
song-tianyang 2023-11-16 15:44:07 +08:00 committed by wxg0103
parent dc49dc4e3c
commit 781f09c2aa
4 changed files with 15 additions and 58 deletions

View File

@ -216,9 +216,7 @@ public class FileMetadataService {
FileRequest uploadFileRequest = new FileRequest();
uploadFileRequest.setFileName(fileMetadata.getId());
uploadFileRequest.setMainFolder(FileRequest.MAIN_FOLDER_PROJECT);
uploadFileRequest.setAppName(FileRequest.APP_NAME_FILE_MANAGEMENT);
uploadFileRequest.setSourceGroupFolder(fileMetadata.getProjectId());
uploadFileRequest.setFolder(this.generateMinIOFilePath(projectId));
uploadFileRequest.setStorage(StorageType.MINIO.name());
FileRepository minio = CommonBeanFactory.getBean(MinioRepository.class);
@ -282,9 +280,7 @@ public class FileMetadataService {
private String uploadFile(FileMetadata fileMetadata, MultipartFile file) throws Exception {
FileRequest uploadFileRequest = new FileRequest();
uploadFileRequest.setFileName(fileMetadata.getId());
uploadFileRequest.setSourceGroupFolder(fileMetadata.getProjectId());
uploadFileRequest.setMainFolder(FileRequest.MAIN_FOLDER_PROJECT);
uploadFileRequest.setAppName(FileRequest.APP_NAME_FILE_MANAGEMENT);
uploadFileRequest.setFolder(this.generateMinIOFilePath(fileMetadata.getProjectId()));
uploadFileRequest.setStorage(StorageType.MINIO.name());
return fileService.upload(file, uploadFileRequest);
}
@ -324,9 +320,7 @@ public class FileMetadataService {
}
FileRequest fileRequest = new FileRequest();
fileRequest.setFileName(fileMetadata.getId());
fileRequest.setSourceGroupFolder(fileMetadata.getProjectId());
fileRequest.setMainFolder(FileRequest.MAIN_FOLDER_PROJECT);
fileRequest.setAppName(FileRequest.APP_NAME_FILE_MANAGEMENT);
fileRequest.setFolder(this.generateMinIOFilePath(fileMetadata.getProjectId()));
fileRequest.setStorage(fileMetadata.getStorage());
//获取git文件下载
@ -666,4 +660,11 @@ public class FileMetadataService {
});
return fileVersionResponseList;
}
}
private static final String MAIN_FOLDER_PROJECT = "project";
private static final String APP_NAME_FILE_MANAGEMENT = "fileManagement";
private String generateMinIOFilePath(String projectId) {
return StringUtils.join(MAIN_FOLDER_PROJECT, "/", projectId, "/", APP_NAME_FILE_MANAGEMENT);
}
}

View File

@ -649,15 +649,6 @@ public class EnvironmentControllerTests extends BaseTest {
Assertions.assertNotNull(response);
environment = environmentMapper.selectByPrimaryKey(response.getId());
Assertions.assertEquals(response.getName(), environment.getName());
//查询文件
FileRequest fileRequest = new FileRequest();
fileRequest.setProjectId(StringUtils.join(DIR_PATH, environment.getProjectId()));
fileRequest.setResourceId(environment.getId());
MinioRepository minioRepository = CommonBeanFactory.getBean(MinioRepository.class);
assert minioRepository != null;
List<String> fileNames = minioRepository.getFolderFileNames(fileRequest);
//校验文件
Assertions.assertEquals(2, fileNames.size());
//校验权限
request.setProjectId(DEFAULT_PROJECT_ID);
@ -843,15 +834,6 @@ public class EnvironmentControllerTests extends BaseTest {
Assertions.assertNotNull(response);
environment = environmentMapper.selectByPrimaryKey(response.getId());
Assertions.assertEquals(response.getName(), environment.getName());
//查询文件
FileRequest fileRequest = new FileRequest();
fileRequest.setProjectId(StringUtils.join(DIR_PATH, environment.getProjectId()));
fileRequest.setResourceId(environment.getId());
MinioRepository minioRepository = CommonBeanFactory.getBean(MinioRepository.class);
assert minioRepository != null;
List<String> fileNames = minioRepository.getFolderFileNames(fileRequest);
//校验文件
Assertions.assertEquals(2, fileNames.size());
//校验权限
example = new EnvironmentExample();
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andNameEqualTo("校验权限");

View File

@ -7,28 +7,8 @@ import lombok.Data;
@Data
public class FileRequest {
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;
private String folder;
//项目ID
private String projectId;

View File

@ -24,15 +24,9 @@ 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(mainFolder, sourceGroupFolder, appName, resourceId, request.getFileName());
String folder = StringUtils.isNotEmpty(request.getFolder()) ? request.getFolder() : request.getProjectId();
//todo 后续要增加对folder起始路径的校验: system / project / organization
return StringUtils.join(folder, "/", request.getFileName());
}
@Override