Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
3878a50d
authored
Oct 10, 2024
by
Archer
Committed by
GitHub
Oct 10, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: file extension check (#2876)
parent
15b8353c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
4 deletions
+28
-4
docSite/content/zh-cn/docs/development/upgrading/4811.md
+1
-1
docSite/content/zh-cn/docs/development/upgrading/4812.md
+2
-0
packages/global/common/string/tools.ts
+18
-0
packages/service/common/file/gridfs/controller.ts
+2
-1
packages/service/core/dataset/read.ts
+2
-1
packages/service/core/workflow/dispatch/tools/readFiles.ts
+3
-1
No files found.
docSite/content/zh-cn/docs/development/upgrading/4811.md
View file @
3878a50d
...
@@ -80,7 +80,7 @@ weight: 813
...
@@ -80,7 +80,7 @@ weight: 813
### 3. 修改镜像 tag 并重启
### 3. 修改镜像 tag 并重启
-
更新 FastGPT 镜像 tag: v4.8.11
-
更新 FastGPT 镜像 tag: v4.8.11
-fix
-
更新 FastGPT 商业版镜像 tag: v4.8.11
-
更新 FastGPT 商业版镜像 tag: v4.8.11
-
更新 FastGPT Sandbox 镜像 tag: v4.8.11
-
更新 FastGPT Sandbox 镜像 tag: v4.8.11
...
...
docSite/content/zh-cn/docs/development/upgrading/4812.md
View file @
3878a50d
...
@@ -10,3 +10,4 @@ weight: 812
...
@@ -10,3 +10,4 @@ weight: 812
## 更新说明
## 更新说明
1.
新增 - 全局变量支持更多数据类型
1.
新增 - 全局变量支持更多数据类型
2.
修复 - 文件后缀判断,去除 query 影响。
\ No newline at end of file
packages/global/common/string/tools.ts
View file @
3878a50d
...
@@ -102,3 +102,21 @@ export const sliceStrStartEnd = (str: string, start: number, end: number) => {
...
@@ -102,3 +102,21 @@ export const sliceStrStartEnd = (str: string, start: number, end: number) => {
return
`
${
startContent
}${
overSize
?
`\n\n...[hide
${
str
.
length
-
start
-
end
}
chars]...\n\n`
:
''
}${
endContent
}
`
;
return
`
${
startContent
}${
overSize
?
`\n\n...[hide
${
str
.
length
-
start
-
end
}
chars]...\n\n`
:
''
}${
endContent
}
`
;
};
};
/*
Parse file extension from url
Test:
1. https://xxx.com/file.pdf?token=123
=> pdf
2. https://xxx.com/file.pdf
=> pdf
*/
export
const
parseFileExtensionFromUrl
=
(
url
=
''
)
=>
{
// Remove query params
const
urlWithoutQuery
=
url
.
split
(
'?'
)[
0
];
// Get file name
const
fileName
=
urlWithoutQuery
.
split
(
'/'
).
pop
()
||
''
;
// Get file extension
const
extension
=
fileName
.
split
(
'.'
).
pop
();
return
(
extension
||
''
).
toLowerCase
();
};
packages/service/common/file/gridfs/controller.ts
View file @
3878a50d
...
@@ -11,6 +11,7 @@ import { readRawContentByFileBuffer } from '../read/utils';
...
@@ -11,6 +11,7 @@ import { readRawContentByFileBuffer } from '../read/utils';
import
{
gridFsStream2Buffer
,
stream2Encoding
}
from
'./utils'
;
import
{
gridFsStream2Buffer
,
stream2Encoding
}
from
'./utils'
;
import
{
addLog
}
from
'../../system/log'
;
import
{
addLog
}
from
'../../system/log'
;
import
{
readFromSecondary
}
from
'../../mongo/utils'
;
import
{
readFromSecondary
}
from
'../../mongo/utils'
;
import
{
parseFileExtensionFromUrl
}
from
'@fastgpt/global/common/string/tools'
;
export
function
getGFSCollection
(
bucket
:
`
${
BucketNameEnum
}
`
)
{
export
function
getGFSCollection
(
bucket
:
`
${
BucketNameEnum
}
`
)
{
MongoDatasetFileSchema
;
MongoDatasetFileSchema
;
...
@@ -163,7 +164,7 @@ export const readFileContentFromMongo = async ({
...
@@ -163,7 +164,7 @@ export const readFileContentFromMongo = async ({
return
Promise
.
reject
(
CommonErrEnum
.
fileNotFound
);
return
Promise
.
reject
(
CommonErrEnum
.
fileNotFound
);
}
}
const
extension
=
file
?.
filename
?.
split
(
'.'
)?.
pop
()?.
toLowerCase
()
||
''
;
const
extension
=
parseFileExtensionFromUrl
(
file
?.
filename
)
;
const
start
=
Date
.
now
();
const
start
=
Date
.
now
();
const
fileBuffers
=
await
gridFsStream2Buffer
(
fileStream
);
const
fileBuffers
=
await
gridFsStream2Buffer
(
fileStream
);
...
...
packages/service/core/dataset/read.ts
View file @
3878a50d
...
@@ -6,6 +6,7 @@ import { parseCsvTable2Chunks } from './training/utils';
...
@@ -6,6 +6,7 @@ import { parseCsvTable2Chunks } from './training/utils';
import
{
TextSplitProps
,
splitText2Chunks
}
from
'@fastgpt/global/common/string/textSplitter'
;
import
{
TextSplitProps
,
splitText2Chunks
}
from
'@fastgpt/global/common/string/textSplitter'
;
import
axios
from
'axios'
;
import
axios
from
'axios'
;
import
{
readRawContentByFileBuffer
}
from
'../../common/file/read/utils'
;
import
{
readRawContentByFileBuffer
}
from
'../../common/file/read/utils'
;
import
{
parseFileExtensionFromUrl
}
from
'@fastgpt/global/common/string/tools'
;
export
const
readFileRawTextByUrl
=
async
({
export
const
readFileRawTextByUrl
=
async
({
teamId
,
teamId
,
...
@@ -21,7 +22,7 @@ export const readFileRawTextByUrl = async ({
...
@@ -21,7 +22,7 @@ export const readFileRawTextByUrl = async ({
url
:
url
,
url
:
url
,
responseType
:
'arraybuffer'
responseType
:
'arraybuffer'
});
});
const
extension
=
url
.
split
(
'.'
)?.
pop
()?.
toLowerCase
()
||
''
;
const
extension
=
parseFileExtensionFromUrl
(
url
)
;
const
buffer
=
Buffer
.
from
(
response
.
data
,
'binary'
);
const
buffer
=
Buffer
.
from
(
response
.
data
,
'binary'
);
...
...
packages/service/core/workflow/dispatch/tools/readFiles.ts
View file @
3878a50d
...
@@ -12,6 +12,7 @@ import { detectFileEncoding } from '@fastgpt/global/common/file/tools';
...
@@ -12,6 +12,7 @@ import { detectFileEncoding } from '@fastgpt/global/common/file/tools';
import
{
readRawContentByFileBuffer
}
from
'../../../../common/file/read/utils'
;
import
{
readRawContentByFileBuffer
}
from
'../../../../common/file/read/utils'
;
import
{
ChatRoleEnum
}
from
'@fastgpt/global/core/chat/constants'
;
import
{
ChatRoleEnum
}
from
'@fastgpt/global/core/chat/constants'
;
import
{
UserChatItemValueItemType
}
from
'@fastgpt/global/core/chat/type'
;
import
{
UserChatItemValueItemType
}
from
'@fastgpt/global/core/chat/type'
;
import
{
parseFileExtensionFromUrl
}
from
'@fastgpt/global/common/string/tools'
;
type
Props
=
ModuleDispatchProps
<
{
type
Props
=
ModuleDispatchProps
<
{
[
NodeInputKeyEnum
.
fileUrlList
]:
string
[];
[
NodeInputKeyEnum
.
fileUrlList
]:
string
[];
...
@@ -144,7 +145,8 @@ export const dispatchReadFiles = async (props: Props): Promise<Response> => {
...
@@ -144,7 +145,8 @@ export const dispatchReadFiles = async (props: Props): Promise<Response> => {
return
url
;
return
url
;
})();
})();
// Extension
// Extension
const
extension
=
filename
.
split
(
'.'
).
pop
()?.
toLowerCase
()
||
''
;
const
extension
=
parseFileExtensionFromUrl
(
filename
);
// Get encoding
// Get encoding
const
encoding
=
(()
=>
{
const
encoding
=
(()
=>
{
const
contentType
=
response
.
headers
[
'content-type'
];
const
contentType
=
response
.
headers
[
'content-type'
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment