feat: binary files

This commit is contained in:
Joel 2024-08-29 11:50:42 +08:00
parent 41f0ce1012
commit 2a6629d435
2 changed files with 9 additions and 5 deletions

View File

@ -89,7 +89,7 @@ const EditBody: FC<Props> = ({
}, [onChange, payload])
const filterOnlyFileVariable = (varPayload: Var) => {
return varPayload.type === VarType.file
return [VarType.file, VarType.arrayFile].includes(varPayload.type)
}
const handleBodyValueChange = useCallback((value: string) => {
@ -109,7 +109,13 @@ const EditBody: FC<Props> = ({
const handleBinaryFileChange = useCallback((value: ValueSelector | string) => {
const newBody = produce(payload, (draft: Body) => {
draft.binaryFileVariable = value as ValueSelector
if ((draft.data as BodyPayload).length === 0) {
(draft.data as BodyPayload).push({
id: uniqueId(UNIQUE_ID_PREFIX),
type: BodyPayloadValueType.file,
})
}
(draft.data as BodyPayload)[0].file = value as ValueSelector
})
onChange(newBody)
}, [onChange, payload])
@ -172,12 +178,11 @@ const EditBody: FC<Props> = ({
/>
)}
{/* TODO */}
{type === BodyType.binary && (
<VarReferencePicker
nodeId={nodeId}
readonly={readonly}
value={payload.binaryFileVariable || []}
value={bodyPayload[0]?.file || []}
onChange={handleBinaryFileChange}
filterVar={filterOnlyFileVariable}
/>

View File

@ -39,7 +39,6 @@ export type BodyPayload = {
export type Body = {
type: BodyType
data: string | BodyPayload // string is deprecated, it would convert to BodyPayload after loaded
binaryFileVariable?: ValueSelector
}
export enum AuthorizationType {