feat:文档集文件大小和个数限制
- 单个文件不能大于10MB - 总文件不能大于100MB - 总文件个数不能超过1000个
This commit is contained in:
@ -427,7 +427,40 @@ export function getDocsetDialogScript(): string {
|
|||||||
if (message.errors && message.errors.length > 0) {
|
if (message.errors && message.errors.length > 0) {
|
||||||
alert('部分文件添加失败:\\n' + message.errors.join('\\n'));
|
alert('部分文件添加失败:\\n' + message.errors.join('\\n'));
|
||||||
}
|
}
|
||||||
docsetFiles = [...docsetFiles, ...message.files];
|
|
||||||
|
const MAX_FILE_SIZE = 10 * 1024 * 1024;
|
||||||
|
const MAX_TOTAL_SIZE = 50 * 1024 * 1024;
|
||||||
|
const MAX_FILE_COUNT = 1000;
|
||||||
|
|
||||||
|
const vaildFiles = [];
|
||||||
|
const errors = [];
|
||||||
|
|
||||||
|
for (const file of message.files) {
|
||||||
|
if (file.size > MAX_FILE_SIZE) {
|
||||||
|
errors.push(\`\${file.path} 超过单个文件大小限制(\${formatFileSize(MAX_FILE_SIZE)})\`);
|
||||||
|
} else {
|
||||||
|
vaildFiles.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newFiles = [...docsetFiles, ...vaildFiles];
|
||||||
|
const totalSize = newFiles.reduce((sum, f) => sum + (f.size || 0), 0);
|
||||||
|
|
||||||
|
if (newFiles.length > MAX_FILE_COUNT) {
|
||||||
|
errors.push(\`文档数量超过限制(最多1000个),当前数量(\${newFiles.length} 个)\`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalSize > MAX_TOTAL_SIZE) {
|
||||||
|
errors.push(\`文档集总大小超过 50MB 限制,当前大小为(\${formatFileSize(MAX_TOTAL_SIZE)})\`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(errors.length > 0) {
|
||||||
|
alert('以下文件被跳过:\\n' + errors.join('\\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
docsetFiles = newFiles;
|
||||||
updateDocsetDisplay();
|
updateDocsetDisplay();
|
||||||
} else if (message.command === 'documentSetSaved') {
|
} else if (message.command === 'documentSetSaved') {
|
||||||
renderDocumentSets(message.documentSets);
|
renderDocumentSets(message.documentSets);
|
||||||
|
|||||||
Reference in New Issue
Block a user