1- import type {
2- AIChatItemType ,
3- AIChatItemValueItemType ,
4- UserChatItemType
5- } from '@fastgpt/global/core/chat/type.d' ;
1+ import type { AIChatItemType , UserChatItemType } from '@fastgpt/global/core/chat/type.d' ;
62import { MongoApp } from '../app/schema' ;
73import type { ChatSourceEnum } from '@fastgpt/global/core/chat/constants' ;
84import { ChatItemValueTypeEnum , ChatRoleEnum } from '@fastgpt/global/core/chat/constants' ;
@@ -23,7 +19,6 @@ import { MongoChatItemResponse } from './chatItemResponseSchema';
2319import { chatValue2RuntimePrompt } from '@fastgpt/global/core/chat/adapt' ;
2420import { MongoS3TTL } from '../../common/s3/schema' ;
2521import type { ClientSession } from '../../common/mongo' ;
26- import { getGlobalRedisConnection } from '../../common/redis' ;
2722
2823type Props = {
2924 chatId : string ;
@@ -46,44 +41,6 @@ type Props = {
4641 errorMsg ?: string ;
4742} ;
4843
49- // TODO: 在我迁移完到 JWT 后移除这个 transformAiResponse
50- // const transformAiResponse = async (value: AIChatItemValueItemType[]) => {
51- // const redis = getGlobalRedisConnection();
52- // const regex = /(!?)\[([^\]]+)\]\((https?:\/\/[^\s)]+\/api\/file\/temp[^\s)]*)\)/g;
53-
54- // return Promise.all(
55- // value.map(async (item) => {
56- // if (item.type !== ChatItemValueTypeEnum.text || !item.text) return item;
57- // let content = item.text.content;
58- // const matches = Array.from(content.matchAll(regex));
59-
60- // for (const match of matches.slice().reverse()) {
61- // const [full, bang, alt, link] = match;
62- // if (typeof match.index !== 'number') continue;
63-
64- // try {
65- // const url = new URL(link); // 可能会发生解析错误
66- // const k = url.searchParams.get('k');
67- // if (!k) continue;
68-
69- // const redisKey = `chat:temp_file:${decodeURIComponent(k)}`;
70- // const objectKey = await redis.get(redisKey);
71- // if (!objectKey) continue;
72-
73- // const replacement = `${bang}[${alt}](${objectKey})`;
74- // content =
75- // content.slice(0, match.index) + replacement + content.slice(match.index + full.length);
76- // } catch {
77- // continue;
78- // }
79- // }
80-
81- // item.text.content = content;
82- // return item;
83- // })
84- // );
85- // };
86-
8744const beforProcess = ( props : Props ) => {
8845 // Remove url
8946 props . userContent . value . forEach ( ( item ) => {
@@ -113,6 +70,7 @@ const afterProcess = async ({
11370 } )
11471 . flat ( )
11572 . filter ( Boolean ) as string [ ] ;
73+
11674 if ( fileKeys . length > 0 ) {
11775 await MongoS3TTL . deleteMany ( { minioKey : { $in : fileKeys } } , { session } ) ;
11876 }
@@ -152,10 +110,6 @@ const formatAiContent = ({
152110 return responseItem ;
153111 } ) ;
154112
155- // aiResponse.value = await transformAiResponse(aiResponse.value);
156- // console.log('aiResponse ========================');
157- // console.dir(aiResponse, { depth: null });
158-
159113 return {
160114 aiResponse : {
161115 ...aiResponse ,
0 commit comments