| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- const startButton = document.getElementById('startButton');
- const statusDiv = document.getElementById('zipstatus');
- let pollingInterval = null;
- startButton.addEventListener('click', startZipCreation);
- function startZipCreation() {
- console.log(startButton.getAttribute('data-dir2zip'));
- const sourcePath = startButton.getAttribute('data-dir2zip');
- if (!sourcePath) {
- alert('Please enter the source path');
- return;
- }
-
- fetch('/start_zip', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ source_path: sourcePath })
- })
- .then(response => response.json())
- .then(data => {
- console.log(data);
- startPolling();
- })
- .catch(error => console.error('Error starting zip creation:', error));
- }
- function startPolling() {
- statusDiv.innerText = 'Zip creation in progress...';
- pollingInterval = setInterval(pollStatus, 1000);
- }
- function pollStatus() {
- fetch('/status')
- .then(response => response.json())
- .then(data => {
- if (data.status === 'completed') {
- clearInterval(pollingInterval);
- statusDiv.innerText = 'Zip creation completed. Downloading...';
- window.location.href = '/download';
- } else if (data.status === 'failed') {
- clearInterval(pollingInterval);
- statusDiv.innerText = `Error: ${data.error}`;
- } else {
- statusDiv.innerText = 'Zip creation in progress...';
- }
- })
- .catch(error => console.error('Error polling status:', error));
- }
|