mirror of
https://github.com/labring/FastGPT.git
synced 2026-02-27 01:02:22 +08:00
fix: santinize the upload filename (#6159)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user