MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / ShareXFormFields

Function ShareXFormFields

settings.tsx:552–711  ·  view source on GitHub ↗
(props: { store: { sharexConfig?: string; }; update: () => void; })

Source from the content-addressed store, hash-verified

550}
551
552function ShareXFormFields(props: { store: { sharexConfig?: string; }; update: () => void; }) {
553 const { store, update } = props;
554 const config = readShareXConfigObject(store.sharexConfig);
555
556 const setField = (key: string, value: string) => {
557 const next = readShareXConfigObject(store.sharexConfig);
558 if (value.trim() === "") delete next[key];
559 else next[key] = value;
560 store.sharexConfig = JSON.stringify(next, null, 2);
561 update();
562 };
563
564 const method = String(config.RequestMethod || "POST");
565 const body = String(config.Body || "MultipartFormData");
566 const isMultipart = body === "MultipartFormData" || body === "FormData";
567
568 const [headersText, setHeadersText] = React.useState(() => {
569 const headers = config.Headers;
570 return headers && typeof headers === "object" && Object.keys(headers).length
571 ? JSON.stringify(headers, null, 2)
572 : "";
573 });
574 const [headersInvalid, setHeadersInvalid] = React.useState(false);
575
576 const [argsText, setArgsText] = React.useState(() => {
577 const args = config.Arguments;
578 return args && typeof args === "object" && Object.keys(args).length
579 ? JSON.stringify(args, null, 2)
580 : "";
581 });
582 const [argsInvalid, setArgsInvalid] = React.useState(false);
583
584 const applyHeaders = (text: string) => {
585 setHeadersText(text);
586 const next = readShareXConfigObject(store.sharexConfig);
587
588 if (text.trim() === "") {
589 delete next.Headers;
590 store.sharexConfig = JSON.stringify(next, null, 2);
591 setHeadersInvalid(false);
592 update();
593 return;
594 }
595
596 try {
597 const parsed = JSON.parse(text);
598 if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("not an object");
599 next.Headers = parsed;
600 store.sharexConfig = JSON.stringify(next, null, 2);
601 setHeadersInvalid(false);
602 update();
603 } catch {
604 setHeadersInvalid(true);
605 }
606 };
607
608 const applyArgs = (text: string) => {
609 setArgsText(text);

Callers

nothing calls this directly

Calls 2

readShareXConfigObjectFunction · 0.85
setFieldFunction · 0.85

Tested by

no test coverage detected