feat: form data support file type

This commit is contained in:
Joel 2024-08-09 10:29:29 +08:00
parent 939df16655
commit 97b2a42cc3
6 changed files with 22 additions and 3 deletions

View File

@ -23,15 +23,17 @@ const allTypes = [
BodyType.none, BodyType.none,
BodyType.formData, BodyType.formData,
BodyType.xWwwFormUrlencoded, BodyType.xWwwFormUrlencoded,
BodyType.rawText,
BodyType.json, BodyType.json,
BodyType.rawText,
BodyType.binary,
] ]
const bodyTextMap = { const bodyTextMap = {
[BodyType.none]: 'none', [BodyType.none]: 'none',
[BodyType.formData]: 'form-data', [BodyType.formData]: 'form-data',
[BodyType.xWwwFormUrlencoded]: 'x-www-form-urlencoded', [BodyType.xWwwFormUrlencoded]: 'x-www-form-urlencoded',
[BodyType.rawText]: 'raw text', [BodyType.rawText]: 'raw',
[BodyType.json]: 'JSON', [BodyType.json]: 'JSON',
[BodyType.binary]: 'binary',
} }
const EditBody: FC<Props> = ({ const EditBody: FC<Props> = ({
@ -125,6 +127,7 @@ const EditBody: FC<Props> = ({
list={body} list={body}
onChange={setBody} onChange={setBody}
onAdd={addBody} onAdd={addBody}
isSupportFile={type === BodyType.formData}
/> />
)} )}

View File

@ -10,6 +10,7 @@ type Props = {
list: KeyValue[] list: KeyValue[]
onChange: (newList: KeyValue[]) => void onChange: (newList: KeyValue[]) => void
onAdd: () => void onAdd: () => void
isSupportFile: boolean
// toggleKeyValueEdit: () => void // toggleKeyValueEdit: () => void
} }
@ -19,6 +20,7 @@ const KeyValueList: FC<Props> = ({
list, list,
onChange, onChange,
onAdd, onAdd,
isSupportFile,
// toggleKeyValueEdit, // toggleKeyValueEdit,
}) => { }) => {
// const handleBulkValueChange = useCallback((value: string) => { // const handleBulkValueChange = useCallback((value: string) => {
@ -48,6 +50,7 @@ const KeyValueList: FC<Props> = ({
list={list} list={list}
onChange={onChange} onChange={onChange}
onAdd={onAdd} onAdd={onAdd}
isSupportFile={isSupportFile}
// onSwitchToBulkEdit={toggleKeyValueEdit} // onSwitchToBulkEdit={toggleKeyValueEdit}
/> />
// : <BulkEdit // : <BulkEdit

View File

@ -16,6 +16,7 @@ type Props = {
list: KeyValue[] list: KeyValue[]
onChange: (newList: KeyValue[]) => void onChange: (newList: KeyValue[]) => void
onAdd: () => void onAdd: () => void
isSupportFile?: boolean
// onSwitchToBulkEdit: () => void // onSwitchToBulkEdit: () => void
} }
@ -25,6 +26,7 @@ const KeyValueList: FC<Props> = ({
list, list,
onChange, onChange,
onAdd, onAdd,
isSupportFile,
// onSwitchToBulkEdit, // onSwitchToBulkEdit,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
@ -79,6 +81,7 @@ const KeyValueList: FC<Props> = ({
onAdd={onAdd} onAdd={onAdd}
readonly={readonly} readonly={readonly}
canRemove={list.length > 1} canRemove={list.length > 1}
isSupportFile={isSupportFile}
/> />
)) ))
} }

View File

@ -18,6 +18,7 @@ type Props = {
onRemove?: () => void onRemove?: () => void
placeholder?: string placeholder?: string
readOnly?: boolean readOnly?: boolean
isSupportFile?: boolean
} }
const InputItem: FC<Props> = ({ const InputItem: FC<Props> = ({
@ -30,6 +31,7 @@ const InputItem: FC<Props> = ({
onRemove, onRemove,
placeholder, placeholder,
readOnly, readOnly,
isSupportFile,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
@ -39,7 +41,11 @@ const InputItem: FC<Props> = ({
const { availableVars, availableNodesWithParent } = useAvailableVarList(nodeId, { const { availableVars, availableNodesWithParent } = useAvailableVarList(nodeId, {
onlyLeafNodeVar: false, onlyLeafNodeVar: false,
filterVar: (varPayload: Var) => { filterVar: (varPayload: Var) => {
return [VarType.string, VarType.number, VarType.secret].includes(varPayload.type) const supportVarTypes = [VarType.string, VarType.number, VarType.secret]
if (isSupportFile)
supportVarTypes.push(...[VarType.file, VarType.arrayFile])
return supportVarTypes.includes(varPayload.type)
}, },
}) })

View File

@ -20,6 +20,7 @@ type Props = {
onRemove: () => void onRemove: () => void
isLastItem: boolean isLastItem: boolean
onAdd: () => void onAdd: () => void
isSupportFile?: boolean
} }
const KeyValueItem: FC<Props> = ({ const KeyValueItem: FC<Props> = ({
@ -33,6 +34,7 @@ const KeyValueItem: FC<Props> = ({
onRemove, onRemove,
isLastItem, isLastItem,
onAdd, onAdd,
isSupportFile,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
@ -71,6 +73,7 @@ const KeyValueItem: FC<Props> = ({
onRemove={onRemove} onRemove={onRemove}
placeholder={t(`${i18nPrefix}.value`)!} placeholder={t(`${i18nPrefix}.value`)!}
readOnly={readonly} readOnly={readonly}
isSupportFile={isSupportFile}
/> />
</div> </div>
</div> </div>

View File

@ -15,6 +15,7 @@ export enum BodyType {
xWwwFormUrlencoded = 'x-www-form-urlencoded', xWwwFormUrlencoded = 'x-www-form-urlencoded',
rawText = 'raw-text', rawText = 'raw-text',
json = 'json', json = 'json',
binary = 'binary',
} }
export type KeyValue = { export type KeyValue = {