Skip to content

Commit c314312

Browse files
4.7.1 production (#1173)
Co-authored-by: heheer <[email protected]>
1 parent db2dd91 commit c314312

File tree

19 files changed

+198
-119
lines changed

19 files changed

+198
-119
lines changed

docSite/content/docs/development/upgrading/471.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'V4.7.1(进行中)'
2+
title: 'V4.7.1(需要初始化)'
33
description: 'FastGPT V4.7.1 更新说明'
44
icon: 'upgrade'
55
draft: false
@@ -32,8 +32,10 @@ curl --location --request POST 'https://{{host}}/api/admin/clearInvalidData' \
3232
3. 新增 - 集成 Laf 云函数,可以读取 Laf 账号中的云函数作为 HTTP 模块。
3333
4. 新增 - 定时器,清理垃圾数据。(采用小范围清理,会清理最近n个小时的,所以请保证服务持续运行,长时间不允许,可以继续执行 clearInvalidData 的接口进行全量清理。)
3434
5. 商业版新增 - 后台配置系统通知。
35-
6. 修改 - csv导入模板,取消 header 校验,自动获取前两列。
36-
7. 修复 - 工具调用模块连线数据类型校验错误。
37-
8. 修复 - 自定义索引输入时,解构数据失败。
38-
9. 修复 - rerank 模型数据格式。
39-
10. 修复 - 问题补全历史记录BUG
35+
6. 优化 - 支持ip模式导出知识库。
36+
7. 修改 - csv导入模板,取消 header 校验,自动获取前两列。
37+
8. 修复 - 工具调用模块连线数据类型校验错误。
38+
9. 修复 - 自定义索引输入时,解构数据失败。
39+
10. 修复 - rerank 模型数据格式。
40+
11. 修复 - 问题补全历史记录BUG
41+
12. 修复 - 分享页面特殊情况下加载缓慢问题(由于ssr时候数据库不会触发连接)

packages/global/common/file/tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export const formatFileSize = (bytes: number): string => {
1010
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
1111
};
1212

13-
export const detectFileEncoding = (buffers: string | Buffer) => {
14-
return (detect(buffers)?.encoding || 'utf-8') as BufferEncoding;
13+
export const detectFileEncoding = (buffer: Buffer) => {
14+
return detect(buffer.slice(0, 200))?.encoding?.toLocaleLowerCase();
1515
};

packages/service/common/file/gridfs/controller.ts

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { CommonErrEnum } from '@fastgpt/global/common/error/code/common';
99
import { ReadFileByBufferParams } from '../read/type';
1010
import { MongoRwaTextBuffer } from '../../buffer/rawText/schema';
1111
import { readFileRawContent } from '../read/utils';
12+
import { PassThrough } from 'stream';
1213

1314
export function getGFSCollection(bucket: `${BucketNameEnum}`) {
1415
MongoFileSchema;
@@ -113,31 +114,39 @@ export async function getDownloadStream({
113114
fileId: string;
114115
}) {
115116
const bucket = getGridBucket(bucketName);
117+
const stream = bucket.openDownloadStream(new Types.ObjectId(fileId));
118+
const copyStream = stream.pipe(new PassThrough());
116119

117-
return bucket.openDownloadStream(new Types.ObjectId(fileId));
118-
}
119-
120-
export const readFileEncode = async ({
121-
bucketName,
122-
fileId
123-
}: {
124-
bucketName: `${BucketNameEnum}`;
125-
fileId: string;
126-
}) => {
127-
const encodeStream = await getDownloadStream({ bucketName, fileId });
128-
let buffers: Buffer = Buffer.from([]);
129-
for await (const chunk of encodeStream) {
130-
buffers = Buffer.concat([buffers, chunk]);
131-
if (buffers.length > 10) {
132-
encodeStream.abort();
133-
break;
134-
}
135-
}
120+
/* get encoding */
121+
const buffer = await (() => {
122+
return new Promise<Buffer>((resolve, reject) => {
123+
let tmpBuffer: Buffer = Buffer.from([]);
124+
125+
stream.on('data', (chunk) => {
126+
if (tmpBuffer.length < 20) {
127+
tmpBuffer = Buffer.concat([tmpBuffer, chunk]);
128+
}
129+
if (tmpBuffer.length >= 20) {
130+
resolve(tmpBuffer);
131+
}
132+
});
133+
stream.on('end', () => {
134+
resolve(tmpBuffer);
135+
});
136+
stream.on('error', (err) => {
137+
reject(err);
138+
});
139+
});
140+
})();
136141

137-
const encoding = detectFileEncoding(buffers);
142+
const encoding = detectFileEncoding(buffer);
138143

139-
return encoding as BufferEncoding;
140-
};
144+
return {
145+
fileStream: copyStream,
146+
encoding
147+
// encoding: 'utf-8'
148+
};
149+
}
141150

142151
export const readFileContentFromMongo = async ({
143152
teamId,
@@ -162,9 +171,8 @@ export const readFileContentFromMongo = async ({
162171
};
163172
}
164173

165-
const [file, encoding, fileStream] = await Promise.all([
174+
const [file, { encoding, fileStream }] = await Promise.all([
166175
getFileById({ bucketName, fileId }),
167-
readFileEncode({ bucketName, fileId }),
168176
getDownloadStream({ bucketName, fileId })
169177
]);
170178

@@ -176,12 +184,12 @@ export const readFileContentFromMongo = async ({
176184

177185
const fileBuffers = await (() => {
178186
return new Promise<Buffer>((resolve, reject) => {
179-
let buffers = Buffer.from([]);
187+
let buffer = Buffer.from([]);
180188
fileStream.on('data', (chunk) => {
181-
buffers = Buffer.concat([buffers, chunk]);
189+
buffer = Buffer.concat([buffer, chunk]);
182190
});
183191
fileStream.on('end', () => {
184-
resolve(buffers);
192+
resolve(buffer);
185193
});
186194
fileStream.on('error', (err) => {
187195
reject(err);

packages/service/common/file/read/pptx.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ export const readPptxRawText = async ({
66
buffer,
77
encoding
88
}: ReadFileByBufferParams): Promise<ReadFileResponse> => {
9-
const result = await parseOffice({ buffer, encoding, extension: 'pptx' });
9+
const result = await parseOffice({
10+
buffer,
11+
encoding: encoding as BufferEncoding,
12+
extension: 'pptx'
13+
});
1014

1115
return {
1216
rawText: result

packages/service/common/file/read/rawText.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
import { ReadFileByBufferParams, ReadFileResponse } from './type.d';
2+
import iconv from 'iconv-lite';
3+
4+
const rawEncodingList = [
5+
'ascii',
6+
'utf8',
7+
'utf-8',
8+
'utf16le',
9+
'utf-16le',
10+
'ucs2',
11+
'ucs-2',
12+
'base64',
13+
'base64url',
14+
'latin1',
15+
'binary',
16+
'hex'
17+
];
218

319
// 加载源文件内容
420
export const readFileRawText = ({ buffer, encoding }: ReadFileByBufferParams): ReadFileResponse => {
5-
const content = buffer.toString(encoding);
21+
const content = rawEncodingList.includes(encoding)
22+
? buffer.toString(encoding as BufferEncoding)
23+
: iconv.decode(buffer, 'gbk');
624

725
return {
826
rawText: content

packages/service/common/file/read/type.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type ReadFileByBufferParams = {
22
teamId: string;
33
buffer: Buffer;
4-
encoding: BufferEncoding;
4+
encoding: string;
55
metadata?: Record<string, any>;
66
};
77

packages/service/common/vectorStore/pg/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const deleteDatasetDataVector = async (
103103
}
104104
return Promise.reject('deleteDatasetData: no where');
105105
})();
106-
console.log(where, '===');
106+
107107
try {
108108
await PgClient.delete(PgDatasetTableName, {
109109
where: [where]

packages/service/common/vectorStore/pg/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ export const connectPg = async (): Promise<Pool> => {
1313
max: Number(process.env.DB_MAX_LINK || 20),
1414
min: 10,
1515
keepAlive: true,
16-
idleTimeoutMillis: 60000,
17-
connectionTimeoutMillis: 20000
16+
idleTimeoutMillis: 600000,
17+
connectionTimeoutMillis: 20000,
18+
query_timeout: 30000,
19+
statement_timeout: 40000,
20+
idle_in_transaction_session_timeout: 60000
1821
});
1922

2023
global.pgClient.on('error', async (err) => {

packages/service/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"decompress": "^4.2.1",
1414
"encoding": "^0.1.13",
1515
"file-type": "^19.0.0",
16+
"iconv-lite": "^0.6.3",
1617
"json5": "^2.2.3",
1718
"jsonwebtoken": "^9.0.2",
1819
"mammoth": "^1.6.0",

packages/web/components/common/Textarea/PromptEditor/utils.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ export function registerLexicalTextEntity<T extends TextNode>(
173173

174174
export function textToEditorState(text: string = '') {
175175
const paragraph = text?.split('\n');
176-
177176
return JSON.stringify({
178177
root: {
179178
children: paragraph.map((p) => {
@@ -206,11 +205,23 @@ export function textToEditorState(text: string = '') {
206205
}
207206

208207
export function editorStateToText(editor: LexicalEditor) {
209-
const stringifiedEditorState = JSON.stringify(editor.getEditorState().toJSON());
210-
const parsedEditorState = editor.parseEditorState(stringifiedEditorState);
211-
const editorStateTextString = parsedEditorState.read(() => $getRoot().getTextContent());
212-
213-
return editorStateTextString;
208+
const editorStateTextString: string[] = [];
209+
const paragraphs = editor.getEditorState().toJSON().root.children;
210+
paragraphs.forEach((paragraph: any) => {
211+
const children = paragraph.children;
212+
const paragraphText: string[] = [];
213+
children.forEach((child: any) => {
214+
if (child.type === 'linebreak') {
215+
paragraphText.push(`
216+
`);
217+
} else if (child.text) {
218+
paragraphText.push(child.text);
219+
}
220+
});
221+
editorStateTextString.push(paragraphText.join(''));
222+
});
223+
return editorStateTextString.join(`
224+
`);
214225
}
215226

216227
const varRegex = /\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g;

0 commit comments

Comments
 (0)