mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 12:20:34 +00:00
perf: fetch url (#4687)
This commit is contained in:
@@ -187,7 +187,6 @@
|
|||||||
"type.Plugin": "Plugin",
|
"type.Plugin": "Plugin",
|
||||||
"type.Simple bot": "Simple App",
|
"type.Simple bot": "Simple App",
|
||||||
"type.Workflow bot": "Workflow",
|
"type.Workflow bot": "Workflow",
|
||||||
"type.error.URLempty": "The URL cannot be empty",
|
|
||||||
"type.error.Workflow data is empty": "No workflow data was obtained",
|
"type.error.Workflow data is empty": "No workflow data was obtained",
|
||||||
"type.error.workflowresponseempty": "Response content is empty",
|
"type.error.workflowresponseempty": "Response content is empty",
|
||||||
"type_not_recognized": "App type not recognized",
|
"type_not_recognized": "App type not recognized",
|
||||||
|
@@ -196,7 +196,6 @@
|
|||||||
"type.Plugin": "插件",
|
"type.Plugin": "插件",
|
||||||
"type.Simple bot": "简易应用",
|
"type.Simple bot": "简易应用",
|
||||||
"type.Workflow bot": "工作流",
|
"type.Workflow bot": "工作流",
|
||||||
"type.error.URLempty": "URL不能为空",
|
|
||||||
"type.error.Workflow data is empty": "没有获取到工作流数据",
|
"type.error.Workflow data is empty": "没有获取到工作流数据",
|
||||||
"type.error.workflowresponseempty": "响应内容为空",
|
"type.error.workflowresponseempty": "响应内容为空",
|
||||||
"type_not_recognized": "未识别到应用类型",
|
"type_not_recognized": "未识别到应用类型",
|
||||||
|
@@ -187,7 +187,6 @@
|
|||||||
"type.Plugin": "外掛",
|
"type.Plugin": "外掛",
|
||||||
"type.Simple bot": "簡易應用程式",
|
"type.Simple bot": "簡易應用程式",
|
||||||
"type.Workflow bot": "工作流程",
|
"type.Workflow bot": "工作流程",
|
||||||
"type.error.URLempty": "URL不能為空",
|
|
||||||
"type.error.Workflow data is empty": "沒有獲取到工作流數據",
|
"type.error.Workflow data is empty": "沒有獲取到工作流數據",
|
||||||
"type.error.workflowresponseempty": "響應內容為空",
|
"type.error.workflowresponseempty": "響應內容為空",
|
||||||
"type_not_recognized": "未識別到應用程式類型",
|
"type_not_recognized": "未識別到應用程式類型",
|
||||||
|
@@ -16,8 +16,7 @@ import { postCreateApp } from '@/web/core/app/api';
|
|||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { form2AppWorkflow } from '@/web/core/app/utils';
|
import { form2AppWorkflow } from '@/web/core/app/utils';
|
||||||
import ImportAppConfigEditor from '@/pageComponents/app/ImportAppConfigEditor';
|
import ImportAppConfigEditor from '@/pageComponents/app/ImportAppConfigEditor';
|
||||||
import { useToast } from '@fastgpt/web/hooks/useToast';
|
import { postFetchWorkflow } from '@/web/support/marketing/api';
|
||||||
import { getFetchWorkflow } from '@/web/core/app/api/app';
|
|
||||||
import {
|
import {
|
||||||
getUtmParams,
|
getUtmParams,
|
||||||
getUtmWorkflow,
|
getUtmWorkflow,
|
||||||
@@ -50,7 +49,7 @@ const JsonImportModal = ({ onClose }: { onClose: () => void }) => {
|
|||||||
const url = getUtmWorkflow();
|
const url = getUtmWorkflow();
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
|
|
||||||
const workflowData = await getFetchWorkflow({ url });
|
const workflowData = await postFetchWorkflow({ url });
|
||||||
|
|
||||||
setValue('workflowStr', JSON.stringify(workflowData, null, 2));
|
setValue('workflowStr', JSON.stringify(workflowData, null, 2));
|
||||||
|
|
||||||
|
@@ -1,51 +0,0 @@
|
|||||||
import { NextAPI } from '@/service/middleware/entry';
|
|
||||||
import { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
|
||||||
import axios from 'axios';
|
|
||||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
|
||||||
|
|
||||||
export type FetchWorkflowBody = {
|
|
||||||
url: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FetchWorkflowQuery = {
|
|
||||||
url: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FetchWorkflowResponseType = ApiResponseType<{
|
|
||||||
data: JSON;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
async function handler(
|
|
||||||
req: ApiRequestProps<FetchWorkflowBody, FetchWorkflowQuery>,
|
|
||||||
res: FetchWorkflowResponseType
|
|
||||||
) {
|
|
||||||
await authCert({ req, authToken: true });
|
|
||||||
|
|
||||||
const url = req.body?.url || req.query?.url;
|
|
||||||
|
|
||||||
if (!url) {
|
|
||||||
return Promise.reject('app:type.error.URLempty');
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await axios.get(url, {
|
|
||||||
headers: {
|
|
||||||
Accept: 'application/json',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'User-Agent': 'Mozilla/5.0 (compatible; FastGPT/1.0)'
|
|
||||||
},
|
|
||||||
timeout: 30000,
|
|
||||||
validateStatus: (status) => status < 500
|
|
||||||
});
|
|
||||||
|
|
||||||
const contentType = response.headers['content-type'] || '';
|
|
||||||
|
|
||||||
if (!response.data || response.data.length === 0) {
|
|
||||||
return Promise.reject('app:type.error.workflowresponseempty');
|
|
||||||
}
|
|
||||||
|
|
||||||
JSON.parse(JSON.stringify(response.data));
|
|
||||||
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default NextAPI(handler);
|
|
@@ -0,0 +1,46 @@
|
|||||||
|
import { NextAPI } from '@/service/middleware/entry';
|
||||||
|
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||||
|
import { isInternalAddress } from '@fastgpt/service/common/system/utils';
|
||||||
|
import { NextApiResponse } from 'next';
|
||||||
|
|
||||||
|
export type FetchWorkflowBody = {
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type FetchWorkflowQuery = {};
|
||||||
|
|
||||||
|
export type FetchWorkflowResponseType = {
|
||||||
|
data: Record<string, any>;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function handler(
|
||||||
|
req: ApiRequestProps<FetchWorkflowBody, FetchWorkflowQuery>,
|
||||||
|
res: NextApiResponse
|
||||||
|
): Promise<FetchWorkflowResponseType> {
|
||||||
|
await authCert({ req, authToken: true });
|
||||||
|
|
||||||
|
const url = req.body?.url;
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
return Promise.reject('Url is empty');
|
||||||
|
}
|
||||||
|
if (isInternalAddress(url)) {
|
||||||
|
return Promise.reject('Url is invalid');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await axios.get(url, {
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (compatible; FastGPT/1.0)'
|
||||||
|
},
|
||||||
|
timeout: 30000,
|
||||||
|
validateStatus: (status) => status < 500
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NextAPI(handler);
|
@@ -84,7 +84,7 @@ export const useInitApp = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Marketing data track
|
// Marketing data track
|
||||||
useEffect(() => {
|
useMount(() => {
|
||||||
setInviterId(hiId);
|
setInviterId(hiId);
|
||||||
setBdVId(bd_vid);
|
setBdVId(bd_vid);
|
||||||
setUtmWorkflow(utm_workflow);
|
setUtmWorkflow(utm_workflow);
|
||||||
@@ -97,7 +97,9 @@ export const useInitApp = () => {
|
|||||||
};
|
};
|
||||||
setUtmParams(utmParams);
|
setUtmParams(utmParams);
|
||||||
setFastGPTSem({ keyword: k, ...utmParams });
|
setFastGPTSem({ keyword: k, ...utmParams });
|
||||||
}, [bd_vid, hiId, k, utm_workflow, sourceDomain, utm_source, utm_medium, utm_content]);
|
|
||||||
|
router.replace(router.pathname);
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
feConfigs,
|
feConfigs,
|
||||||
|
@@ -10,10 +10,6 @@ import type {
|
|||||||
} from '@/pages/api/core/app/transitionWorkflow';
|
} from '@/pages/api/core/app/transitionWorkflow';
|
||||||
import type { copyAppQuery, copyAppResponse } from '@/pages/api/core/app/copy';
|
import type { copyAppQuery, copyAppResponse } from '@/pages/api/core/app/copy';
|
||||||
|
|
||||||
import type {
|
|
||||||
FetchWorkflowQuery,
|
|
||||||
FetchWorkflowResponseType
|
|
||||||
} from '@/pages/api/core/app/fetchWorkflow';
|
|
||||||
/* folder */
|
/* folder */
|
||||||
export const postCreateAppFolder = (data: CreateAppFolderBody) =>
|
export const postCreateAppFolder = (data: CreateAppFolderBody) =>
|
||||||
POST('/core/app/folder/create', data);
|
POST('/core/app/folder/create', data);
|
||||||
@@ -29,6 +25,3 @@ export const postTransition2Workflow = (data: transitionWorkflowBody) =>
|
|||||||
POST<transitionWorkflowResponse>('/core/app/transitionWorkflow', data);
|
POST<transitionWorkflowResponse>('/core/app/transitionWorkflow', data);
|
||||||
|
|
||||||
export const postCopyApp = (data: copyAppQuery) => POST<copyAppResponse>('/core/app/copy', data);
|
export const postCopyApp = (data: copyAppQuery) => POST<copyAppResponse>('/core/app/copy', data);
|
||||||
|
|
||||||
export const getFetchWorkflow = (data: FetchWorkflowQuery) =>
|
|
||||||
GET<FetchWorkflowResponseType>('/core/app/fetchWorkflow', data);
|
|
||||||
|
8
projects/app/src/web/support/marketing/api.ts
Normal file
8
projects/app/src/web/support/marketing/api.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { POST } from '@/web/common/api/request';
|
||||||
|
import {
|
||||||
|
FetchWorkflowQuery,
|
||||||
|
FetchWorkflowResponseType
|
||||||
|
} from '@/pages/api/support/marketing/fetchWorkflow';
|
||||||
|
|
||||||
|
export const postFetchWorkflow = (data: FetchWorkflowQuery) =>
|
||||||
|
POST<FetchWorkflowResponseType>('/support/marketing/fetchWorkflow', data);
|
Reference in New Issue
Block a user