Debian Codegraph @

src/LibBGCode/wasm/index.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>File Processing</title>
7 </head>
8 <body>
9 <h1>File Processing</h1>
10
11 <!-- File Upload Form -->
12 <form id="upload-form" enctype="multipart/form-data">
13 <input type="file" id="file-input" name="file" accept=".gcode,.bgcode">
14 <button type="button" id="process-button">Process File</button>
15 </form>
16
17 <!-- Processing Status -->
18 <div id="processing-status" style="display: none;">
19 <p>Processing the file...</p>
20 </div>
21
22 <!-- Download Button -->
23 <a id="download-link" style="display: none;" download="processed.bgcode">
24 <button type="button" id="download-button">Download Processed File</button>
25 </a>
26
27 <!--Include the web assembly for gcode conversion-->
28 <script src="bgcode.js"></script>
29
30 <script>
31 function getFileExtension(file) {
32 const parts = file.name.split(".");
33 var ret = "";
34 if (parts.length > 1) {
35 ret = parts[parts.length - 1].toLowerCase();
36 }
37
38 return ret;
39 }
40
41 function getFileName(file) {
42 const parts = file.name.split(".");
43 var ret = "";
44 if (parts.length > 1) {
45 ret = parts[0].toLowerCase();
46 }
47
48 return ret;
49 }
50
51 document.addEventListener("DOMContentLoaded", function () {
52 const uploadForm = document.getElementById("upload-form");
53 const fileInput = document.getElementById("file-input");
54 const processButton = document.getElementById("process-button");
55 const processingStatus = document.getElementById("processing-status");
56 const downloadLink = document.getElementById("download-link");
57 const downloadButton = document.getElementById("download-button");
58
59 var binaryGcode = null;
60 var asciiGcode = null;
61 var jsfile = null;
62
63 processButton.addEventListener("click", function () {
64 // Simulate processing by adding a timeout (replace with your actual processing logic)
65 processingStatus.style.display = "block";
66
67 binaryGcode = null;
68 asciiGcode = null;
69
70 if (fileInput.files.length > 0) {
71 jsfile = fileInput.files.item(0);
72
73 let processAscii = function (data) {
74 let config = Module.get_config();
75 config.compression.file_metadata = Module.BGCode_CompressionType.Heatshrink_11_4;
76 let outbuf = Module.ascii2bgcode_cfg(data, config);
77 binaryGcode = new Uint8Array(outbuf);
78 }
79
80 let processBinary = function (data) {
81 asciiGcode = Module.bgcode2ascii_and_verify(data);
82 }
83
84 let processFn = getFileExtension(jsfile) === "bgcode" ?
85 processBinary :
86 processAscii;
87
88 jsfile.arrayBuffer().then((data) => {
89 processFn(data);
90
91 processingStatus.style.display = "none";
92 downloadLink.style.display = "block";
93 });
94 }
95 });
96
97 downloadButton.addEventListener("click", function () {
98 var url = null;
99 if (binaryGcode) {
100 const blob = new Blob([binaryGcode], { type: "application/octet-stream" });
101 url = window.URL.createObjectURL(blob);
102
103 downloadLink.download = getFileName(jsfile) + ".bgcode";
104 } else if (asciiGcode) {
105 const blob = new Blob([asciiGcode], { type: "text/plain" });
106 url = window.URL.createObjectURL(blob);
107
108 downloadLink.download = getFileName(jsfile) + ".gcode";
109 }
110
111 // Set the href and click the link to trigger the download
112 downloadLink.href = url;
113 });
114 });
115 </script>
116 </body>
117 </html>