feat: 将工作流与 FAQ 上传上限扩至 20MB
- 同步管理端、用户中心与后端工作流文件校验 - 扩展 FAQ 普通及分享上传限制并补充边界测试
This commit is contained in:
@@ -35,7 +35,7 @@ public class WorkflowRunningParameterResolver {
|
||||
private static final String DEFAULT_START_FORM_DESCRIPTION = "请先补充必要信息,再开始执行工作流。";
|
||||
private static final String DEFAULT_START_FORM_SUBMIT_TEXT = "开始";
|
||||
private static final int FILE_MAX_COUNT = 10;
|
||||
private static final long FILE_MAX_SINGLE_SIZE = 5L * 1024 * 1024;
|
||||
private static final long FILE_MAX_SINGLE_SIZE = 20L * 1024 * 1024;
|
||||
private static final long FILE_MAX_TOTAL_SIZE = 50L * 1024 * 1024;
|
||||
|
||||
@Resource
|
||||
@@ -363,7 +363,7 @@ public class WorkflowRunningParameterResolver {
|
||||
}
|
||||
Long size = parseLong(fileMap.get("size"));
|
||||
if (size != null && size > FILE_MAX_SINGLE_SIZE) {
|
||||
throw new BusinessException("文件参数 " + parameterName + " 中单个文件不能超过 5MB");
|
||||
throw new BusinessException("文件参数 " + parameterName + " 中单个文件不能超过 20MB");
|
||||
}
|
||||
if (size != null && size > 0) {
|
||||
totalSize += size;
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.Set;
|
||||
@Component
|
||||
public class DocNodeFileContentExtractor {
|
||||
private static final int FILE_MAX_COUNT = 10;
|
||||
private static final long FILE_MAX_SINGLE_SIZE = 5L * 1024 * 1024;
|
||||
private static final long FILE_MAX_SINGLE_SIZE = 20L * 1024 * 1024;
|
||||
private static final long FILE_MAX_TOTAL_SIZE = 50L * 1024 * 1024;
|
||||
|
||||
private final DocumentParseBridgeService documentParseBridgeService;
|
||||
@@ -145,7 +145,7 @@ public class DocNodeFileContentExtractor {
|
||||
}
|
||||
Long size = sourceRef.getSize();
|
||||
if (size != null && size > FILE_MAX_SINGLE_SIZE) {
|
||||
throw new BusinessException("单个文件不能超过 5MB: " + sourceRef.getFileName());
|
||||
throw new BusinessException("单个文件不能超过 20MB: " + sourceRef.getFileName());
|
||||
}
|
||||
if (size != null && size > 0) {
|
||||
totalSize += size;
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.junit.Test;
|
||||
import tech.easyflow.ai.entity.Workflow;
|
||||
import tech.easyflow.ai.node.SearchDatasetNodeParser;
|
||||
import tech.easyflow.ai.node.WorkflowNodeParser;
|
||||
import tech.easyflow.common.web.exceptions.BusinessException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigInteger;
|
||||
@@ -178,6 +179,40 @@ public class WorkflowRunningParameterResolverTest {
|
||||
Assert.assertEquals(2, ((List<?>) attachments).size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件参数应允许 20MB 边界值,并拒绝超过边界的文件。
|
||||
*
|
||||
* @throws Exception 反射注入失败
|
||||
*/
|
||||
@Test
|
||||
public void testNormalizeRuntimeVariablesShouldEnforceTwentyMbSingleFileLimit() throws Exception {
|
||||
WorkflowRunningParameterResolver resolver = newResolver();
|
||||
Map<String, Object> variables = new LinkedHashMap<>();
|
||||
variables.put("attachments", fileValue(
|
||||
"accepted.pdf",
|
||||
"/files/accepted.pdf",
|
||||
20L * 1024L * 1024L
|
||||
));
|
||||
|
||||
Map<String, Object> normalized = resolver.normalizeRuntimeVariables(
|
||||
workflowContentWithStartParameters(),
|
||||
variables
|
||||
);
|
||||
Assert.assertEquals(1, ((List<?>) normalized.get("attachments")).size());
|
||||
|
||||
variables.put("attachments", fileValue(
|
||||
"oversized.pdf",
|
||||
"/files/oversized.pdf",
|
||||
20L * 1024L * 1024L + 1L
|
||||
));
|
||||
try {
|
||||
resolver.normalizeRuntimeVariables(workflowContentWithStartParameters(), variables);
|
||||
Assert.fail("expected BusinessException");
|
||||
} catch (BusinessException exception) {
|
||||
Assert.assertEquals("文件参数 attachments 中单个文件不能超过 20MB", exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static WorkflowRunningParameterResolver newResolver() throws Exception {
|
||||
WorkflowRunningParameterResolver resolver = new WorkflowRunningParameterResolver();
|
||||
ChainParser parser = ChainParser.builder()
|
||||
|
||||
@@ -263,6 +263,38 @@ public class DocNodeFileContentExtractorTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证文档节点允许 20MB 边界值,并拒绝超过边界的文件。
|
||||
*/
|
||||
@Test
|
||||
public void shouldEnforceTwentyMbSingleFileLimit() {
|
||||
DocNodeFileContentExtractor extractor = new DocNodeFileContentExtractor(
|
||||
new RecordingDocumentParseBridgeService(),
|
||||
new FakeFileStorageService(),
|
||||
new FakeReaderManager("plain text")
|
||||
);
|
||||
Map<String, Object> accepted = buildFileValue(
|
||||
"accepted.pdf",
|
||||
"/files/accepted.pdf",
|
||||
"application/pdf"
|
||||
);
|
||||
accepted.put("size", 20L * 1024L * 1024L);
|
||||
Assert.assertEquals(1, extractor.toDocumentSourceRefs(accepted).size());
|
||||
|
||||
Map<String, Object> oversized = buildFileValue(
|
||||
"oversized.pdf",
|
||||
"/files/oversized.pdf",
|
||||
"application/pdf"
|
||||
);
|
||||
oversized.put("size", 20L * 1024L * 1024L + 1L);
|
||||
try {
|
||||
extractor.toDocumentSourceRefs(oversized);
|
||||
Assert.fail("expected BusinessException");
|
||||
} catch (BusinessException exception) {
|
||||
Assert.assertEquals("单个文件不能超过 20MB: oversized.pdf", exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> buildFileValue(String fileName, String filePath, String contentType) {
|
||||
Map<String, Object> value = new HashMap<String, Object>();
|
||||
value.put("fileName", fileName);
|
||||
|
||||
Reference in New Issue
Block a user