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
8d25a1d3
authored
Jul 26, 2024
by
Archer
Committed by
GitHub
Jul 26, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add img extension (#2172)
* perf: mongo log * perf: img read * doc
parent
2d1e53c3
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
38 additions
and
32 deletions
+38
-32
.vscode/settings.json
+2
-1
docSite/content/zh-cn/docs/development/upgrading/488.md
+9
-10
packages/service/common/file/gridfs/controller.ts
+1
-0
packages/service/common/file/image/controller.ts
+14
-7
packages/service/common/file/read/utils.ts
+3
-2
packages/service/common/mongo/init.ts
+2
-3
packages/service/core/chat/chatSchema.ts
+2
-2
packages/web/components/common/Icon/constants.ts
+1
-0
packages/web/components/common/Icon/icons/common/logLight.svg
+2
-0
projects/app/src/pages/api/common/file/previewContent.ts
+0
-1
projects/app/src/pages/api/system/img/[id].ts
+2
-6
No files found.
.vscode/settings.json
View file @
8d25a1d3
...
@@ -22,6 +22,6 @@
...
@@ -22,6 +22,6 @@
"i18n-ally.pathMatcher"
:
"{locale}/{namespaces}.json"
,
"i18n-ally.pathMatcher"
:
"{locale}/{namespaces}.json"
,
"i18n-ally.extract.targetPickingStrategy"
:
"most-similar-by-key"
,
"i18n-ally.extract.targetPickingStrategy"
:
"most-similar-by-key"
,
"[typescript]"
:
{
"[typescript]"
:
{
"editor.defaultFormatter"
:
"
rvest.vs-code-prettier-eslint
"
"editor.defaultFormatter"
:
"
esbenp.prettier-vscode
"
}
}
}
}
\ No newline at end of file
docSite/content/zh-cn/docs/development/upgrading/488.md
View file @
8d25a1d3
...
@@ -21,7 +21,7 @@ weight: 816
...
@@ -21,7 +21,7 @@ weight: 816
从任意终端,发起 1 个 HTTP 请求。其中 {{rootkey}} 替换成环境变量里的
`rootkey`
;{{host}} 替换成
**FastGPT 域名**
。
从任意终端,发起 1 个 HTTP 请求。其中 {{rootkey}} 替换成环境变量里的
`rootkey`
;{{host}} 替换成
**FastGPT 域名**
。
```
bash
```
bash
curl
--location
--request
POST
'https://{{host}}/api/admin/initv48
8'
\
curl
--location
--request
POST
'https://{{host}}/api/admin/initv488'
\
--header
'rootkey: {{rootkey}}'
\
--header
'rootkey: {{rootkey}}'
\
--header
'Content-Type: application/json'
--header
'Content-Type: application/json'
```
```
...
@@ -40,11 +40,10 @@ curl --location --request POST 'https://{{host}}/api/admin/initv48 8' \
...
@@ -40,11 +40,10 @@ curl --location --request POST 'https://{{host}}/api/admin/initv48 8' \
6.
优化 - 移动端快速切换应用交互。
6.
优化 - 移动端快速切换应用交互。
7.
优化 - 节点图标。
7.
优化 - 节点图标。
8.
优化 - 对话框引用增加额外复制案件,便于复制。增加引用内容折叠。
8.
优化 - 对话框引用增加额外复制案件,便于复制。增加引用内容折叠。
9.
优化 - 对话框底部增加复制,简便复制交互,无需滚动到消息开头。
9.
优化 - OpenAI sdk 升级,并自定义了 whisper 模型接口(未仔细查看 sdk 实现,但 sdk 中 whisper 接口,似乎无法适配一般 fastapi 接口)
10.
优化 - OpenAI sdk 升级,并自定义了 whisper 模型接口(未仔细查看 sdk 实现,但 sdk 中 whisper 接口,似乎无法适配一般 fastapi 接口)
10.
修复 - Permission 表声明问题。
11.
修复 - Permission 表声明问题。
11.
修复 - 并行执行节点,运行时间未正确记录。
12.
修复 - 并行执行节点,运行时间未正确记录。
12.
修复 - 运行详情未正确展示嵌套节点信息。
13.
修复 - 运行详情未正确展示嵌套节点信息。
13.
修复 - 简易模式,首次进入,无法正确获取知识库配置。
14.
修复 - 简易模式,首次进入,无法正确获取知识库配置。
14.
修复 - Log debug level 配置无效。
15.
修复 - Log debug level 配置无效。
15.
修复 - 插件独立运行时,会将插件输入的值进行变量替换,可能导致后续节点变量异常。
16.
修复 - 插件独立运行时,会将插件输入的值进行变量替换,可能导致后续节点变量异常。
\ No newline at end of file
\ No newline at end of file
packages/service/common/file/gridfs/controller.ts
View file @
8d25a1d3
...
@@ -163,6 +163,7 @@ export const readFileContentFromMongo = async ({
...
@@ -163,6 +163,7 @@ export const readFileContentFromMongo = async ({
const
encoding
=
file
?.
metadata
?.
encoding
||
detectFileEncoding
(
fileBuffers
);
const
encoding
=
file
?.
metadata
?.
encoding
||
detectFileEncoding
(
fileBuffers
);
// Get raw text
const
{
rawText
}
=
await
readRawContentByFileBuffer
({
const
{
rawText
}
=
await
readRawContentByFileBuffer
({
extension
,
extension
,
isQAImport
,
isQAImport
,
...
...
packages/service/common/file/image/controller.ts
View file @
8d25a1d3
...
@@ -2,9 +2,10 @@ import { UploadImgProps } from '@fastgpt/global/common/file/api';
...
@@ -2,9 +2,10 @@ import { UploadImgProps } from '@fastgpt/global/common/file/api';
import
{
imageBaseUrl
}
from
'@fastgpt/global/common/file/image/constants'
;
import
{
imageBaseUrl
}
from
'@fastgpt/global/common/file/image/constants'
;
import
{
MongoImage
}
from
'./schema'
;
import
{
MongoImage
}
from
'./schema'
;
import
{
ClientSession
}
from
'../../../common/mongo'
;
import
{
ClientSession
}
from
'../../../common/mongo'
;
import
{
guessBase64ImageType
}
from
'../utils'
;
export
function
getMongoImgUrl
(
id
:
string
)
{
export
function
getMongoImgUrl
(
id
:
string
,
extension
:
string
)
{
return
`
${
imageBaseUrl
}${
id
}
`
;
return
`
${
imageBaseUrl
}${
id
}
.
${
extension
}
`
;
}
}
export
const
maxImgSize
=
1024
*
1024
*
12
;
export
const
maxImgSize
=
1024
*
1024
*
12
;
...
@@ -23,9 +24,10 @@ export async function uploadMongoImg({
...
@@ -23,9 +24,10 @@ export async function uploadMongoImg({
return
Promise
.
reject
(
'Image too large'
);
return
Promise
.
reject
(
'Image too large'
);
}
}
const
[
base64Mime
,
base64Data
]
=
base64Img
.
split
(
','
)
const
[
base64Mime
,
base64Data
]
=
base64Img
.
split
(
','
)
;
const
mime
=
`image/
${
base64Mime
.
match
(
base64MimeRegex
)?.[
1
]
??
'
jpeg'
}
`
const
mime
=
`image/
${
base64Mime
.
match
(
base64MimeRegex
)?.[
1
]
??
'
image/jpeg'
}
`;
const binary = Buffer.from(base64Data, 'base64');
const binary = Buffer.from(base64Data, 'base64');
const extension = mime.split('/')[1];
const { _id } = await MongoImage.create({
const { _id } = await MongoImage.create({
type,
type,
...
@@ -36,15 +38,20 @@ export async function uploadMongoImg({
...
@@ -36,15 +38,20 @@ export async function uploadMongoImg({
shareId
shareId
});
});
return getMongoImgUrl(String(_id));
return getMongoImgUrl(String(_id)
, extension
);
}
}
export async function readMongoImg({ id }: { id: string }) {
export async function readMongoImg({ id }: { id: string }) {
const data = await MongoImage.findById(id);
const formatId = id.replace(/\.[^/.]+$/, '');
const data = await MongoImage.findById(formatId);
if (!data) {
if (!data) {
return Promise.reject('Image not found');
return Promise.reject('Image not found');
}
}
return data;
return {
binary: data.binary,
mime: data.metadata?.mime ?? guessBase64ImageType(data.binary.toString('base64'))
};
}
}
export async function delImgByRelatedId({
export async function delImgByRelatedId({
...
...
packages/service/common/file/read/utils.ts
View file @
8d25a1d3
...
@@ -8,7 +8,8 @@ import fs from 'fs';
...
@@ -8,7 +8,8 @@ import fs from 'fs';
import
{
detectFileEncoding
}
from
'@fastgpt/global/common/file/tools'
;
import
{
detectFileEncoding
}
from
'@fastgpt/global/common/file/tools'
;
import
type
{
ReadFileResponse
}
from
'../../../worker/readFile/type'
;
import
type
{
ReadFileResponse
}
from
'../../../worker/readFile/type'
;
export
const
initMarkdownText
=
({
// match md img text and upload to db
export
const
matchMdImgTextAndUpload
=
({
teamId
,
teamId
,
md
,
md
,
metadata
metadata
...
@@ -79,7 +80,7 @@ export const readRawContentByFileBuffer = async ({
...
@@ -79,7 +80,7 @@ export const readRawContentByFileBuffer = async ({
// markdown data format
// markdown data format
if
([
'md'
,
'html'
,
'docx'
].
includes
(
extension
))
{
if
([
'md'
,
'html'
,
'docx'
].
includes
(
extension
))
{
rawText
=
await
initMarkdownText
({
rawText
=
await
matchMdImgTextAndUpload
({
teamId
:
teamId
,
teamId
:
teamId
,
md
:
rawText
,
md
:
rawText
,
metadata
:
metadata
metadata
:
metadata
...
...
packages/service/common/mongo/init.ts
View file @
8d25a1d3
...
@@ -46,12 +46,11 @@ export async function connectMongo(): Promise<Mongoose> {
...
@@ -46,12 +46,11 @@ export async function connectMongo(): Promise<Mongoose> {
});
});
console
.
log
(
'mongo connected'
);
console
.
log
(
'mongo connected'
);
return
connectionMongo
;
}
catch
(
error
)
{
}
catch
(
error
)
{
addLog
.
error
(
'mongo connect error'
,
error
);
addLog
.
error
(
'mongo connect error'
,
error
);
await
connectionMongo
.
disconnect
();
await
connectionMongo
.
disconnect
();
await
delay
(
1000
);
await
delay
(
1000
);
connectMongo
();
return
connectMongo
();
}
}
return
connectionMongo
;
}
}
packages/service/core/chat/chatSchema.ts
View file @
8d25a1d3
import
{
connectionMongo
,
getMongoModel
,
type
Model
}
from
'../../common/mongo'
;
import
{
connectionMongo
,
getMongoModel
}
from
'../../common/mongo'
;
const
{
Schema
,
model
,
models
}
=
connectionMongo
;
const
{
Schema
}
=
connectionMongo
;
import
{
ChatSchema
as
ChatType
}
from
'@fastgpt/global/core/chat/type.d'
;
import
{
ChatSchema
as
ChatType
}
from
'@fastgpt/global/core/chat/type.d'
;
import
{
ChatSourceMap
}
from
'@fastgpt/global/core/chat/constants'
;
import
{
ChatSourceMap
}
from
'@fastgpt/global/core/chat/constants'
;
import
{
import
{
...
...
packages/web/components/common/Icon/constants.ts
View file @
8d25a1d3
...
@@ -36,6 +36,7 @@ export const iconPaths = {
...
@@ -36,6 +36,7 @@ export const iconPaths = {
'common/leftArrowLight'
:
()
=>
import
(
'./icons/common/leftArrowLight.svg'
),
'common/leftArrowLight'
:
()
=>
import
(
'./icons/common/leftArrowLight.svg'
),
'common/linkBlue'
:
()
=>
import
(
'./icons/common/linkBlue.svg'
),
'common/linkBlue'
:
()
=>
import
(
'./icons/common/linkBlue.svg'
),
'common/loading'
:
()
=>
import
(
'./icons/common/loading.svg'
),
'common/loading'
:
()
=>
import
(
'./icons/common/loading.svg'
),
'common/logLight'
:
()
=>
import
(
'./icons/common/logLight.svg'
),
'common/navbar/pluginFill'
:
()
=>
import
(
'./icons/common/navbar/pluginFill.svg'
),
'common/navbar/pluginFill'
:
()
=>
import
(
'./icons/common/navbar/pluginFill.svg'
),
'common/navbar/pluginLight'
:
()
=>
import
(
'./icons/common/navbar/pluginLight.svg'
),
'common/navbar/pluginLight'
:
()
=>
import
(
'./icons/common/navbar/pluginLight.svg'
),
'common/openai'
:
()
=>
import
(
'./icons/common/openai.svg'
),
'common/openai'
:
()
=>
import
(
'./icons/common/openai.svg'
),
...
...
packages/web/components/common/Icon/icons/common/logLight.svg
0 → 100644
View file @
8d25a1d3
<svg
t=
"1721963050324"
class=
"icon"
viewBox=
"0 0 1024 1024"
version=
"1.1"
xmlns=
"http://www.w3.org/2000/svg"
p-id=
"4271"
width=
"200"
height=
"200"
><path
d=
"M269.844659 81.4308h44.821057v166.626082h-44.821057zM677.140966 491.719232c52.335426 0 102.092273 19.937769 140.105639 56.13883 38.126482 36.31053 60.461599 85.284073 62.891788 137.900467 2.5056 54.276658-16.27424 106.280032-52.881549 146.431672-36.60731 40.15164-86.65972 63.643469-140.936379 66.150285-3.180653 0.147174-6.401444 0.221369-9.576016 0.221369-52.341508 0-102.102004-19.936552-140.114153-56.136398-38.126482-36.309314-60.461599-85.284073-62.891789-137.902899-2.5056-54.276658 16.27424-106.280032 52.88155-146.431672 36.60731-40.15164 86.65972-63.643469 140.936379-66.149069a208.122961 208.122961 0 0 1 9.576016-0.221369h0.008514m-0.00973-44.822274c-3.859355 0-7.746684 0.088791-11.642528 0.268805-136.951744 6.3236-242.847422 122.470346-236.525038 259.422091 6.143586 133.0559 115.942406 236.793842 247.779562 236.793842 3.859355 0 7.747901-0.088791 11.642529-0.268804 136.951744-6.322384 242.847422-122.470346 236.525037-259.422091-6.143586-133.057117-115.942406-236.798708-247.779562-236.793843z"
fill=
"#4E4D4D"
p-id=
"4272"
></path><path
d=
"M490.264524 891.110734a272.361206 272.361206 0 0 1-32.682275-37.369937H180.453104c-20.912034 0-37.927007-17.013757-37.927007-37.92579v-590.263526c0-20.912034 17.013757-37.927007 37.927007-37.927007H732.799354c20.912034 0 37.925791 17.013757 37.925791 37.927007V441.15597a268.605238 268.605238 0 0 1 44.821057 21.463023V225.551481c0-45.70045-37.047614-82.746848-82.746848-82.746849H180.453104c-45.70045 0-82.746848 37.047614-82.746848 82.746849v590.263526c0 45.70045 37.047614 82.746848 82.746848 82.746848h317.980164a273.587248 273.587248 0 0 1-8.168744-7.451121z"
fill=
"#4E4D4D"
p-id=
"4273"
></path><path
d=
"M770.725145 489.61623a225.243754 225.243754 0 0 1 44.821057 27.231985v-0.21407a225.182938 225.182938 0 0 0-44.821057-27.114003v0.096088zM812.590566 778.530212H646.820768V576.105667h44.821057v157.604704h120.948741zM209.55091 380.121489h498.255687v44.821057H209.55091zM600.682445 81.4308h44.821058v166.626082h-44.821058zM406.842623 712.17437H209.55091v44.821057h203.864657a272.351476 272.351476 0 0 1-6.572944-44.821057zM450.941192 546.147929H209.55091v44.821057h217.435038a268.707408 268.707408 0 0 1 23.955244-44.821057z"
p-id=
"4274"
></path></svg>
\ No newline at end of file
projects/app/src/pages/api/common/file/previewContent.ts
View file @
8d25a1d3
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
Read db file content and response 3000 words
Read db file content and response 3000 words
*/
*/
import
type
{
NextApiResponse
}
from
'next'
;
import
type
{
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@fastgpt/service/common/response'
;
import
{
authFile
}
from
'@fastgpt/service/support/permission/auth/file'
;
import
{
authFile
}
from
'@fastgpt/service/support/permission/auth/file'
;
import
{
NextAPI
}
from
'@/service/middleware/entry'
;
import
{
NextAPI
}
from
'@/service/middleware/entry'
;
import
{
DatasetSourceReadTypeEnum
}
from
'@fastgpt/global/core/dataset/constants'
;
import
{
DatasetSourceReadTypeEnum
}
from
'@fastgpt/global/core/dataset/constants'
;
...
...
projects/app/src/pages/api/system/img/[id].ts
View file @
8d25a1d3
...
@@ -2,7 +2,6 @@ import type { NextApiRequest, NextApiResponse } from 'next';
...
@@ -2,7 +2,6 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import
{
jsonRes
}
from
'@fastgpt/service/common/response'
;
import
{
jsonRes
}
from
'@fastgpt/service/common/response'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
readMongoImg
}
from
'@fastgpt/service/common/file/image/controller'
;
import
{
readMongoImg
}
from
'@fastgpt/service/common/file/image/controller'
;
import
{
guessBase64ImageType
}
from
'@fastgpt/service/common/file/utils'
;
// get the models available to the system
// get the models available to the system
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
...
@@ -10,12 +9,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -10,12 +9,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await
connectToDatabase
();
await
connectToDatabase
();
const
{
id
}
=
req
.
query
as
{
id
:
string
};
const
{
id
}
=
req
.
query
as
{
id
:
string
};
const
{
binary
,
m
etadata
}
=
await
readMongoImg
({
id
});
const
{
binary
,
m
ime
}
=
await
readMongoImg
({
id
});
res
.
setHeader
(
res
.
setHeader
(
'Content-Type'
,
mime
);
'Content-Type'
,
metadata
?.
mime
??
guessBase64ImageType
(
binary
.
toString
(
'base64'
))
);
res
.
send
(
binary
);
res
.
send
(
binary
);
}
catch
(
error
)
{
}
catch
(
error
)
{
jsonRes
(
res
,
{
jsonRes
(
res
,
{
...
...
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