Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions pt/web/firebird/src/js/components/DownloadPanel/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
let errorCount = 0;
let downloadError = $state(false);
let downloadErrorMessage = $state('');
let progressError;
let closeDownloadModal = false;

const _mtm = (window._mtm = window._mtm || []);

Expand Down Expand Up @@ -101,9 +103,10 @@
console.log('-- download.callback cancel download');
clearInterval(trackerInterval);
trackerInterval = null;
modal.hide();
if (closeDownloadModal) modal.hide();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only want to hide the modal if the user clicks the Cancel button. I needed a way to send the cancel callback without closing the modal, so this I added a conditional for that here.

document.getElementById('submit-download').focus();
}
closeDownloadModal = false;
}

function checkStatusInterval() {
Expand All @@ -120,12 +123,21 @@
if (status.done) {
clearInterval(trackerInterval);
trackerInterval = null;
}
}
})
.catch((error) => {
console.error('Progress check error:', error);
console.error('Error with imgsrv', error);
numAttempts += 1;
errorCount++;

if (progressError) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there's an error with /imgsrv/download-status update the UI and clear the trackerInterval.

clearInterval(trackerInterval);
trackerInterval = null;
downloadInProgress = false;
downloadError = true;
downloadErrorMessage = `Please try again. If downloads continue to fail, contact <a href="mailto:support@hathitrust.org">support@hathitrust.org</a>.`;
HT.live.announce(`${downloadErrorMessage.replace(/<\/?[^>]+(>|$)/g, "")}${' '.repeat(errorCount)}`);
}

// Stop polling after too many failures
if (numAttempts > 3) {
Expand All @@ -135,20 +147,25 @@
downloadError = true;
downloadErrorMessage = `Please try again. If downloads continue to fail, contact <a href="mailto:support@hathitrust.org">support@hathitrust.org</a>.`;
HT.live.announce(`${downloadErrorMessage.replace(/<\/?[^>]+(>|$)/g, "")}${' '.repeat(errorCount)}`);
status.error = true;
_mtm.push({'event': 'pt-large-download-error', 'downloadUrl': `${progressUrl.toString()}`});
_mtm.push({'event': 'pt-download-error','errorType': 'imgsrv unreachable', 'downloadUrl': `${progressUrl.toString()}`});
}
});
}

function updateProgress(data) {
progressError = false;
let percent;
let current = data.status;
if (current == 'EOT' || current == 'DONE') {
if (current == 'EOT' || (current == 'DONE' && data.current_page == -1)) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scenario 1: The real DONE status is always accompanied by a current_page of -1, so I added that to the "ready for download" conditional.

status.done = true;
percent = 100;
downloadInProgress = false;
HT.live.announce(`All done! Your ${formatTitle[format]} is ready for download.`);
} else if (current == 'DONE' && !data.current_page) {
Copy link
Copy Markdown
Member Author

@carylwyatt carylwyatt Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scenario 2: The response that comes back from imgsrv with the "No Download Found" message doesn't include a current_page, so I added that to an additional conditional. Under these conditions, there will be an error message in the modal and a matomo error event logged.

console.log('weird progress bug, set downloads to false, throw error')
progressError = true;
_mtm.push({'event': 'pt-download-error', 'errorType': 'imgsrv: no download found', 'downloadUrl': `${progressUrl.toString()}`});
throw new Error(`imgsrv: "No download found"`);
} else {
status.done = false;
current = data.current_page;
Expand All @@ -160,8 +177,12 @@
} else {
numAttempts += 1;
}
if (numAttempts > 100) {
status.error = true;
if (numAttempts > 5) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scenario 3: Changed this from 100 to 5 attempts and replaced the bogus status.error to use the new progressError conditional in the try/catch block.

console.log('cancelling from updateProgress');
progressError = true;
cancelDownload(false);
_mtm.push({'event': 'pt-download-error', 'errorType': 'too many attempts to download same page', 'downloadUrl': `${progressUrl.toString()}`});
throw new Error(`Too many attempts at the same page.`);
}

status.percent = percent;
Expand All @@ -179,12 +200,16 @@
// but we are not exiting!!
}

function cancelDownload() {
function cancelDownload(closeThisModal) {
if (!downloadInProgress) {
console.log('-- download.cancelDownload EXITING');
return;
}

if (closeThisModal) {
closeDownloadModal = true;
}

cancellingDownload = true;

let cancelUrl = new URL(`${location.protocol}//${HT.service_domain}/${action}`);
Expand Down Expand Up @@ -284,7 +309,7 @@
errorMessage = 'Please try again. If downloads continue to fail, contact <a href="mailto:support@hathitrust.org">support@hathitrust.org</a>.';
HT.live.announce(errorMessage.replace(/<\/?[^>]+(>|$)/g, ""));
downloadInProgress = false;
_mtm.push({'event': 'pt-large-download-error', 'downloadUrl': `${requestUrl.toString()}`});
_mtm.push({'event': 'pt-download-error', 'errorType': 'callback script error', 'downloadUrl': `${requestUrl.toString()}`});
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the original matomo custom event error handling to be more specific to the situation it's logging.

};
}

Expand Down
Loading