refactor: a running download is worded the same on the admin Overview as on the wanted list, from one liveDownloadLine (M505 #5641)
release / govulncheck (push) Successful in 17s
release / web (push) Successful in 1m29s
release / go (push) Successful in 1m37s
release / integration (push) Successful in 5m8s
release / android (push) Successful in 5m21s
release / Build signed APK (releases and dev) (push) Successful in 5m35s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
release / govulncheck (push) Successful in 17s
release / web (push) Successful in 1m29s
release / go (push) Successful in 1m37s
release / integration (push) Successful in 5m8s
release / android (push) Successful in 5m21s
release / Build signed APK (releases and dev) (push) Successful in 5m35s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { liveDownloadLine } from './downloadState.js';
|
||||
|
||||
describe('liveDownloadLine', () => {
|
||||
const g = (import_state: Parameters<typeof liveDownloadLine>[0]['import_state'], import_reason = '') => ({
|
||||
import_state,
|
||||
progress: 0.428,
|
||||
import_reason
|
||||
});
|
||||
|
||||
test('says each state of a running download', () => {
|
||||
expect(liveDownloadLine(g('downloading'))).toBe('Downloading 42%');
|
||||
expect(liveDownloadLine(g('importing'))).toBe('Downloaded; checking it is the album and filing it');
|
||||
expect(liveDownloadLine(g('waiting'))).toBe('Downloaded; waiting to be imported');
|
||||
expect(liveDownloadLine(g('waiting', 'the library is busy'))).toBe('Downloaded; the library is busy');
|
||||
expect(liveDownloadLine(g('review', '9 files against 12 tracks'))).toBe('Needs you: 9 files against 12 tracks');
|
||||
expect(liveDownloadLine(g('failed', 'disk full'))).toBe('Import failed: disk full');
|
||||
});
|
||||
|
||||
test('has nothing to say before the client reports', () => {
|
||||
expect(liveDownloadLine(g(''))).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { ImportState } from '#lib/api/types.js';
|
||||
|
||||
// A running download's state in a line: how far it has got, or what its
|
||||
// import is doing or waiting on. The wanted list and the admin Overview say
|
||||
// it the same way (M505). Null before the download client has reported on it.
|
||||
export function liveDownloadLine(g: { import_state: ImportState; progress: number; import_reason: string }): string | null {
|
||||
switch (g.import_state) {
|
||||
case 'downloading':
|
||||
return `Downloading ${Math.floor(g.progress * 100)}%`;
|
||||
case 'importing':
|
||||
return 'Downloaded; checking it is the album and filing it';
|
||||
case 'waiting':
|
||||
return `Downloaded; ${g.import_reason || 'waiting to be imported'}`;
|
||||
case 'review':
|
||||
return `Needs you: ${g.import_reason}`;
|
||||
case 'failed':
|
||||
return `Import failed: ${g.import_reason}`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { relativeTime } from '#lib/utils/relativeTime.js';
|
||||
import type { SearchResult, Want } from '#lib/api/types.js';
|
||||
import { liveDownloadLine } from './downloadState.js';
|
||||
|
||||
// How a want reads in a line, wherever it is shown: the Collection's lists
|
||||
// and the Missing page's folders (M504).
|
||||
@@ -29,18 +30,9 @@ export function searched(w: Want, r: SearchResult): string {
|
||||
export function downloading(w: Want): string | null {
|
||||
const g = w.grab;
|
||||
if (!g?.live) return null;
|
||||
switch (g.import_state) {
|
||||
case 'downloading':
|
||||
return `Downloading ${Math.floor(g.progress * 100)}% · ${g.name}`;
|
||||
case 'importing':
|
||||
return `Downloaded; checking it is the album and filing it · ${g.name}`;
|
||||
case 'waiting':
|
||||
return `Downloaded; ${g.import_reason || 'waiting to be imported'}`;
|
||||
case 'review':
|
||||
return `Needs you: ${g.import_reason}`;
|
||||
case 'failed':
|
||||
return `Import failed: ${g.import_reason}`;
|
||||
}
|
||||
const line = liveDownloadLine(g);
|
||||
// While it downloads or files, the line names the release it took.
|
||||
if (line) return g.import_state === 'downloading' || g.import_state === 'importing' ? `${line} · ${g.name}` : line;
|
||||
const who = g.origin === 'operator' ? 'taken by you' : 'taken by the schedule';
|
||||
return `Downloading ${g.name}, ${who} ${relativeTime(g.grabbed_at)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user