mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 05:19:08 +08:00
feat: http support body binary
This commit is contained in:
parent
97b2a42cc3
commit
bc5f109308
@ -39,10 +39,11 @@ export const isENV = (valueSelector: ValueSelector) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const inputVarTypeToVarType = (type: InputVarType): VarType => {
|
const inputVarTypeToVarType = (type: InputVarType): VarType => {
|
||||||
if (type === InputVarType.number)
|
return ({
|
||||||
return VarType.number
|
[InputVarType.number]: VarType.number,
|
||||||
|
[InputVarType.singleFile]: VarType.file,
|
||||||
return VarType.string
|
[InputVarType.multiFiles]: VarType.arrayFile,
|
||||||
|
} as any)[type] || VarType.string
|
||||||
}
|
}
|
||||||
|
|
||||||
const findExceptVarInObject = (obj: any, filterVar: (payload: Var, selector: ValueSelector) => boolean, value_selector: ValueSelector): Var => {
|
const findExceptVarInObject = (obj: any, filterVar: (payload: Var, selector: ValueSelector) => boolean, value_selector: ValueSelector): Var => {
|
||||||
|
@ -7,9 +7,10 @@ import { BodyType } from '../../types'
|
|||||||
import useKeyValueList from '../../hooks/use-key-value-list'
|
import useKeyValueList from '../../hooks/use-key-value-list'
|
||||||
import KeyValue from '../key-value'
|
import KeyValue from '../key-value'
|
||||||
import useAvailableVarList from '../../../_base/hooks/use-available-var-list'
|
import useAvailableVarList from '../../../_base/hooks/use-available-var-list'
|
||||||
|
import VarReferencePicker from '../../../_base/components/variable/var-reference-picker'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import InputWithVar from '@/app/components/workflow/nodes/_base/components/prompt/editor'
|
import InputWithVar from '@/app/components/workflow/nodes/_base/components/prompt/editor'
|
||||||
import type { Var } from '@/app/components/workflow/types'
|
import type { ValueSelector, Var } from '@/app/components/workflow/types'
|
||||||
import { VarType } from '@/app/components/workflow/types'
|
import { VarType } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -77,6 +78,10 @@ const EditBody: FC<Props> = ({
|
|||||||
onChange(newBody)
|
onChange(newBody)
|
||||||
}, type === BodyType.json)
|
}, type === BodyType.json)
|
||||||
|
|
||||||
|
const filterOnlyFileVariable = (varPayload: Var) => {
|
||||||
|
return varPayload.type === VarType.file
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isCurrentKeyValue)
|
if (!isCurrentKeyValue)
|
||||||
return
|
return
|
||||||
@ -99,6 +104,13 @@ const EditBody: FC<Props> = ({
|
|||||||
onChange(newBody)
|
onChange(newBody)
|
||||||
}, [onChange, payload])
|
}, [onChange, payload])
|
||||||
|
|
||||||
|
const handleBinaryFileChange = useCallback((value: ValueSelector | string) => {
|
||||||
|
const newBody = produce(payload, (draft: Body) => {
|
||||||
|
draft.binaryFileVariable = value as ValueSelector
|
||||||
|
})
|
||||||
|
onChange(newBody)
|
||||||
|
}, [onChange, payload])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{/* body type */}
|
{/* body type */}
|
||||||
@ -156,6 +168,16 @@ const EditBody: FC<Props> = ({
|
|||||||
readOnly={readonly}
|
readOnly={readonly}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{type === BodyType.binary && (
|
||||||
|
<VarReferencePicker
|
||||||
|
nodeId={nodeId}
|
||||||
|
readonly={readonly}
|
||||||
|
value={payload.binaryFileVariable || []}
|
||||||
|
onChange={handleBinaryFileChange}
|
||||||
|
filterVar={filterOnlyFileVariable}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,7 @@ type Props = {
|
|||||||
list: KeyValue[]
|
list: KeyValue[]
|
||||||
onChange: (newList: KeyValue[]) => void
|
onChange: (newList: KeyValue[]) => void
|
||||||
onAdd: () => void
|
onAdd: () => void
|
||||||
isSupportFile: boolean
|
isSupportFile?: boolean
|
||||||
// toggleKeyValueEdit: () => void
|
// toggleKeyValueEdit: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,9 @@ const nodeDefault: NodeDefault<HttpNodeType> = {
|
|||||||
if (!errorMessages && !payload.url)
|
if (!errorMessages && !payload.url)
|
||||||
errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.api') })
|
errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.api') })
|
||||||
|
|
||||||
|
if (!errorMessages && payload.body.type === BodyType.binary && !payload.body.binaryFileVariable)
|
||||||
|
errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.binaryFileVariable') })
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isValid: !errorMessages,
|
isValid: !errorMessages,
|
||||||
errorMessage: errorMessages,
|
errorMessage: errorMessages,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import type { CommonNodeType, Variable } from '@/app/components/workflow/types'
|
import type { CommonNodeType, ValueSelector, Variable } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
export enum Method {
|
export enum Method {
|
||||||
get = 'get',
|
get = 'get',
|
||||||
@ -27,6 +27,7 @@ export type KeyValue = {
|
|||||||
export type Body = {
|
export type Body = {
|
||||||
type: BodyType
|
type: BodyType
|
||||||
data: string
|
data: string
|
||||||
|
binaryFileVariable?: ValueSelector
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AuthorizationType {
|
export enum AuthorizationType {
|
||||||
|
@ -323,6 +323,7 @@ const translation = {
|
|||||||
headers: 'Headers',
|
headers: 'Headers',
|
||||||
params: 'Params',
|
params: 'Params',
|
||||||
body: 'Body',
|
body: 'Body',
|
||||||
|
binaryFileVariable: 'Binary File Variable',
|
||||||
outputVars: {
|
outputVars: {
|
||||||
body: 'Response Content',
|
body: 'Response Content',
|
||||||
statusCode: 'Response Status Code',
|
statusCode: 'Response Status Code',
|
||||||
|
@ -323,6 +323,7 @@ const translation = {
|
|||||||
headers: 'Headers',
|
headers: 'Headers',
|
||||||
params: 'Params',
|
params: 'Params',
|
||||||
body: 'Body',
|
body: 'Body',
|
||||||
|
binaryFileVariable: 'Binary 文件变量',
|
||||||
outputVars: {
|
outputVars: {
|
||||||
body: '响应内容',
|
body: '响应内容',
|
||||||
statusCode: '响应状态码',
|
statusCode: '响应状态码',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user