MCPcopy Create free account
hub / github.com/EsperoTech/yaade / buildFormDataBody

Function buildFormDataBody

extension/background.js:54–85  ·  view source on GitHub ↗
(body, senderUrl)

Source from the content-addressed store, hash-verified

52}
53
54async function buildFormDataBody(body, senderUrl) {
55 let host = senderUrl.split("/#/")[0];
56 if (host.endsWith("/")) {
57 host = host.slice(0, -1);
58 }
59 const formData = new FormData();
60 if (!body) {
61 return formData;
62 }
63 for (const part of body) {
64 if (part.isEnabled === false) {
65 continue;
66 }
67 if (part.type === "file") {
68 const fileId = part.file?.id;
69 if (!fileId) {
70 continue;
71 }
72 const filename = part.file?.name || "unkown-filename";
73 const res = await fetch(`${host}/api/files/${fileId}`);
74 if (res.status !== 200) {
75 throw new Error(`Failed to fetch file: ${filename}`);
76 }
77 const blob = await res.blob();
78 const file = new File([blob], filename, { type: blob.type });
79 formData.append(part.key, file);
80 } else {
81 formData.append(part.key, part.value);
82 }
83 }
84 return formData;
85}
86
87function connectWebsocket(request, senderTabId, sendResponse) {
88 const wsId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);

Callers 1

buildOptionsFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected