mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
perf: http body;perf: create by json;perf: create by curl (#3570)
* perf: http body * feat: create app by json (#3557) * feat: create app by json * fix build * perf: create by json;perf: create by curl * fix: ts --------- Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
@@ -5,6 +5,6 @@ export const getErrText = (err: any, def = ''): any => {
|
||||
typeof err === 'string'
|
||||
? err
|
||||
: err?.response?.data?.message || err?.response?.message || err?.message || def;
|
||||
msg && console.log('error =>', msg);
|
||||
// msg && console.log('error =>', msg);
|
||||
return replaceSensitiveText(msg);
|
||||
};
|
||||
|
38
packages/global/common/string/http.ts
Normal file
38
packages/global/common/string/http.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import parse from '@bany/curl-to-json';
|
||||
|
||||
type RequestMethod = 'get' | 'post' | 'put' | 'delete' | 'patch';
|
||||
const methodMap: { [K in RequestMethod]: string } = {
|
||||
get: 'GET',
|
||||
post: 'POST',
|
||||
put: 'PUT',
|
||||
delete: 'DELETE',
|
||||
patch: 'PATCH'
|
||||
};
|
||||
|
||||
export const parseCurl = (curlContent: string) => {
|
||||
const parsed = parse(curlContent);
|
||||
|
||||
if (!parsed.url) {
|
||||
throw new Error('url not found');
|
||||
}
|
||||
|
||||
const newParams = Object.keys(parsed.params || {}).map((key) => ({
|
||||
key,
|
||||
value: parsed.params?.[key],
|
||||
type: 'string'
|
||||
}));
|
||||
const newHeaders = Object.keys(parsed.header || {}).map((key) => ({
|
||||
key,
|
||||
value: parsed.header?.[key],
|
||||
type: 'string'
|
||||
}));
|
||||
const newBody = JSON.stringify(parsed.data, null, 2);
|
||||
|
||||
return {
|
||||
url: parsed.url,
|
||||
method: methodMap[parsed.method?.toLowerCase() as RequestMethod] || 'GET',
|
||||
params: newParams,
|
||||
headers: newHeaders,
|
||||
body: newBody
|
||||
};
|
||||
};
|
@@ -5,6 +5,8 @@ import type { FlowNodeInputItemType } from '../workflow/type/io.d';
|
||||
import { getAppChatConfig } from '../workflow/utils';
|
||||
import { StoreNodeItemType } from '../workflow/type/node';
|
||||
import { DatasetSearchModeEnum } from '../dataset/constants';
|
||||
import { WorkflowTemplateBasicType } from '../workflow/type';
|
||||
import { AppTypeEnum } from './constants';
|
||||
|
||||
export const getDefaultAppForm = (): AppSimpleEditFormType => {
|
||||
return {
|
||||
@@ -127,3 +129,20 @@ export const appWorkflow2Form = ({
|
||||
|
||||
return defaultAppForm;
|
||||
};
|
||||
|
||||
export const getAppType = (config?: WorkflowTemplateBasicType | AppSimpleEditFormType) => {
|
||||
if (!config) return '';
|
||||
|
||||
if ('aiSettings' in config) {
|
||||
return AppTypeEnum.simple;
|
||||
}
|
||||
|
||||
if (!('nodes' in config)) return '';
|
||||
if (config.nodes.some((node) => node.flowNodeType === 'workflowStart')) {
|
||||
return AppTypeEnum.workflow;
|
||||
}
|
||||
if (config.nodes.some((node) => node.flowNodeType === 'pluginInput')) {
|
||||
return AppTypeEnum.plugin;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
@@ -14,7 +14,8 @@
|
||||
"openai": "4.61.0",
|
||||
"openapi-types": "^12.1.3",
|
||||
"json5": "^2.2.3",
|
||||
"timezones-list": "^3.0.2"
|
||||
"timezones-list": "^3.0.2",
|
||||
"@bany/curl-to-json": "^1.2.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
|
Reference in New Issue
Block a user