Update static/js/index.js
Browse files- static/js/index.js +80 -6
static/js/index.js
CHANGED
@@ -136,6 +136,85 @@ async function handleDockerFormSubmit(event) {
|
|
136 |
// }
|
137 |
// }
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
async function handlePipFormSubmit(event) {
|
140 |
event.preventDefault(); // Prevent the form from submitting the traditional way
|
141 |
const submitButton = document.getElementById('pip-submit-button');
|
@@ -155,18 +234,13 @@ async function handlePipFormSubmit(event) {
|
|
155 |
method: 'POST',
|
156 |
body: formData
|
157 |
});
|
158 |
-
|
159 |
if (response.ok) {
|
160 |
const reader = response.body.getReader();
|
161 |
const contentLength = response.headers.get('content-length');
|
162 |
const total = contentLength ? parseInt(contentLength, 10) : null;
|
163 |
let loaded = 0;
|
164 |
|
165 |
-
if (!total) {
|
166 |
-
// Handle case where content-length is not provided
|
167 |
-
messageDiv.textContent = "Warning: Content length is not provided.";
|
168 |
-
}
|
169 |
-
|
170 |
const stream = new ReadableStream({
|
171 |
start(controller) {
|
172 |
function push() {
|
|
|
136 |
// }
|
137 |
// }
|
138 |
|
139 |
+
// async function handlePipFormSubmit(event) {
|
140 |
+
// event.preventDefault(); // Prevent the form from submitting the traditional way
|
141 |
+
// const submitButton = document.getElementById('pip-submit-button');
|
142 |
+
// const messageDiv = document.getElementById('pip-message');
|
143 |
+
// const progressBar = document.getElementById('progress-bar');
|
144 |
+
// const progressContainer = document.getElementById('progress-container');
|
145 |
+
// submitButton.disabled = true; // Disable the submit button
|
146 |
+
// messageDiv.textContent = "Downloading dependencies..."; // Show downloading message
|
147 |
+
// messageDiv.style.display = 'block';
|
148 |
+
// progressContainer.style.display = 'block';
|
149 |
+
// progressBar.style.width = '0%'; // Reset progress bar
|
150 |
+
|
151 |
+
// const formData = new FormData(event.target);
|
152 |
+
|
153 |
+
// try {
|
154 |
+
// const response = await fetch('/download-dependencies', {
|
155 |
+
// method: 'POST',
|
156 |
+
// body: formData
|
157 |
+
// });
|
158 |
+
|
159 |
+
// if (response.ok) {
|
160 |
+
// const reader = response.body.getReader();
|
161 |
+
// const contentLength = response.headers.get('content-length');
|
162 |
+
// const total = contentLength ? parseInt(contentLength, 10) : null;
|
163 |
+
// let loaded = 0;
|
164 |
+
|
165 |
+
// if (!total) {
|
166 |
+
// // Handle case where content-length is not provided
|
167 |
+
// messageDiv.textContent = "Warning: Content length is not provided.";
|
168 |
+
// }
|
169 |
+
|
170 |
+
// const stream = new ReadableStream({
|
171 |
+
// start(controller) {
|
172 |
+
// function push() {
|
173 |
+
// reader.read().then(({ done, value }) => {
|
174 |
+
// if (done) {
|
175 |
+
// controller.close();
|
176 |
+
// if (total) {
|
177 |
+
// updateProgress(progressBar, messageDiv, total, total);
|
178 |
+
// } else {
|
179 |
+
// messageDiv.textContent = "Download complete!";
|
180 |
+
// }
|
181 |
+
// return;
|
182 |
+
// }
|
183 |
+
// loaded += value.length;
|
184 |
+
// if (total) {
|
185 |
+
// updateProgress(progressBar, messageDiv, loaded, total);
|
186 |
+
// }
|
187 |
+
// controller.enqueue(value);
|
188 |
+
// push();
|
189 |
+
// }).catch(error => {
|
190 |
+
// console.error('Error:', error);
|
191 |
+
// messageDiv.textContent = "Error downloading dependencies.";
|
192 |
+
// });
|
193 |
+
// }
|
194 |
+
// push();
|
195 |
+
// }
|
196 |
+
// });
|
197 |
+
|
198 |
+
// const blob = await new Response(stream).blob();
|
199 |
+
// const url = window.URL.createObjectURL(blob);
|
200 |
+
// const a = document.createElement('a');
|
201 |
+
// a.style.display = 'none';
|
202 |
+
// a.href = url;
|
203 |
+
// a.download = 'dependencies.tar.gz';
|
204 |
+
// document.body.appendChild(a);
|
205 |
+
// a.click();
|
206 |
+
// window.URL.revokeObjectURL(url);
|
207 |
+
// } else {
|
208 |
+
// throw new Error('Download failed');
|
209 |
+
// }
|
210 |
+
// } catch (error) {
|
211 |
+
// console.error('Error:', error);
|
212 |
+
// messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again.";
|
213 |
+
// } finally {
|
214 |
+
// submitButton.disabled = false; // Re-enable the submit button after download
|
215 |
+
// }
|
216 |
+
// }
|
217 |
+
|
218 |
async function handlePipFormSubmit(event) {
|
219 |
event.preventDefault(); // Prevent the form from submitting the traditional way
|
220 |
const submitButton = document.getElementById('pip-submit-button');
|
|
|
234 |
method: 'POST',
|
235 |
body: formData
|
236 |
});
|
237 |
+
|
238 |
if (response.ok) {
|
239 |
const reader = response.body.getReader();
|
240 |
const contentLength = response.headers.get('content-length');
|
241 |
const total = contentLength ? parseInt(contentLength, 10) : null;
|
242 |
let loaded = 0;
|
243 |
|
|
|
|
|
|
|
|
|
|
|
244 |
const stream = new ReadableStream({
|
245 |
start(controller) {
|
246 |
function push() {
|