fix: share page data;Adapt findLastIndex api (#3147)
* perf: share page data * perf: adapt findLastIndex
This commit is contained in:
@@ -82,11 +82,16 @@ async function handler(
|
||||
limit: pageSize
|
||||
});
|
||||
|
||||
const responseDetail = !shareChat || shareChat.responseDetail;
|
||||
|
||||
// Remove important information
|
||||
if (shareChat && app.type !== AppTypeEnum.plugin) {
|
||||
histories.forEach((item) => {
|
||||
if (item.obj === ChatRoleEnum.AI) {
|
||||
item.responseData = filterPublicNodeResponseData({ flowResponses: item.responseData });
|
||||
item.responseData = filterPublicNodeResponseData({
|
||||
flowResponses: item.responseData,
|
||||
responseDetail
|
||||
});
|
||||
|
||||
if (shareChat.showNodeStatus === false) {
|
||||
item.value = item.value.filter((v) => v.type !== ChatItemValueTypeEnum.tool);
|
||||
@@ -96,7 +101,7 @@ async function handler(
|
||||
}
|
||||
|
||||
return {
|
||||
list: isPlugin ? histories : transformPreviewHistories(histories),
|
||||
list: isPlugin ? histories : transformPreviewHistories(histories, responseDetail),
|
||||
total
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
|
||||
import { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat';
|
||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { filterPublicNodeResponseData } from '@fastgpt/global/core/chat/utils';
|
||||
import { MongoOutLink } from '@fastgpt/service/support/outLink/schema';
|
||||
|
||||
export type getResDataQuery = OutLinkChatAuthProps & {
|
||||
chatId?: string;
|
||||
@@ -26,44 +27,57 @@ async function handler(
|
||||
req: ApiRequestProps<getResDataBody, getResDataQuery>,
|
||||
res: ApiResponseType<any>
|
||||
): Promise<getResDataResponse> {
|
||||
const { appId, chatId, dataId } = req.query;
|
||||
const { appId, chatId, dataId, shareId } = req.query;
|
||||
if (!appId || !chatId || !dataId) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// 1. Un login api: share chat, team chat
|
||||
// 2. Login api: account chat, chat log
|
||||
try {
|
||||
await authChatCrud({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true,
|
||||
...req.query,
|
||||
per: ReadPermissionVal
|
||||
});
|
||||
} catch (error) {
|
||||
await authApp({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true,
|
||||
appId,
|
||||
per: ManagePermissionVal
|
||||
});
|
||||
const authData = await (() => {
|
||||
try {
|
||||
return authChatCrud({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true,
|
||||
...req.query,
|
||||
per: ReadPermissionVal
|
||||
});
|
||||
} catch (error) {
|
||||
return authApp({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true,
|
||||
appId,
|
||||
per: ManagePermissionVal
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
const [chatData] = await Promise.all([
|
||||
MongoChatItem.findOne(
|
||||
{
|
||||
appId,
|
||||
chatId,
|
||||
dataId
|
||||
},
|
||||
'obj responseData'
|
||||
).lean(),
|
||||
shareId ? MongoOutLink.findOne({ shareId }).lean() : Promise.resolve(null)
|
||||
]);
|
||||
|
||||
if (chatData?.obj !== ChatRoleEnum.AI) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const chatData = await MongoChatItem.findOne(
|
||||
{
|
||||
appId,
|
||||
chatId,
|
||||
dataId
|
||||
},
|
||||
'obj responseData'
|
||||
).lean();
|
||||
|
||||
if (chatData?.obj === ChatRoleEnum.AI) {
|
||||
const data = chatData.responseData || {};
|
||||
return req.query.shareId ? filterPublicNodeResponseData(data) : data;
|
||||
} else return {};
|
||||
const flowResponses = chatData.responseData ?? {};
|
||||
return req.query.shareId
|
||||
? filterPublicNodeResponseData({
|
||||
// @ts-ignore
|
||||
responseDetail: authData.responseDetail,
|
||||
flowResponses: chatData.responseData
|
||||
})
|
||||
: flowResponses;
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
|
||||
@@ -363,7 +363,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
/* select fe response field */
|
||||
const feResponseData = canWrite
|
||||
? flowResponses
|
||||
: filterPublicNodeResponseData({ flowResponses });
|
||||
: filterPublicNodeResponseData({ flowResponses, responseDetail });
|
||||
|
||||
if (stream) {
|
||||
workflowResponseWrite({
|
||||
@@ -380,12 +380,10 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
});
|
||||
|
||||
if (detail) {
|
||||
if (responseDetail || isPlugin) {
|
||||
workflowResponseWrite({
|
||||
event: SseResponseEventEnum.flowResponses,
|
||||
data: feResponseData
|
||||
});
|
||||
}
|
||||
workflowResponseWrite({
|
||||
event: SseResponseEventEnum.flowResponses,
|
||||
data: feResponseData
|
||||
});
|
||||
}
|
||||
|
||||
res.end();
|
||||
|
||||
Reference in New Issue
Block a user