UNPKG

ipull

Version:

The only file downloader you'll ever need. For node.js and the browser, CLI and library for fast and reliable file downloads.

35 lines 2.04 kB
import { BaseMultiProgressBar } from "./BaseMultiProgressBar.js"; import { DownloadFlags, DownloadStatus } from "../../../download-engine/download-file/progress-status-file.js"; export class SummaryMultiProgressBar extends BaseMultiProgressBar { printType = "update"; updateIntervalMs = 0; _parallelDownloads = 0; _lastStatuses = []; createMultiProgressBar(statuses, oneStatus, loadingDownloads = 0) { oneStatus = structuredClone(oneStatus); oneStatus.downloadFlags.push(DownloadFlags.DownloadSequence); const linesToPrint = []; for (const status of statuses) { const lastStatus = this._lastStatuses.find(x => x.downloadId === status.downloadId); const isStatusChanged = lastStatus?.downloadStatus !== status.downloadStatus; const copyStatus = structuredClone(status); if (isStatusChanged) { linesToPrint.push(copyStatus); } } if (this.printType === "log") { this._lastStatuses = structuredClone(statuses); } const { allStatusesSorted } = this.recorderStatusByImportance(linesToPrint); const filterStatusesSliced = allStatusesSorted.slice(0, this.options.maxViewDownloads); if (statuses.length > 1 || oneStatus.downloadStatus === DownloadStatus.Active) { filterStatusesSliced.push(oneStatus); } const activeDownloads = statuses.filter((status) => status.downloadStatus === DownloadStatus.Active).length; this._parallelDownloads ||= activeDownloads; const finishedDownloads = statuses.filter((status) => status.downloadStatus === DownloadStatus.Finished).length; oneStatus.comment = `${finishedDownloads.toLocaleString()}/${(statuses.length + loadingDownloads).toLocaleString()} files done${this._parallelDownloads > 1 ? ` (${activeDownloads.toLocaleString()} active)` : ""}`; return this.createProgresses(filterStatusesSliced); } } //# sourceMappingURL=SummaryMultiProgressBar.js.map