Update templates/index.html
Browse files- templates/index.html +38 -11
templates/index.html
CHANGED
|
@@ -59,7 +59,6 @@
|
|
| 59 |
background: #005bb5;
|
| 60 |
}
|
| 61 |
</style>
|
| 62 |
-
<script src="https://cdn.socket.io/4.0.1/socket.io.min.js"></script>
|
| 63 |
</head>
|
| 64 |
<body>
|
| 65 |
<div class="terminal">
|
|
@@ -71,22 +70,50 @@
|
|
| 71 |
</div>
|
| 72 |
</div>
|
| 73 |
<script>
|
| 74 |
-
const socket = io();
|
| 75 |
-
const outputDiv = document.getElementById("output");
|
| 76 |
-
|
| 77 |
-
socket.on("output", function (data) {
|
| 78 |
-
outputDiv.innerHTML += data.data;
|
| 79 |
-
outputDiv.scrollTop = outputDiv.scrollHeight; // Auto-scroll to bottom
|
| 80 |
-
});
|
| 81 |
-
|
| 82 |
function executeCode() {
|
| 83 |
const codeInput = document.getElementById("code-input");
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
codeInput.value = ""; // Clear input field
|
| 86 |
}
|
| 87 |
|
| 88 |
function cleanup() {
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
}
|
| 91 |
|
| 92 |
// Cleanup temporary files when the user leaves the page
|
|
|
|
| 59 |
background: #005bb5;
|
| 60 |
}
|
| 61 |
</style>
|
|
|
|
| 62 |
</head>
|
| 63 |
<body>
|
| 64 |
<div class="terminal">
|
|
|
|
| 70 |
</div>
|
| 71 |
</div>
|
| 72 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
function executeCode() {
|
| 74 |
const codeInput = document.getElementById("code-input");
|
| 75 |
+
const outputDiv = document.getElementById("output");
|
| 76 |
+
|
| 77 |
+
// Show loading indicator
|
| 78 |
+
outputDiv.innerHTML += `\n> ${codeInput.value}<br>Running...`;
|
| 79 |
+
|
| 80 |
+
fetch("/execute", {
|
| 81 |
+
method: "POST",
|
| 82 |
+
headers: { "Content-Type": "application/json" },
|
| 83 |
+
body: JSON.stringify({ code: codeInput.value }),
|
| 84 |
+
})
|
| 85 |
+
.then(response => {
|
| 86 |
+
const reader = response.body.getReader();
|
| 87 |
+
const decoder = new TextDecoder();
|
| 88 |
+
let content = "";
|
| 89 |
+
|
| 90 |
+
function readStream() {
|
| 91 |
+
reader.read().then(({ done, value }) => {
|
| 92 |
+
if (done) return;
|
| 93 |
+
content += decoder.decode(value);
|
| 94 |
+
outputDiv.innerHTML += content;
|
| 95 |
+
outputDiv.scrollTop = outputDiv.scrollHeight;
|
| 96 |
+
readStream();
|
| 97 |
+
});
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
readStream();
|
| 101 |
+
})
|
| 102 |
+
.catch(error => {
|
| 103 |
+
outputDiv.innerHTML += `<br>Error: ${error}`;
|
| 104 |
+
outputDiv.scrollTop = outputDiv.scrollHeight;
|
| 105 |
+
});
|
| 106 |
codeInput.value = ""; // Clear input field
|
| 107 |
}
|
| 108 |
|
| 109 |
function cleanup() {
|
| 110 |
+
fetch("/cleanup", { method: "POST" })
|
| 111 |
+
.then(response => response.json())
|
| 112 |
+
.then(data => {
|
| 113 |
+
const outputDiv = document.getElementById("output");
|
| 114 |
+
outputDiv.innerHTML += `\n${data.result}`;
|
| 115 |
+
outputDiv.scrollTop = outputDiv.scrollHeight; // Auto-scroll to bottom
|
| 116 |
+
});
|
| 117 |
}
|
| 118 |
|
| 119 |
// Cleanup temporary files when the user leaves the page
|