diff --git a/client/src/app/add-new-torrent/add-new-torrent.component.ts b/client/src/app/add-new-torrent/add-new-torrent.component.ts index fb71bc2..f83dc25 100644 --- a/client/src/app/add-new-torrent/add-new-torrent.component.ts +++ b/client/src/app/add-new-torrent/add-new-torrent.component.ts @@ -59,25 +59,24 @@ export class AddNewTorrentComponent implements OnInit { } }); this.settingsService.get().subscribe((settings) => { - const providerSetting = settings.first((m) => m.key === 'Provider:Provider'); + const providerSetting = settings.find((m) => m.key === 'Provider:Provider'); this.provider = providerSetting.enumValues[providerSetting.value as number]; - this.downloadClient = settings.first((m) => m.key === 'DownloadClient:Client')?.value as number; + this.downloadClient = settings.find((m) => m.key === 'DownloadClient:Client')?.value as number; - this.category = settings.first((m) => m.key === 'Gui:Default:Category')?.value as string; - this.hostDownloadAction = this.downloadAction = settings.first((m) => m.key === 'Gui:Default:HostDownloadAction') + this.category = settings.find((m) => m.key === 'Gui:Default:Category')?.value as string; + this.hostDownloadAction = this.downloadAction = settings.find((m) => m.key === 'Gui:Default:HostDownloadAction') ?.value as number; this.downloadAction = - settings.first((m) => m.key === 'Gui:Default:OnlyDownloadAvailableFiles')?.value === true ? 1 : 0; - this.finishedAction = settings.first((m) => m.key === 'Gui:Default:FinishedAction')?.value as number; - this.downloadMinSize = settings.first((m) => m.key === 'Gui:Default:MinFileSize')?.value as number; - this.includeRegex = settings.first((m) => m.key === 'Gui:Default:IncludeRegex')?.value as string; - this.excludeRegex = settings.first((m) => m.key === 'Gui:Default:ExcludeRegex')?.value as string; - this.torrentRetryAttempts = settings.first((m) => m.key === 'Gui:Default:TorrentRetryAttempts')?.value as number; - this.downloadRetryAttempts = settings.first((m) => m.key === 'Gui:Default:DownloadRetryAttempts') - ?.value as number; - this.torrentDeleteOnError = settings.first((m) => m.key === 'Gui:Default:DeleteOnError')?.value as number; - this.torrentLifetime = settings.first((m) => m.key === 'Gui:Default:TorrentLifetime')?.value as number; - this.priority = settings.first((m) => m.key === 'Gui:Default:Priority')?.value as number; + settings.find((m) => m.key === 'Gui:Default:OnlyDownloadAvailableFiles')?.value === true ? 1 : 0; + this.finishedAction = settings.find((m) => m.key === 'Gui:Default:FinishedAction')?.value as number; + this.downloadMinSize = settings.find((m) => m.key === 'Gui:Default:MinFileSize')?.value as number; + this.includeRegex = settings.find((m) => m.key === 'Gui:Default:IncludeRegex')?.value as string; + this.excludeRegex = settings.find((m) => m.key === 'Gui:Default:ExcludeRegex')?.value as string; + this.torrentRetryAttempts = settings.find((m) => m.key === 'Gui:Default:TorrentRetryAttempts')?.value as number; + this.downloadRetryAttempts = settings.find((m) => m.key === 'Gui:Default:DownloadRetryAttempts')?.value as number; + this.torrentDeleteOnError = settings.find((m) => m.key === 'Gui:Default:DeleteOnError')?.value as number; + this.torrentLifetime = settings.find((m) => m.key === 'Gui:Default:TorrentLifetime')?.value as number; + this.priority = settings.find((m) => m.key === 'Gui:Default:Priority')?.value as number; this.setFinishAction(); }); diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index fb07c04..b39801f 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts @@ -1,4 +1,3 @@ -import 'curray'; import { ClipboardModule } from '@angular/cdk/clipboard'; import { APP_BASE_HREF } from '@angular/common'; import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; diff --git a/client/src/app/settings/settings.component.ts b/client/src/app/settings/settings.component.ts index 0ef3186..17ec763 100644 --- a/client/src/app/settings/settings.component.ts +++ b/client/src/app/settings/settings.component.ts @@ -39,10 +39,10 @@ export class SettingsComponent implements OnInit { public reset(): void { this.settingsService.get().subscribe((settings) => { - this.tabs = settings.where((m) => m.key.indexOf(':') === -1); + this.tabs = settings.filter((m) => m.key.indexOf(':') === -1); for (let tab of this.tabs) { - tab.settings = settings.where((m) => m.key.indexOf(`${tab.key}:`) > -1); + tab.settings = settings.filter((m) => m.key.indexOf(`${tab.key}:`) > -1); } }); } @@ -50,7 +50,7 @@ export class SettingsComponent implements OnInit { public ok(): void { this.saving = true; - const settingsToSave = this.tabs.selectMany((m) => m.settings).where((m) => m.type !== 'Object'); + const settingsToSave = this.tabs.flatMap((m) => m.settings).filter((m) => m.type !== 'Object'); this.settingsService.update(settingsToSave).subscribe( () => { @@ -67,8 +67,8 @@ export class SettingsComponent implements OnInit { public testDownloadPath(): void { const settingDownloadPath = this.tabs - .first((m) => m.key === 'DownloadClient') - .settings.first((m) => m.key === 'DownloadClient:DownloadPath').value as string; + .find((m) => m.key === 'DownloadClient') + .settings.find((m) => m.key === 'DownloadClient:DownloadPath').value as string; this.saving = true; this.testPathError = null; @@ -121,11 +121,11 @@ export class SettingsComponent implements OnInit { public testAria2cConnection(): void { const settingAria2cUrl = this.tabs - .first((m) => m.key === 'DownloadClient') - .settings.first((m) => m.key === 'DownloadClient:Aria2cUrl').value as string; + .find((m) => m.key === 'DownloadClient') + .settings.find((m) => m.key === 'DownloadClient:Aria2cUrl').value as string; const settingAria2cSecret = this.tabs - .first((m) => m.key === 'DownloadClient') - .settings.first((m) => m.key === 'DownloadClient:Aria2cSecret').value as string; + .find((m) => m.key === 'DownloadClient') + .settings.find((m) => m.key === 'DownloadClient:Aria2cSecret').value as string; this.saving = true; this.testAria2cConnectionError = null; diff --git a/client/src/app/torrent-status.pipe.ts b/client/src/app/torrent-status.pipe.ts index 9d827e8..bb4aff6 100644 --- a/client/src/app/torrent-status.pipe.ts +++ b/client/src/app/torrent-status.pipe.ts @@ -15,25 +15,25 @@ export class TorrentStatusPipe implements PipeTransform { } if (torrent.downloads.length > 0) { - const allFinished = torrent.downloads.all((m) => m.completed != null); + const allFinished = torrent.downloads.every((m) => m.completed != null); if (allFinished) { return 'Finished'; } - const downloading = torrent.downloads.where((m) => m.downloadStarted && !m.downloadFinished && m.bytesDone > 0); - const downloaded = torrent.downloads.where((m) => m.downloadFinished != null); + const downloading = torrent.downloads.filter((m) => m.downloadStarted && !m.downloadFinished && m.bytesDone > 0); + const downloaded = torrent.downloads.filter((m) => m.downloadFinished != null); if (downloading.length > 0) { - const bytesDone = downloading.sum((m) => m.bytesDone); - const bytesTotal = downloading.sum((m) => m.bytesTotal); + const bytesDone = downloading.reduce((sum, m) => sum + m.bytesDone, 0); + const bytesTotal = downloading.reduce((sum, m) => sum + m.bytesTotal, 0); let progress = (bytesDone / bytesTotal) * 100; if (isNaN(progress)) { progress = 0; } - let allSpeeds = downloading.sum((m) => m.speed); + let allSpeeds = downloading.reduce((sum, m) => sum + m.speed, 0); let speed: string | string[] = '0'; @@ -44,12 +44,12 @@ export class TorrentStatusPipe implements PipeTransform { } (${progress.toFixed(2)}% - ${speed}/s)`; } - const unpacking = torrent.downloads.where((m) => m.unpackingStarted && !m.unpackingFinished && m.bytesDone > 0); - const unpacked = torrent.downloads.where((m) => m.unpackingFinished != null); + const unpacking = torrent.downloads.filter((m) => m.unpackingStarted && !m.unpackingFinished && m.bytesDone > 0); + const unpacked = torrent.downloads.filter((m) => m.unpackingFinished != null); if (unpacking.length > 0) { - const bytesDone = unpacking.sum((m) => m.bytesDone); - const bytesTotal = unpacking.sum((m) => m.bytesTotal); + const bytesDone = unpacking.reduce((sum, m) => sum + m.bytesDone, 0); + const bytesTotal = unpacking.reduce((sum, m) => sum + m.bytesTotal, 0); let progress = (bytesDone / bytesTotal) * 100; if (isNaN(progress)) { @@ -61,13 +61,13 @@ export class TorrentStatusPipe implements PipeTransform { )}%)`; } - const queuedForUnpacking = torrent.downloads.where((m) => m.unpackingQueued && !m.unpackingStarted); + const queuedForUnpacking = torrent.downloads.filter((m) => m.unpackingQueued && !m.unpackingStarted); if (queuedForUnpacking.length > 0) { return `Queued for unpacking`; } - const queuedForDownload = torrent.downloads.where((m) => !m.downloadStarted && !m.downloadFinished); + const queuedForDownload = torrent.downloads.filter((m) => !m.downloadStarted && !m.downloadFinished); if (queuedForDownload.length > 0) { return `Queued for downloading`; diff --git a/client/src/app/torrent-table/torrent-table.component.html b/client/src/app/torrent-table/torrent-table.component.html index db890fd..f5b27c6 100644 --- a/client/src/app/torrent-table/torrent-table.component.html +++ b/client/src/app/torrent-table/torrent-table.component.html @@ -33,7 +33,7 @@