Azeez98 commited on
Commit
86136f0
·
verified ·
1 Parent(s): 44fc8ec

Update static/js/index.js

Browse files
Files changed (1) hide show
  1. static/js/index.js +270 -234
static/js/index.js CHANGED
@@ -1,235 +1,271 @@
1
-
2
- async function handleDockerFormSubmit(event) {
3
- event.preventDefault(); // Prevent the form from submitting the traditional way
4
- const submitButton = document.getElementById('docker-submit-button');
5
- const messageDiv = document.getElementById('docker-message');
6
- const progressBar = document.getElementById('progress-bar');
7
- submitButton.disabled = true; // Disable the submit button
8
- messageDiv.textContent = "Downloading Docker image..."; // Show downloading message
9
- messageDiv.style.display = 'block';
10
-
11
- const form = event.target;
12
- const imageName = form.image_name.value;
13
- const tag = form.tag.value;
14
-
15
- try {
16
- const response = await fetch(`/download-docker-image?image_name=${imageName}&tag=${tag}`);
17
- if (response.ok) {
18
- const reader = response.body.getReader();
19
- const contentLength = response.headers.get('content-length');
20
- const total = parseInt(contentLength, 10);
21
- let loaded = 0;
22
-
23
- const stream = new ReadableStream({
24
- start(controller) {
25
- function push() {
26
- reader.read().then(({ done, value }) => {
27
- if (done) {
28
- controller.close();
29
- updateProgress(progressBar, messageDiv, total, total);
30
- return;
31
- }
32
- loaded += value.length;
33
- updateProgress(progressBar, messageDiv, loaded, total);
34
- controller.enqueue(value);
35
- push();
36
- }).catch(error => {
37
- console.error('Error:', error);
38
- messageDiv.textContent = "Error downloading image.";
39
- });
40
- }
41
- push();
42
- }
43
- });
44
-
45
- const blob = await new Response(stream).blob();
46
- const url = window.URL.createObjectURL(blob);
47
- const a = document.createElement('a');
48
- a.style.display = 'none';
49
- a.href = url;
50
- a.download = `${imageName.replace("/", "_")}.tar`;
51
- document.body.appendChild(a);
52
- a.click();
53
- window.URL.revokeObjectURL(url);
54
- } else if (response.status === 404) {
55
- throw new Error('Image not found');
56
- } else {
57
- throw new Error('Download failed');
58
- }
59
- } catch (error) {
60
- console.error('Error:', error);
61
- if (error.message === 'Image not found') {
62
- messageDiv.textContent = "Error: Docker image not found."; // Show not found message
63
- } else {
64
- messageDiv.innerHTML = "Error downloading image.<br>Check the image name and tag."; // Show error message in two lines
65
- }
66
- } finally {
67
- submitButton.disabled = false; // Re-enable the submit button after download
68
- }
69
- }
70
-
71
- async function handlePipFormSubmit(event) {
72
- event.preventDefault(); // Prevent the form from submitting the traditional way
73
- const submitButton = document.getElementById('pip-submit-button');
74
- const messageDiv = document.getElementById('pip-message');
75
- submitButton.disabled = true; // Disable the submit button
76
- messageDiv.textContent = "Downloading dependencies..."; // Show downloading message
77
- messageDiv.style.display = 'block';
78
-
79
- const formData = new FormData(event.target);
80
- try {
81
- const response = await fetch('/download-dependencies', {
82
- method: 'POST',
83
- body: formData
84
- });
85
- if (response.ok) {
86
- const blob = await response.blob();
87
- const url = window.URL.createObjectURL(blob);
88
- const a = document.createElement('a');
89
- a.style.display = 'none';
90
- a.href = url;
91
- a.download = 'dependencies.tar.gz';
92
- document.body.appendChild(a);
93
- a.click();
94
- window.URL.revokeObjectURL(url);
95
- messageDiv.textContent = "Download complete!"; // Show download complete message
96
- } else {
97
- throw new Error('Download failed');
98
- }
99
- } catch (error) {
100
- console.error('Error:', error);
101
- messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again."; // Show error message in two lines
102
- } finally {
103
- submitButton.disabled = false; // Re-enable the submit button after download
104
- }
105
- }
106
-
107
- async function handleDebFormSubmit(event) {
108
- event.preventDefault(); // Prevent the form from submitting the traditional way
109
- const submitButton = document.getElementById('deb-submit-button');
110
- const messageDiv = document.getElementById('deb-message');
111
- submitButton.disabled = true; // Disable the submit button
112
- messageDiv.textContent = "Downloading Debian packages..."; // Show downloading message
113
- messageDiv.style.display = 'block';
114
-
115
- const formData = new FormData(event.target);
116
- try {
117
- const response = await fetch('/download-deb-packages', {
118
- method: 'POST',
119
- body: formData
120
- });
121
- if (response.ok) {
122
- const blob = await response.blob();
123
- const url = window.URL.createObjectURL(blob);
124
- const a = document.createElement('a');
125
- a.style.display = 'none';
126
- a.href = url;
127
- a.download = 'deb-packages.tar.gz';
128
- document.body.appendChild(a);
129
- a.click();
130
- window.URL.revokeObjectURL(url);
131
- messageDiv.textContent = "Download complete!"; // Show download complete message
132
- } else {
133
- throw new Error('Download failed');
134
- }
135
- } catch (error) {
136
- console.error('Error:', error);
137
- messageDiv.innerHTML = "Error downloading Debian packages.<br>Please try again."; // Show error message in two lines
138
- } finally {
139
- submitButton.disabled = false; // Re-enable the submit button after download
140
- }
141
- }
142
-
143
- function updateProgress(progressBar, messageDiv, loaded, total) {
144
- const percent = Math.round((loaded / total) * 100);
145
- progressBar.style.width = `${percent}%`;
146
- progressBar.textContent = `${percent}%`;
147
- if (percent >= 100) {
148
- messageDiv.textContent = "Download complete!";
149
- messageDiv.style.display = 'block';
150
- }
151
- }
152
-
153
- async function handlePipFormSubmit(event) {
154
- event.preventDefault();
155
- const submitButton = document.getElementById('pip-submit-button');
156
- const messageDiv = document.getElementById('pip-message');
157
- const progressBar = document.getElementById('progress-bar');
158
- const progressContainer = document.getElementById('progress-container');
159
- submitButton.disabled = true;
160
- messageDiv.textContent = "Downloading dependencies...";
161
- messageDiv.style.display = 'block';
162
- progressContainer.style.display = 'block';
163
- progressBar.style.width = '0%'; // Reset progress bar
164
-
165
- const formData = new FormData(event.target);
166
-
167
- try {
168
- const response = await fetch('/download-dependencies', {
169
- method: 'POST',
170
- body: formData
171
- });
172
- if (response.ok) {
173
- const reader = response.body.getReader();
174
- const contentLength = response.headers.get('content-length');
175
- const total = parseInt(contentLength, 10);
176
- let loaded = 0;
177
-
178
- const stream = new ReadableStream({
179
- start(controller) {
180
- function push() {
181
- reader.read().then(({ done, value }) => {
182
- if (done) {
183
- controller.close();
184
- updateProgress(progressBar, messageDiv, total, total);
185
- return;
186
- }
187
- loaded += value.length;
188
- updateProgress(progressBar, messageDiv, loaded, total);
189
- controller.enqueue(value);
190
- push();
191
- }).catch(error => {
192
- console.error('Error:', error);
193
- messageDiv.textContent = "Error downloading dependencies.";
194
- });
195
- }
196
- push();
197
- }
198
- });
199
-
200
- const blob = await new Response(stream).blob();
201
- const url = window.URL.createObjectURL(blob);
202
- const a = document.createElement('a');
203
- a.style.display = 'none';
204
- a.href = url;
205
- a.download = 'dependencies.tar.gz';
206
- document.body.appendChild(a);
207
- a.click();
208
- window.URL.revokeObjectURL(url);
209
- } else {
210
- throw new Error('Download failed');
211
- }
212
- } catch (error) {
213
- console.error('Error:', error);
214
- messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again.";
215
- } finally {
216
- submitButton.disabled = false;
217
- }
218
- }
219
-
220
- function openTab(event, tabName) {
221
- const tabContents = document.getElementsByClassName("tabcontent");
222
- for (let i = 0; i < tabContents.length; i++) {
223
- tabContents[i].style.display = "none";
224
- }
225
- const tabLinks = document.getElementsByClassName("tablink");
226
- for (let i = 0; i < tabLinks.length; i++) {
227
- tabLinks[i].className = tabLinks[i].className.replace(" active", "");
228
- }
229
- document.getElementById(tabName).style.display = "block";
230
- event.currentTarget.className += " active";
231
- }
232
-
233
- window.onload = () => {
234
- document.getElementById("defaultOpen").click(); // Open the default tab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  };
 
1
+
2
+ async function handleDockerFormSubmit(event) {
3
+ event.preventDefault(); // Prevent the form from submitting the traditional way
4
+ const submitButton = document.getElementById('docker-submit-button');
5
+ const messageDiv = document.getElementById('docker-message');
6
+ const progressBar = document.getElementById('progress-bar');
7
+ submitButton.disabled = true; // Disable the submit button
8
+ messageDiv.textContent = "Downloading Docker image..."; // Show downloading message
9
+ messageDiv.style.display = 'block';
10
+
11
+ const form = event.target;
12
+ const imageName = form.image_name.value;
13
+ const tag = form.tag.value;
14
+
15
+ try {
16
+ const response = await fetch(`/download-docker-image?image_name=${imageName}&tag=${tag}`);
17
+ if (response.ok) {
18
+ const reader = response.body.getReader();
19
+ const contentLength = response.headers.get('content-length');
20
+ const total = parseInt(contentLength, 10);
21
+ let loaded = 0;
22
+
23
+ const stream = new ReadableStream({
24
+ start(controller) {
25
+ function push() {
26
+ reader.read().then(({ done, value }) => {
27
+ if (done) {
28
+ controller.close();
29
+ updateProgress(progressBar, messageDiv, total, total);
30
+ return;
31
+ }
32
+ loaded += value.length;
33
+ updateProgress(progressBar, messageDiv, loaded, total);
34
+ controller.enqueue(value);
35
+ push();
36
+ }).catch(error => {
37
+ console.error('Error:', error);
38
+ messageDiv.textContent = "Error downloading image.";
39
+ });
40
+ }
41
+ push();
42
+ }
43
+ });
44
+
45
+ const blob = await new Response(stream).blob();
46
+ const url = window.URL.createObjectURL(blob);
47
+ const a = document.createElement('a');
48
+ a.style.display = 'none';
49
+ a.href = url;
50
+ a.download = `${imageName.replace("/", "_")}.tar`;
51
+ document.body.appendChild(a);
52
+ a.click();
53
+ window.URL.revokeObjectURL(url);
54
+ } else if (response.status === 404) {
55
+ throw new Error('Image not found');
56
+ } else {
57
+ throw new Error('Download failed');
58
+ }
59
+ } catch (error) {
60
+ console.error('Error:', error);
61
+ if (error.message === 'Image not found') {
62
+ messageDiv.textContent = "Error: Docker image not found."; // Show not found message
63
+ } else {
64
+ messageDiv.innerHTML = "Error downloading image.<br>Check the image name and tag."; // Show error message in two lines
65
+ }
66
+ } finally {
67
+ submitButton.disabled = false; // Re-enable the submit button after download
68
+ }
69
+ }
70
+
71
+ async function handlePipFormSubmit(event) {
72
+ event.preventDefault(); // Prevent the form from submitting the traditional way
73
+ const submitButton = document.getElementById('pip-submit-button');
74
+ const messageDiv = document.getElementById('pip-message');
75
+ submitButton.disabled = true; // Disable the submit button
76
+ messageDiv.textContent = "Downloading dependencies..."; // Show downloading message
77
+ messageDiv.style.display = 'block';
78
+
79
+ const formData = new FormData(event.target);
80
+ try {
81
+ const response = await fetch('/download-dependencies', {
82
+ method: 'POST',
83
+ body: formData
84
+ });
85
+ if (response.ok) {
86
+ const blob = await response.blob();
87
+ const url = window.URL.createObjectURL(blob);
88
+ const a = document.createElement('a');
89
+ a.style.display = 'none';
90
+ a.href = url;
91
+ a.download = 'dependencies.tar.gz';
92
+ document.body.appendChild(a);
93
+ a.click();
94
+ window.URL.revokeObjectURL(url);
95
+ messageDiv.textContent = "Download complete!"; // Show download complete message
96
+ } else {
97
+ throw new Error('Download failed');
98
+ }
99
+ } catch (error) {
100
+ console.error('Error:', error);
101
+ messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again."; // Show error message in two lines
102
+ } finally {
103
+ submitButton.disabled = false; // Re-enable the submit button after download
104
+ }
105
+ }
106
+
107
+ // async function handlePipFormSubmit(event) {
108
+ // event.preventDefault(); // Prevent the form from submitting the traditional way
109
+ // const submitButton = document.getElementById('pip-submit-button');
110
+ // const messageDiv = document.getElementById('pip-message');
111
+ // submitButton.disabled = true; // Disable the submit button
112
+ // messageDiv.textContent = "Downloading dependencies..."; // Show downloading message
113
+ // messageDiv.style.display = 'block';
114
+
115
+ // const formData = new FormData(event.target);
116
+ // try {
117
+ // const response = await fetch('/download-dependencies', {
118
+ // method: 'POST',
119
+ // body: formData
120
+ // });
121
+ // if (response.ok) {
122
+ // const blob = await response.blob();
123
+ // const url = window.URL.createObjectURL(blob);
124
+ // const a = document.createElement('a');
125
+ // a.style.display = 'none';
126
+ // a.href = url;
127
+ // a.download = 'dependencies.tar.gz';
128
+ // document.body.appendChild(a);
129
+ // a.click();
130
+ // window.URL.revokeObjectURL(url);
131
+ // messageDiv.textContent = "Download complete!"; // Show download complete message
132
+ // } else {
133
+ // throw new Error('Download failed');
134
+ // }
135
+ // } catch (error) {
136
+ // console.error('Error:', error);
137
+ // messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again."; // Show error message in two lines
138
+ // } finally {
139
+ // submitButton.disabled = false; // Re-enable the submit button after download
140
+ // }
141
+ // }
142
+
143
+ async function handleDebFormSubmit(event) {
144
+ event.preventDefault(); // Prevent the form from submitting the traditional way
145
+ const submitButton = document.getElementById('deb-submit-button');
146
+ const messageDiv = document.getElementById('deb-message');
147
+ submitButton.disabled = true; // Disable the submit button
148
+ messageDiv.textContent = "Downloading Debian packages..."; // Show downloading message
149
+ messageDiv.style.display = 'block';
150
+
151
+ const formData = new FormData(event.target);
152
+ try {
153
+ const response = await fetch('/download-deb-packages', {
154
+ method: 'POST',
155
+ body: formData
156
+ });
157
+ if (response.ok) {
158
+ const blob = await response.blob();
159
+ const url = window.URL.createObjectURL(blob);
160
+ const a = document.createElement('a');
161
+ a.style.display = 'none';
162
+ a.href = url;
163
+ a.download = 'deb-packages.tar.gz';
164
+ document.body.appendChild(a);
165
+ a.click();
166
+ window.URL.revokeObjectURL(url);
167
+ messageDiv.textContent = "Download complete!"; // Show download complete message
168
+ } else {
169
+ throw new Error('Download failed');
170
+ }
171
+ } catch (error) {
172
+ console.error('Error:', error);
173
+ messageDiv.innerHTML = "Error downloading Debian packages.<br>Please try again."; // Show error message in two lines
174
+ } finally {
175
+ submitButton.disabled = false; // Re-enable the submit button after download
176
+ }
177
+ }
178
+
179
+ function updateProgress(progressBar, messageDiv, loaded, total) {
180
+ const percent = Math.round((loaded / total) * 100);
181
+ progressBar.style.width = `${percent}%`;
182
+ progressBar.textContent = `${percent}%`;
183
+ if (percent >= 100) {
184
+ messageDiv.textContent = "Download complete!";
185
+ messageDiv.style.display = 'block';
186
+ }
187
+ }
188
+
189
+ async function handlePipFormSubmit(event) {
190
+ event.preventDefault();
191
+ const submitButton = document.getElementById('pip-submit-button');
192
+ const messageDiv = document.getElementById('pip-message');
193
+ const progressBar = document.getElementById('progress-bar');
194
+ const progressContainer = document.getElementById('progress-container');
195
+ submitButton.disabled = true;
196
+ messageDiv.textContent = "Downloading dependencies...";
197
+ messageDiv.style.display = 'block';
198
+ progressContainer.style.display = 'block';
199
+ progressBar.style.width = '0%'; // Reset progress bar
200
+
201
+ const formData = new FormData(event.target);
202
+
203
+ try {
204
+ const response = await fetch('/download-dependencies', {
205
+ method: 'POST',
206
+ body: formData
207
+ });
208
+ if (response.ok) {
209
+ const reader = response.body.getReader();
210
+ const contentLength = response.headers.get('content-length');
211
+ const total = parseInt(contentLength, 10);
212
+ let loaded = 0;
213
+
214
+ const stream = new ReadableStream({
215
+ start(controller) {
216
+ function push() {
217
+ reader.read().then(({ done, value }) => {
218
+ if (done) {
219
+ controller.close();
220
+ updateProgress(progressBar, messageDiv, total, total);
221
+ return;
222
+ }
223
+ loaded += value.length;
224
+ updateProgress(progressBar, messageDiv, loaded, total);
225
+ controller.enqueue(value);
226
+ push();
227
+ }).catch(error => {
228
+ console.error('Error:', error);
229
+ messageDiv.textContent = "Error downloading dependencies.";
230
+ });
231
+ }
232
+ push();
233
+ }
234
+ });
235
+
236
+ const blob = await new Response(stream).blob();
237
+ const url = window.URL.createObjectURL(blob);
238
+ const a = document.createElement('a');
239
+ a.style.display = 'none';
240
+ a.href = url;
241
+ a.download = 'dependencies.tar.gz';
242
+ document.body.appendChild(a);
243
+ a.click();
244
+ window.URL.revokeObjectURL(url);
245
+ } else {
246
+ throw new Error('Download failed');
247
+ }
248
+ } catch (error) {
249
+ console.error('Error:', error);
250
+ messageDiv.innerHTML = "Error downloading dependencies.<br>Please try again.";
251
+ } finally {
252
+ submitButton.disabled = false;
253
+ }
254
+ }
255
+
256
+ function openTab(event, tabName) {
257
+ const tabContents = document.getElementsByClassName("tabcontent");
258
+ for (let i = 0; i < tabContents.length; i++) {
259
+ tabContents[i].style.display = "none";
260
+ }
261
+ const tabLinks = document.getElementsByClassName("tablink");
262
+ for (let i = 0; i < tabLinks.length; i++) {
263
+ tabLinks[i].className = tabLinks[i].className.replace(" active", "");
264
+ }
265
+ document.getElementById(tabName).style.display = "block";
266
+ event.currentTarget.className += " active";
267
+ }
268
+
269
+ window.onload = () => {
270
+ document.getElementById("defaultOpen").click(); // Open the default tab
271
  };