(jobRef, updates = {})
| 872 | } |
| 873 | |
| 874 | export function updateTransferProgress(jobRef, updates = {}) { |
| 875 | const job = resolveJob(jobRef); |
| 876 | if (!job) return; |
| 877 | |
| 878 | let progressed = false; |
| 879 | |
| 880 | if (typeof updates.state === 'string') job.state = updates.state.toLowerCase(); |
| 881 | if (typeof updates.status === 'string') job.state = updates.status.toLowerCase(); |
| 882 | if (typeof updates.error === 'string') job.error = updates.error; |
| 883 | if (typeof updates.current === 'string') { |
| 884 | if (updates.current !== job.current) progressed = true; |
| 885 | job.current = updates.current; |
| 886 | } |
| 887 | if (typeof updates.cancelRequested === 'boolean') { |
| 888 | job.cancelRequested = updates.cancelRequested; |
| 889 | if (updates.cancelRequested && (job.state === 'running' || job.state === 'queued')) { |
| 890 | job.state = 'cancel_requested'; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | if (Number.isFinite(updates.pct)) { |
| 895 | const next = clamp(Number(updates.pct), 0, 100); |
| 896 | if (!Number.isFinite(job.pct) || next !== job.pct) progressed = true; |
| 897 | job.pct = next; |
| 898 | } |
| 899 | if (Number.isFinite(updates.bytesDone)) { |
| 900 | const next = Number(updates.bytesDone); |
| 901 | if (!Number.isFinite(job.bytesDone) || next !== job.bytesDone) progressed = true; |
| 902 | job.bytesDone = next; |
| 903 | } |
| 904 | if (Number.isFinite(updates.bytesTotal)) job.bytesTotal = Number(updates.bytesTotal); |
| 905 | if (Number.isFinite(updates.selectedBytes)) job.bytesTotal = Number(updates.selectedBytes); |
| 906 | if (Number.isFinite(updates.filesDone)) { |
| 907 | const next = Number(updates.filesDone); |
| 908 | if (!Number.isFinite(job.filesDone) || next !== job.filesDone) progressed = true; |
| 909 | job.filesDone = next; |
| 910 | } |
| 911 | if (Number.isFinite(updates.filesTotal)) job.filesTotal = Number(updates.filesTotal); |
| 912 | if (Number.isFinite(updates.selectedFiles)) job.filesTotal = Number(updates.selectedFiles); |
| 913 | |
| 914 | if (progressed) { |
| 915 | job.lastProgressAt = Date.now(); |
| 916 | } |
| 917 | |
| 918 | job.mode = 'actual'; |
| 919 | |
| 920 | const st = String(job.state || '').toLowerCase(); |
| 921 | if (['done', 'error', 'failed', 'cancelled'].includes(st)) { |
| 922 | job.cancelable = false; |
| 923 | job.onCancel = null; |
| 924 | job.cancelInFlight = false; |
| 925 | if (!job.endedAt) { |
| 926 | job.endedAt = Date.now(); |
| 927 | } |
| 928 | if (!job.removeAt) { |
| 929 | job.removeAt = Date.now() + FINAL_VISIBLE_MS; |
| 930 | } |
| 931 | } |
no test coverage detected