mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-19 15:19:07 +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 => {
|
||||
if (type === InputVarType.number)
|
||||
return VarType.number
|
||||
|
||||
return VarType.string
|
||||
return ({
|
||||
[InputVarType.number]: VarType.number,
|
||||
[InputVarType.singleFile]: VarType.file,
|
||||
[InputVarType.multiFiles]: VarType.arrayFile,
|
||||
} as any)[type] || VarType.string
|
||||
}
|
||||
|
||||
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 KeyValue from '../key-value'
|
||||
import useAvailableVarList from '../../../_base/hooks/use-available-var-list'
|
||||
import VarReferencePicker from '../../../_base/components/variable/var-reference-picker'
|
||||
import cn from '@/utils/classnames'
|
||||
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'
|
||||
|
||||
type Props = {
|
||||
@ -77,6 +78,10 @@ const EditBody: FC<Props> = ({
|
||||
onChange(newBody)
|
||||
}, type === BodyType.json)
|
||||
|
||||
const filterOnlyFileVariable = (varPayload: Var) => {
|
||||
return varPayload.type === VarType.file
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!isCurrentKeyValue)
|
||||
return
|
||||
@ -99,6 +104,13 @@ const EditBody: FC<Props> = ({
|
||||
onChange(newBody)
|
||||
}, [onChange, payload])
|
||||
|
||||
const handleBinaryFileChange = useCallback((value: ValueSelector | string) => {
|
||||
const newBody = produce(payload, (draft: Body) => {
|
||||
draft.binaryFileVariable = value as ValueSelector
|
||||
})
|
||||
onChange(newBody)
|
||||
}, [onChange, payload])
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* body type */}
|
||||
@ -156,6 +168,16 @@ const EditBody: FC<Props> = ({
|
||||
readOnly={readonly}
|
||||
/>
|
||||
)}
|
||||
|
||||
{type === BodyType.binary && (
|
||||
<VarReferencePicker
|
||||
nodeId={nodeId}
|
||||
readonly={readonly}
|
||||
value={payload.binaryFileVariable || []}
|
||||
onChange={handleBinaryFileChange}
|
||||
filterVar={filterOnlyFileVariable}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
@ -10,7 +10,7 @@ type Props = {
|
||||
list: KeyValue[]
|
||||
onChange: (newList: KeyValue[]) => void
|
||||
onAdd: () => void
|
||||
isSupportFile: boolean
|
||||
isSupportFile?: boolean
|
||||
// toggleKeyValueEdit: () => void
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,9 @@ const nodeDefault: NodeDefault<HttpNodeType> = {
|
||||
if (!errorMessages && !payload.url)
|
||||
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 {
|
||||
isValid: !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 {
|
||||
get = 'get',
|
||||
@ -27,6 +27,7 @@ export type KeyValue = {
|
||||
export type Body = {
|
||||
type: BodyType
|
||||
data: string
|
||||
binaryFileVariable?: ValueSelector
|
||||
}
|
||||
|
||||
export enum AuthorizationType {
|
||||
|
@ -323,6 +323,7 @@ const translation = {
|
||||
headers: 'Headers',
|
||||
params: 'Params',
|
||||
body: 'Body',
|
||||
binaryFileVariable: 'Binary File Variable',
|
||||
outputVars: {
|
||||
body: 'Response Content',
|
||||
statusCode: 'Response Status Code',
|
||||
|
@ -323,6 +323,7 @@ const translation = {
|
||||
headers: 'Headers',
|
||||
params: 'Params',
|
||||
body: 'Body',
|
||||
binaryFileVariable: 'Binary 文件变量',
|
||||
outputVars: {
|
||||
body: '响应内容',
|
||||
statusCode: '响应状态码',
|
||||
|
Loading…
x
Reference in New Issue
Block a user