feat: 将工作流与 FAQ 上传上限扩至 20MB

- 同步管理端、用户中心与后端工作流文件校验

- 扩展 FAQ 普通及分享上传限制并补充边界测试
This commit is contained in:
2026-07-30 17:39:13 +08:00
parent 2abff304ed
commit 100d744c25
12 changed files with 93 additions and 16 deletions

View File

@@ -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()

View File

@@ -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);