Skip to content

Commit 8934191

Browse files
authored
fix outlink quote number auth (#4705)
1 parent 14ad6ae commit 8934191

File tree

5 files changed

+71
-17
lines changed

5 files changed

+71
-17
lines changed

projects/app/src/components/Markdown/A.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const A = ({ children, ...props }: any) => {
5252
data: quoteData,
5353
loading,
5454
runAsync: getQuoteDataById
55-
} = useRequest2(getQuoteData, {
55+
} = useRequest2((id: string) => getQuoteData({ id, ...props.metadata }), {
5656
manual: true
5757
});
5858
const sourceData = useMemo(

projects/app/src/components/Markdown/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ type Props = {
3131
showAnimation?: boolean;
3232
isDisabled?: boolean;
3333
forbidZhFormat?: boolean;
34+
metadata?: {
35+
appId: string;
36+
chatId: string;
37+
shareId?: string;
38+
outLinkUid?: string;
39+
teamId?: string;
40+
teamToken?: string;
41+
};
3442
};
3543
const Markdown = (props: Props) => {
3644
const source = props.source || '';
@@ -41,15 +49,21 @@ const Markdown = (props: Props) => {
4149

4250
return <Box whiteSpace={'pre-wrap'}>{source}</Box>;
4351
};
44-
const MarkdownRender = ({ source = '', showAnimation, isDisabled, forbidZhFormat }: Props) => {
52+
const MarkdownRender = ({
53+
source = '',
54+
showAnimation,
55+
isDisabled,
56+
forbidZhFormat,
57+
metadata
58+
}: Props) => {
4559
const components = useMemo<any>(
4660
() => ({
4761
img: Image,
4862
pre: RewritePre,
4963
code: Code,
50-
a: A
64+
a: (props: any) => <A {...props} metadata={metadata} />
5165
}),
52-
[]
66+
[metadata]
5367
);
5468

5569
const formatSource = useMemo(() => {

projects/app/src/components/core/chat/components/AIResponseBox.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { SelectOptionsComponent, FormInputComponent } from './Interactive/Intera
3131
import { extractDeepestInteractive } from '@fastgpt/global/core/workflow/runtime/utils';
3232
import { useContextSelector } from 'use-context-selector';
3333
import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
34+
import { ChatBoxContext } from '../ChatContainer/ChatBox/Provider';
3435

3536
const accordionButtonStyle = {
3637
w: 'auto',
@@ -94,6 +95,10 @@ const RenderText = React.memo(function RenderText({
9495
}) {
9596
const isResponseDetail = useContextSelector(ChatItemContext, (v) => v.isResponseDetail);
9697

98+
const appId = useContextSelector(ChatBoxContext, (v) => v.appId);
99+
const chatId = useContextSelector(ChatBoxContext, (v) => v.chatId);
100+
const outLinkAuthData = useContextSelector(ChatBoxContext, (v) => v.outLinkAuthData);
101+
97102
const source = useMemo(() => {
98103
if (!text) return '';
99104

@@ -104,7 +109,13 @@ const RenderText = React.memo(function RenderText({
104109
// First empty line
105110
// if (!source && !isLastChild) return null;
106111

107-
return <Markdown source={source} showAnimation={showAnimation} />;
112+
return (
113+
<Markdown
114+
source={source}
115+
showAnimation={showAnimation}
116+
metadata={{ appId, chatId, ...outLinkAuthData }}
117+
/>
118+
);
108119
});
109120

110121
const RenderTool = React.memo(

projects/app/src/pages/api/core/dataset/data/getQuoteData.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,57 @@
11
import type { NextApiRequest } from 'next';
22
import { NextAPI } from '@/service/middleware/entry';
3-
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
4-
import { authDatasetData } from '@fastgpt/service/support/permission/dataset/auth';
53
import { CollectionWithDatasetType } from '@fastgpt/global/core/dataset/type';
4+
import { authChatCrud } from '@/service/support/permission/auth/chat';
5+
import { MongoDatasetData } from '@fastgpt/service/core/dataset/data/schema';
6+
import { getCollectionWithDataset } from '@fastgpt/service/core/dataset/controller';
67

78
export type GetQuoteDataResponse = {
89
collection: CollectionWithDatasetType;
910
q: string;
1011
a: string;
1112
};
1213

14+
export type GetQuoteDataProps = {
15+
id: string;
16+
appId: string;
17+
chatId: string;
18+
shareId?: string;
19+
outLinkUid?: string;
20+
teamId?: string;
21+
teamToken?: string;
22+
};
1323
async function handler(req: NextApiRequest): Promise<GetQuoteDataResponse> {
14-
const { id: dataId } = req.query as {
15-
id: string;
16-
};
24+
const {
25+
id: dataId,
26+
appId,
27+
chatId,
28+
shareId,
29+
outLinkUid,
30+
teamId,
31+
teamToken
32+
} = req.body as GetQuoteDataProps;
1733

18-
// 凭证校验
19-
const { datasetData, collection } = await authDatasetData({
34+
await authChatCrud({
2035
req,
2136
authToken: true,
22-
authApiKey: true,
23-
dataId,
24-
per: ReadPermissionVal
37+
appId,
38+
chatId,
39+
shareId,
40+
outLinkUid,
41+
teamId,
42+
teamToken
2543
});
2644

45+
const datasetData = await MongoDatasetData.findById(dataId);
46+
if (!datasetData) {
47+
return Promise.reject('core.dataset.error.Data not found');
48+
}
49+
50+
const collection = await getCollectionWithDataset(datasetData.collectionId);
51+
if (!collection) {
52+
return Promise.reject('core.dataset.error.Collection not found');
53+
}
54+
2755
return {
2856
collection,
2957
q: datasetData.q,

projects/app/src/web/core/dataset/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import type {
7272
getTrainingErrorResponse
7373
} from '@/pages/api/core/dataset/training/getTrainingError';
7474
import type { APIFileItem } from '@fastgpt/global/core/dataset/apiDataset';
75+
import { GetQuoteDataProps } from '@/pages/api/core/chat/quote/getQuote';
7576

7677
/* ======================== dataset ======================= */
7778
export const getDatasets = (data: GetDatasetListBody) =>
@@ -216,8 +217,8 @@ export const delOneDatasetDataById = (id: string) =>
216217
DELETE<string>(`/core/dataset/data/delete`, { id });
217218

218219
// Get quote data
219-
export const getQuoteData = (id: string) =>
220-
GET<GetQuoteDataResponse>(`/core/dataset/data/getQuoteData`, { id });
220+
export const getQuoteData = (data: GetQuoteDataProps) =>
221+
POST<GetQuoteDataResponse>(`/core/dataset/data/getQuoteData`, data);
221222

222223
/* ================ training ==================== */
223224
export const postRebuildEmbedding = (data: rebuildEmbeddingBody) =>

0 commit comments

Comments
 (0)