fix: santinize the upload filename (#6159)

This commit is contained in:
Roy
2025-12-29 11:32:14 +08:00
committed by GitHub
parent 4ea50bc38d
commit 29f61abcd3
6 changed files with 77 additions and 4 deletions

View File

@@ -151,7 +151,7 @@ const getFormatedFilename = (filename?: string) => {
// 先截断文件名,再进行格式化
const truncatedFilename = truncateFilename(filename);
const extension = path.extname(truncatedFilename); // 带.
const name = path.basename(truncatedFilename, extension);
const name = sanitizeS3ObjectKey(path.basename(truncatedFilename, extension));
return {
formatedFilename: `${id}-${name}`,
extension: extension.replace('.', '')
@@ -245,3 +245,14 @@ export function isS3ObjectKey<T extends keyof typeof S3Sources>(
): key is `${T}/${string}` {
return typeof key === 'string' && key.startsWith(`${S3Sources[source]}/`);
}
export function sanitizeS3ObjectKey(key: string) {
// 替换掉圆括号
const replaceParentheses = (key: string) => {
return key.replace(/[()]/g, (match) => (match === '(' ? '[' : ']'));
};
key = replaceParentheses(key);
return key;
}

View File

@@ -31,7 +31,6 @@ import { postTextCensor } from '../../../../chat/postTextCensor';
import type { FlowNodeInputItemType } from '@fastgpt/global/core/workflow/type/io';
import type { McpToolDataType } from '@fastgpt/global/core/app/tool/mcpTool/type';
import type { JSONSchemaInputType } from '@fastgpt/global/core/app/jsonschema';
import { getFileS3Key } from '../../../../../common/s3/utils';
type Response = DispatchNodeResultType<{
[NodeOutputKeyEnum.answerText]: string;