mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-05 05:29:29 +08:00
feat(项目管理): 限制各种途径的大于50M文件的上传
This commit is contained in:
parent
149c26f1b5
commit
66877a5043
@ -456,6 +456,8 @@ file.log.association.update=更新了关联了文件
|
||||
file.log.association.delete=取消关联了文件
|
||||
file.log.transfer.association=转存并关联了文件
|
||||
file.name.cannot.be.empty=文件名称不能为空
|
||||
file.size.is.too.large=文件过大
|
||||
file.is.empty=文件为空
|
||||
file.name.error=文件名不合法
|
||||
#file management over
|
||||
|
||||
|
@ -492,6 +492,8 @@ file.log.association.update=updated file
|
||||
file.log.association.delete=delete file
|
||||
file.log.transfer.association=transfer and association file
|
||||
file.name.cannot.be.empty=File name cannot be empty
|
||||
file.size.is.too.large=File is too large
|
||||
file.is.empty=File is empty
|
||||
file.name.error=File name error
|
||||
#file management over
|
||||
|
||||
|
@ -491,6 +491,8 @@ file.log.association.update=更新了关联了文件
|
||||
file.log.association.delete=取消关联了文件
|
||||
file.log.transfer.association=转存并关联了文件
|
||||
file.name.cannot.be.empty=文件名称不能为空
|
||||
file.size.is.too.large=文件过大
|
||||
file.is.empty=文件为空
|
||||
file.name.error=文件名不合法
|
||||
#file management over
|
||||
# template
|
||||
|
@ -492,6 +492,8 @@ file.log.association.update=更新了關聯了文件
|
||||
file.log.association.delete=取消關聯了文件
|
||||
file.log.transfer.association=轉存並關聯了文件
|
||||
file.name.cannot.be.empty=文件名稱不能為空
|
||||
file.size.is.too.large=文件過大
|
||||
file.is.empty=文件為空
|
||||
file.name.error=文件名不合法
|
||||
#file management over
|
||||
|
||||
|
@ -71,6 +71,8 @@ public class FileMetadataService {
|
||||
private FileService fileService;
|
||||
|
||||
@Value("${metersphere.file.batch-download-max:600MB}")
|
||||
private DataSize batchDownloadMaxSize;
|
||||
@Value("50MB")
|
||||
private DataSize maxFileSize;
|
||||
|
||||
public FileMetadata selectById(String id) {
|
||||
@ -123,6 +125,9 @@ public class FileMetadataService {
|
||||
}
|
||||
|
||||
public FileMetadata genFileMetadata(String filePath, String storage, long size, boolean enable, String projectId, String moduleId, String operator) {
|
||||
if (size > maxFileSize.toBytes()) {
|
||||
throw new MSException(Translator.get("file.size.is.too.large"));
|
||||
}
|
||||
String fileName = TempFileUtils.getFileNameByPath(filePath);
|
||||
FileMetadata fileMetadata = new FileMetadata();
|
||||
if (StringUtils.lastIndexOf(fileName, ".") > 0) {
|
||||
@ -401,11 +406,11 @@ public class FileMetadataService {
|
||||
}
|
||||
|
||||
if (fileSize.get() == 0) {
|
||||
throw new MSException(Translator.get("file.size.is.zero"));
|
||||
throw new MSException(Translator.get("file.is.empty"));
|
||||
}
|
||||
|
||||
DataSize dataSize = DataSize.ofBytes(fileSize.get());
|
||||
if (maxFileSize.compareTo(dataSize) < 0) {
|
||||
if (batchDownloadMaxSize.compareTo(dataSize) < 0) {
|
||||
throw new MSException(Translator.get("file.size.is.too.large"));
|
||||
}
|
||||
}
|
||||
|
@ -573,6 +573,17 @@ public class FileManagementControllerTests extends BaseTest {
|
||||
paramMap.add("request", JSON.toJSONString(fileUploadRequest));
|
||||
this.requestMultipart(FileManagementRequestUtils.URL_FILE_UPLOAD, paramMap).andExpect(status().is5xxServerError());
|
||||
|
||||
//上传大于50M的文件
|
||||
filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/largeFile.zip")).getPath();
|
||||
file = new MockMultipartFile("file", "largeFile.zip", MediaType.APPLICATION_OCTET_STREAM_VALUE, FileManagementBaseUtils.getFileBytes(filePath));
|
||||
fileUploadRequest = new FileUploadRequest();
|
||||
fileUploadRequest.setProjectId(project.getId());
|
||||
fileUploadRequest.setModuleId(ModuleConstants.DEFAULT_NODE_ID);
|
||||
paramMap = new LinkedMultiValueMap<>();
|
||||
paramMap.add("file", file);
|
||||
paramMap.add("request", JSON.toJSONString(fileUploadRequest));
|
||||
|
||||
this.requestMultipart(FileManagementRequestUtils.URL_FILE_UPLOAD, paramMap).andExpect(status().is5xxServerError());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user