MCPcopy Create free account
hub / github.com/smallfawn/QLScriptPublic / parseBody

Function parseBody

tools/sendNotify.js:1457–1477  ·  view source on GitHub ↗
(body, contentType, valueFormatFn)

Source from the content-addressed store, hash-verified

1455}
1456
1457function parseBody(body, contentType, valueFormatFn) {
1458 if (contentType === 'text/plain' || !body) {
1459 return valueFormatFn && body ? valueFormatFn(body) : body;
1460 }
1461
1462 const parsed = parseString(body, valueFormatFn);
1463
1464 switch (contentType) {
1465 case 'multipart/form-data':
1466 return Object.keys(parsed).reduce((p, c) => {
1467 p.append(c, parsed[c]);
1468 return p;
1469 }, new FormData());
1470 case 'application/x-www-form-urlencoded':
1471 return Object.keys(parsed).reduce((p, c) => {
1472 return p ? `${p}&${c}=${parsed[c]}` : `${c}=${parsed[c]}`;
1473 });
1474 }
1475
1476 return parsed;
1477}
1478
1479function formatBodyFun(contentType, body) {
1480 if (!body) return {};

Callers 1

webhookNotifyFunction · 0.70

Calls 1

parseStringFunction · 0.70

Tested by

no test coverage detected