feat: add individual content types for formadata (#4550)

Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
Akash K
2024-11-24 19:36:10 +05:30
committed by GitHub
parent b78cd57884
commit c74c42ebaf
10 changed files with 161 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ import { HoppCLIError } from "./errors";
export type FormDataEntry = {
key: string;
value: string | Blob;
contentType?: string;
};
export type HoppEnvPair = Environment["variables"][number];

View File

@@ -52,7 +52,21 @@ const getValidRequests = (
export const toFormData = (values: FormDataEntry[]) => {
const formData = new FormData();
values.forEach(({ key, value }) => formData.append(key, value));
values.forEach(({ key, value, contentType }) => {
if (contentType) {
formData.append(
key,
new Blob([value], {
type: contentType,
}),
key
);
return;
}
formData.append(key, value);
});
return formData;
};

View File

@@ -422,11 +422,13 @@ function getFinalBodyFromRequest(
? x.value.map((v) => ({
key: parseTemplateString(x.key, resolvedVariables),
value: v as string | Blob,
contentType: x.contentType,
}))
: [
{
key: parseTemplateString(x.key, resolvedVariables),
value: parseTemplateString(x.value, resolvedVariables),
contentType: x.contentType,
},
]
),