MCPcopy Create free account
hub / github.com/pywebio/PyWebIO / submit

Method submit

webiojs/src/handlers/pin.ts:66–97  ·  view source on GitHub ↗
(msg: ClientEvent, file_input_names: string[])

Source from the content-addressed store, hash-verified

64 * for file input, the `input_value` is in {multiple: bool, files: File[] }
65 * */
66 submit(msg: ClientEvent, file_input_names: string[]) {
67 // See: deserialize_binary_event() in pywebio/platform/utils.py
68 let file_blobs:Blob[] = [];
69 for (let name of file_input_names) {
70 if (msg.data && msg.data[name]) {
71 // {multiple: bool, files: File[]}
72 let {multiple, files} = msg.data[name];
73 msg.data[name] = multiple ? [] : null; // replace file value with initial value
74 file_blobs.push(...files.map((file: File) => serialize_file(file, name)));
75 }
76 }
77
78 if (file_blobs.length) {
79 let toast = Toastify({
80 text: `⏳${t("file_uploading")} 0%`,
81 duration: -1,
82 gravity: "top",
83 position: 'center',
84 backgroundColor: '#1565c0',
85 });
86 toast.showToast();
87 state.CurrentSession.send_buffer(
88 new Blob([serialize_json(msg), ...file_blobs], {type: 'application/octet-stream'}),
89 (loaded: number, total: number) => {
90 toast.toastElement.innerText = `⏳${t("file_uploading")} ${((loaded / total)*100).toFixed(2)}%`;
91 if (total - loaded < 100) toast.hideToast();
92 }
93 );
94 } else {
95 state.CurrentSession.send_message(msg);
96 }
97 }
98}

Callers 4

handle_messageMethod · 0.95
onchangeMethod · 0.95
test_inputFunction · 0.80
codemirror.min.jsFile · 0.80

Calls 6

serialize_fileFunction · 0.90
tFunction · 0.90
serialize_jsonFunction · 0.90
pushMethod · 0.80
send_bufferMethod · 0.65
send_messageMethod · 0.65

Tested by 1

test_inputFunction · 0.64