mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-09 10:49:29 +00:00
fix(downloads): harden queue reordering and summary stats
This commit is contained in:
@@ -37,6 +37,27 @@ describe('download summaries', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('treats completed downloads as having no remaining bytes despite stale progress', () => {
|
||||
expect(summarizeDownloads([
|
||||
item('done', {
|
||||
status: 'completed',
|
||||
totalBytes: 40 * 1024 ** 2,
|
||||
downloadedBytes: 40 * 1024 ** 2,
|
||||
}),
|
||||
], {
|
||||
done: progress('done', {
|
||||
downloaded_bytes: 40 * 1024 ** 2 - 555 * 1024,
|
||||
total_bytes: 555 * 1024,
|
||||
}),
|
||||
})).toEqual({
|
||||
itemCount: 1,
|
||||
activeCount: 0,
|
||||
downloadedBytes: 40 * 1024 ** 2,
|
||||
remainingBytes: 0,
|
||||
remainingIsEstimated: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('does not present partial byte totals as complete aggregates', () => {
|
||||
expect(summarizeDownloads([
|
||||
item('known', { totalBytes: 100, downloadedBytes: 20 }),
|
||||
|
||||
@@ -42,11 +42,13 @@ const effectiveByteState = (
|
||||
const totalBytes = usesStoredMediaTotal
|
||||
? usableBytes(download.totalBytes)
|
||||
: usableBytes(progress?.total_bytes) ?? usableBytes(download.totalBytes);
|
||||
const downloadedBytes =
|
||||
usableBytes(progress?.downloaded_bytes) ??
|
||||
usableBytes(download.downloadedBytes) ??
|
||||
(download.status === 'completed' ? totalBytes : undefined) ??
|
||||
(canInferNoDownloadedBytes(download) ? 0 : undefined);
|
||||
const downloadedBytes = download.status === 'completed'
|
||||
? usableBytes(download.downloadedBytes) ??
|
||||
usableBytes(progress?.downloaded_bytes) ??
|
||||
totalBytes
|
||||
: usableBytes(progress?.downloaded_bytes) ??
|
||||
usableBytes(download.downloadedBytes) ??
|
||||
(canInferNoDownloadedBytes(download) ? 0 : undefined);
|
||||
const totalIsEstimate = usesStoredMediaTotal
|
||||
? storedTotalIsEstimate
|
||||
: (progress?.total_is_estimate ?? storedTotalIsEstimate) === true;
|
||||
@@ -89,6 +91,13 @@ export const summarizeDownloads = (
|
||||
}
|
||||
}
|
||||
|
||||
if (download.status === 'completed') {
|
||||
// A completed row is terminal even when a delayed progress event still
|
||||
// carries an old partial denominator. Never expose that stale value as
|
||||
// remaining work in the aggregate status bar.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
state.totalBytes === undefined ||
|
||||
state.downloadedBytes === undefined ||
|
||||
|
||||
@@ -15,7 +15,7 @@ export const DEFAULT_COLUMN_ORDER = [
|
||||
export const DEFAULT_COLUMN_WIDTHS = [340, 100, 220, 100, 80, 170] as const;
|
||||
export const COLUMN_MINIMUMS = [160, 58, 92, 58, 48, 144] as const;
|
||||
// Width of the fixed action rail shown while hovering a row.
|
||||
export const DOWNLOAD_ACTIONS_COLUMN_WIDTH = 120;
|
||||
export const DOWNLOAD_ACTIONS_COLUMN_WIDTH = 84;
|
||||
// Keep the fixed rail clear of the viewport edge and horizontal scrollbar.
|
||||
export const DOWNLOAD_ACTIONS_VIEWPORT_INSET = 8;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user