mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
fix: share init error (#2690)
This commit is contained in:
@@ -18,6 +18,8 @@ export function transformPreviewHistories(histories: ChatItemType[]) {
|
|||||||
export function addStatisticalDataToHistoryItem(historyItem: ChatItemType) {
|
export function addStatisticalDataToHistoryItem(historyItem: ChatItemType) {
|
||||||
if (historyItem.obj !== ChatRoleEnum.AI) return historyItem;
|
if (historyItem.obj !== ChatRoleEnum.AI) return historyItem;
|
||||||
if (historyItem.totalQuoteList !== undefined) return historyItem;
|
if (historyItem.totalQuoteList !== undefined) return historyItem;
|
||||||
|
|
||||||
|
// Flat children
|
||||||
const flatResData: ChatHistoryItemResType[] =
|
const flatResData: ChatHistoryItemResType[] =
|
||||||
historyItem.responseData
|
historyItem.responseData
|
||||||
?.map((item) => {
|
?.map((item) => {
|
||||||
|
@@ -10,6 +10,7 @@ import { NextAPI } from '@/service/middleware/entry';
|
|||||||
import { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
|
import { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
|
||||||
import { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat';
|
import { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat';
|
||||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||||
|
import { filterPublicNodeResponseData } from '@fastgpt/global/core/chat/utils';
|
||||||
|
|
||||||
export type getResDataQuery = OutLinkChatAuthProps & {
|
export type getResDataQuery = OutLinkChatAuthProps & {
|
||||||
chatId?: string;
|
chatId?: string;
|
||||||
@@ -48,14 +49,18 @@ async function handler(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const chatData = await MongoChatItem.findOne({
|
const chatData = await MongoChatItem.findOne(
|
||||||
appId,
|
{
|
||||||
chatId,
|
appId,
|
||||||
dataId
|
chatId,
|
||||||
});
|
dataId
|
||||||
|
},
|
||||||
|
'obj responseData'
|
||||||
|
).lean();
|
||||||
|
|
||||||
if (chatData?.obj === ChatRoleEnum.AI) {
|
if (chatData?.obj === ChatRoleEnum.AI) {
|
||||||
return chatData.responseData || {};
|
const data = chatData.responseData || {};
|
||||||
|
return req.query.shareId ? filterPublicNodeResponseData(data) : data;
|
||||||
} else return {};
|
} else return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
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 type { InitChatResponse, InitOutLinkChatProps } from '@/global/core/chat/api.d';
|
import type { InitChatResponse, InitOutLinkChatProps } from '@/global/core/chat/api.d';
|
||||||
import { getGuideModule, getAppChatConfig } from '@fastgpt/global/core/workflow/utils';
|
import { getGuideModule, getAppChatConfig } from '@fastgpt/global/core/workflow/utils';
|
||||||
import { getChatModelNameListByModules } from '@/service/core/app/workflow';
|
import { getChatModelNameListByModules } from '@/service/core/app/workflow';
|
||||||
@@ -9,11 +8,9 @@ import { getChatItems } from '@fastgpt/service/core/chat/controller';
|
|||||||
import { MongoTeamMember } from '@fastgpt/service/support/user/team/teamMemberSchema';
|
import { MongoTeamMember } from '@fastgpt/service/support/user/team/teamMemberSchema';
|
||||||
import { authOutLink } from '@/service/support/permission/auth/outLink';
|
import { authOutLink } from '@/service/support/permission/auth/outLink';
|
||||||
import { MongoApp } from '@fastgpt/service/core/app/schema';
|
import { MongoApp } from '@fastgpt/service/core/app/schema';
|
||||||
import { filterPublicNodeResponseData } from '@fastgpt/global/core/chat/utils';
|
|
||||||
import { AppErrEnum } from '@fastgpt/global/common/error/code/app';
|
import { AppErrEnum } from '@fastgpt/global/common/error/code/app';
|
||||||
import { MongoChat } from '@fastgpt/service/core/chat/chatSchema';
|
import { MongoChat } from '@fastgpt/service/core/chat/chatSchema';
|
||||||
import { ChatErrEnum } from '@fastgpt/global/common/error/code/chat';
|
import { ChatErrEnum } from '@fastgpt/global/common/error/code/chat';
|
||||||
import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
|
|
||||||
import { getAppLatestVersion } from '@fastgpt/service/core/app/controller';
|
import { getAppLatestVersion } from '@fastgpt/service/core/app/controller';
|
||||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
||||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||||
@@ -56,14 +53,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
getAppLatestVersion(app._id, app)
|
getAppLatestVersion(app._id, app)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// pick share response field
|
|
||||||
app.type !== AppTypeEnum.plugin &&
|
|
||||||
histories.forEach((item) => {
|
|
||||||
if (item.obj === ChatRoleEnum.AI) {
|
|
||||||
item.responseData = filterPublicNodeResponseData({ flowResponses: item.responseData });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
jsonRes<InitChatResponse>(res, {
|
jsonRes<InitChatResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
chatId,
|
chatId,
|
||||||
|
@@ -11,8 +11,6 @@ import { AppErrEnum } from '@fastgpt/global/common/error/code/app';
|
|||||||
import { authTeamSpaceToken } from '@/service/support/permission/auth/team';
|
import { authTeamSpaceToken } from '@/service/support/permission/auth/team';
|
||||||
import { MongoTeam } from '@fastgpt/service/support/user/team/teamSchema';
|
import { MongoTeam } from '@fastgpt/service/support/user/team/teamSchema';
|
||||||
import { ChatErrEnum } from '@fastgpt/global/common/error/code/chat';
|
import { ChatErrEnum } from '@fastgpt/global/common/error/code/chat';
|
||||||
import { filterPublicNodeResponseData } from '@fastgpt/global/core/chat/utils';
|
|
||||||
import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
|
|
||||||
import { getAppLatestVersion } from '@fastgpt/service/core/app/controller';
|
import { getAppLatestVersion } from '@fastgpt/service/core/app/controller';
|
||||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
||||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||||
@@ -57,14 +55,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
getAppLatestVersion(app._id, app)
|
getAppLatestVersion(app._id, app)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// pick share response field
|
|
||||||
app.type !== AppTypeEnum.plugin &&
|
|
||||||
histories.forEach((item) => {
|
|
||||||
if (item.obj === ChatRoleEnum.AI) {
|
|
||||||
item.responseData = filterPublicNodeResponseData({ flowResponses: item.responseData });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
jsonRes<InitChatResponse>(res, {
|
jsonRes<InitChatResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
chatId,
|
chatId,
|
||||||
|
Reference in New Issue
Block a user