MCPcopy Create free account
hub / github.com/di-sukharev/opencommit / prepareFormData

Function prepareFormData

out/cli.cjs:76183–76214  ·  view source on GitHub ↗
(formData, request3)

Source from the content-addressed store, hash-verified

76181 urlSearchParams.append(key, subValue.toString());
76182 }
76183 } else {
76184 urlSearchParams.append(key, value.toString());
76185 }
76186 }
76187 return urlSearchParams.toString();
76188}
76189async function prepareFormData(formData, request3) {
76190 const contentType = request3.headers.get("Content-Type");
76191 if (contentType && !contentType.startsWith("multipart/form-data")) {
76192 return;
76193 }
76194 request3.headers.set("Content-Type", contentType !== null && contentType !== void 0 ? contentType : "multipart/form-data");
76195 const parts = [];
76196 for (const [fieldName, values] of Object.entries(formData)) {
76197 for (const value of Array.isArray(values) ? values : [values]) {
76198 if (typeof value === "string") {
76199 parts.push({
76200 headers: createHttpHeaders({
76201 "Content-Disposition": `form-data; name="${fieldName}"`
76202 }),
76203 body: stringToUint8Array(value, "utf-8")
76204 });
76205 } else if (value === void 0 || value === null || typeof value !== "object") {
76206 throw new Error(`Unexpected value for key ${fieldName}: ${value}. Value should be serialized to string first.`);
76207 } else {
76208 const fileName = value.name || "blob";
76209 const headers = createHttpHeaders();
76210 headers.set("Content-Disposition", `form-data; name="${fieldName}"; filename="${fileName}"`);
76211 headers.set("Content-Type", value.type || "application/octet-stream");
76212 parts.push({
76213 headers,
76214 body: value
76215 });
76216 }
76217 }

Callers 1

sendRequestFunction · 0.85

Calls 7

createHttpHeadersFunction · 0.85
stringToUint8ArrayFunction · 0.85
startsWithMethod · 0.80
getMethod · 0.45
setMethod · 0.45
entriesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected