From 5c691dc98437a4cd24560ff625414fe05dd22f89 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 14 Jan 2022 10:21:54 +0000 Subject: [PATCH 1/3] fix(sonarr): :bug: Fixed an issue where we could attempt to add a series to sonarr before sonarr has got all the metadata #4459 --- src/Ombi.Core/Senders/TvSender.cs | 32 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Ombi.Core/Senders/TvSender.cs b/src/Ombi.Core/Senders/TvSender.cs index 2f42a12c0..bb2a5d628 100644 --- a/src/Ombi.Core/Senders/TvSender.cs +++ b/src/Ombi.Core/Senders/TvSender.cs @@ -309,6 +309,20 @@ namespace Ombi.Core.Senders private async Task SendToSonarr(ChildRequests model, SonarrSeries result, SonarrSettings s) { + // Check to ensure we have the all the seasons, ensure the Sonarr metadata has grabbed all the data + foreach (var season in model.SeasonRequests) + { + var attempt = 0; + var existingSeason = result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber); + while (existingSeason == null && attempt < 5) + { + attempt++; + Logger.LogInformation("There was no season numer {0} in Sonarr for title {1}. Will try again as the metadata did not get created", season.SeasonNumber, model.ParentRequest.Title); + result = await SonarrApi.GetSeriesById(result.id, s.ApiKey, s.FullUri); + await Task.Delay(500); + } + } + var episodesToUpdate = new List(); // Ok, now let's sort out the episodes. @@ -327,10 +341,11 @@ namespace Ombi.Core.Senders await Task.Delay(500); } + var seriesChanges = false; - foreach (var req in model.SeasonRequests) + foreach (var season in model.SeasonRequests) { - foreach (var ep in req.Episodes) + foreach (var ep in season.Episodes) { var sonarrEp = sonarrEpList.FirstOrDefault(x => x.episodeNumber == ep.EpisodeNumber && x.seasonNumber == req.SeasonNumber); @@ -340,11 +355,6 @@ namespace Ombi.Core.Senders episodesToUpdate.Add(sonarrEp); } } - } - var seriesChanges = false; - - foreach (var season in model.SeasonRequests) - { var sonarrEpisodeList = sonarrEpList.Where(x => x.seasonNumber == season.SeasonNumber).ToList(); var sonarrEpCount = sonarrEpisodeList.Count; var ourRequestCount = season.Episodes.Count; @@ -358,13 +368,7 @@ namespace Ombi.Core.Senders //var distinctEpisodes = ourEpisodes.Distinct().ToList(); //var missingEpisodes = Enumerable.Range(distinctEpisodes.Min(), distinctEpisodes.Count).Except(distinctEpisodes); - var existingSeason = - result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber); - if (existingSeason == null) - { - Logger.LogError("There was no season numer {0} in Sonarr for title {1}", season.SeasonNumber, model.ParentRequest.Title); - continue; - } + if (sonarrEpCount == ourRequestCount /*|| !missingEpisodes.Any()*/) From 33b8d1111a1c6663d8c0bbd912be4660da7d013f Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 14 Jan 2022 10:49:52 +0000 Subject: [PATCH 2/3] fix(wizard): :bug: Fixed the issue where the Application Url wasn't validated in the wizard #4417 --- src/Ombi.Core/Senders/TvSender.cs | 10 ++-- .../app/wizard/welcome/welcome.component.ts | 54 +++++++++++++------ src/Ombi/Controllers/V1/SettingsController.cs | 1 + 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/Ombi.Core/Senders/TvSender.cs b/src/Ombi.Core/Senders/TvSender.cs index bb2a5d628..9f60d2ba0 100644 --- a/src/Ombi.Core/Senders/TvSender.cs +++ b/src/Ombi.Core/Senders/TvSender.cs @@ -310,15 +310,17 @@ namespace Ombi.Core.Senders private async Task SendToSonarr(ChildRequests model, SonarrSeries result, SonarrSettings s) { // Check to ensure we have the all the seasons, ensure the Sonarr metadata has grabbed all the data + Season existingSeason = null; foreach (var season in model.SeasonRequests) { var attempt = 0; - var existingSeason = result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber); + existingSeason = result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber); while (existingSeason == null && attempt < 5) { attempt++; Logger.LogInformation("There was no season numer {0} in Sonarr for title {1}. Will try again as the metadata did not get created", season.SeasonNumber, model.ParentRequest.Title); result = await SonarrApi.GetSeriesById(result.id, s.ApiKey, s.FullUri); + existingSeason = result.seasons.FirstOrDefault(x => x.seasonNumber == season.SeasonNumber); await Task.Delay(500); } } @@ -348,7 +350,7 @@ namespace Ombi.Core.Senders foreach (var ep in season.Episodes) { var sonarrEp = sonarrEpList.FirstOrDefault(x => - x.episodeNumber == ep.EpisodeNumber && x.seasonNumber == req.SeasonNumber); + x.episodeNumber == ep.EpisodeNumber && x.seasonNumber == season.SeasonNumber); if (sonarrEp != null && !sonarrEp.monitored) { sonarrEp.monitored = true; @@ -366,9 +368,7 @@ namespace Ombi.Core.Senders //// NOTE, not sure if needed since ombi ui displays future episodes anyway... //ourEpisodes.AddRange(unairedEpisodes); //var distinctEpisodes = ourEpisodes.Distinct().ToList(); - //var missingEpisodes = Enumerable.Range(distinctEpisodes.Min(), distinctEpisodes.Count).Except(distinctEpisodes); - - + //var missingEpisodes = Enumerable.Range(distinctEpisodes.Min(), distinctEpisodes.Count).Except(distinctEpisodes); if (sonarrEpCount == ourRequestCount /*|| !missingEpisodes.Any()*/) diff --git a/src/Ombi/ClientApp/src/app/wizard/welcome/welcome.component.ts b/src/Ombi/ClientApp/src/app/wizard/welcome/welcome.component.ts index 849977b55..ef29266d1 100644 --- a/src/Ombi/ClientApp/src/app/wizard/welcome/welcome.component.ts +++ b/src/Ombi/ClientApp/src/app/wizard/welcome/welcome.component.ts @@ -1,11 +1,11 @@ import { AfterViewInit, Component, OnInit, ViewChild } from "@angular/core"; -import { Router } from "@angular/router"; +import { IdentityService, NotificationService, SettingsService } from "../../services"; + import { ICreateWizardUser } from "../../interfaces"; -import { IdentityService, NotificationService } from "../../services"; import { IOmbiConfigModel } from "../models/OmbiConfigModel"; -import { WizardService } from "../services/wizard.service"; import { MatHorizontalStepper } from'@angular/material/stepper'; -import { StepperSelectionEvent } from "@angular/cdk/stepper"; +import { Router } from "@angular/router"; +import { WizardService } from "../services/wizard.service"; @Component({ templateUrl: "./welcome.component.html", @@ -18,7 +18,8 @@ export class WelcomeComponent implements OnInit { public config: IOmbiConfigModel; constructor(private router: Router, private identityService: IdentityService, - private notificationService: NotificationService, private WizardService: WizardService) { } + private notificationService: NotificationService, private WizardService: WizardService, + private settingsService: SettingsService) { } public ngOnInit(): void { this.localUser = { @@ -34,20 +35,39 @@ export class WelcomeComponent implements OnInit { } public createUser() { - this.WizardService.addOmbiConfig(this.config).subscribe(config => { - if(config != null) { - this.identityService.createWizardUser(this.localUser).subscribe(x => { - if (x.result) { - // save the config - this.router.navigate(["login"]); + if (this.config.applicationUrl) { + this.settingsService.verifyUrl(this.config.applicationUrl).subscribe(x => { + if (!x) { + this.notificationService.error(`The URL "${this.config.applicationUrl}" is not valid. Please format it correctly e.g. http://www.google.com/`); + this.stepper.selectedIndex = 3; + return; + } + this.saveConfig(); + }); } else { - if (x.errors.length > 0) { - this.notificationService.error(x.errors[0]); - this.stepper.previous(); - } + this.saveConfig(); } - }); } - }, configErr => this.notificationService.error(configErr)); + + private saveConfig() { + this.WizardService.addOmbiConfig(this.config).subscribe({ + next: (config) => { + if(config != null) { + this.identityService.createWizardUser(this.localUser).subscribe(x => { + if (x.result) { + // save the config + this.router.navigate(["login"]); + } else { + if (x.errors.length > 0) { + this.notificationService.error(x.errors[0]); + this.stepper.previous(); + } + } + }); + } + }, + error: (configErr) => this.notificationService.error(configErr) + }); } + } diff --git a/src/Ombi/Controllers/V1/SettingsController.cs b/src/Ombi/Controllers/V1/SettingsController.cs index abf1e86b7..fcd4bb1a4 100644 --- a/src/Ombi/Controllers/V1/SettingsController.cs +++ b/src/Ombi/Controllers/V1/SettingsController.cs @@ -334,6 +334,7 @@ namespace Ombi.Controllers.V1 [ApiExplorerSettings(IgnoreApi = true)] [HttpPost("customization/urlverify")] + [AllowAnonymous] public bool VerifyUrl([FromBody]UrlVerifyModel url) { return Uri.TryCreate(url.Url, UriKind.Absolute, out var __); From 033fa52fac13f14200f73c5368c30f1556512b8f Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 14 Jan 2022 10:52:02 +0000 Subject: [PATCH 3/3] chore(wizard): :recycle: Set the state when saving the wizard --- .../ClientApp/src/app/wizard/welcome/welcome.component.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Ombi/ClientApp/src/app/wizard/welcome/welcome.component.ts b/src/Ombi/ClientApp/src/app/wizard/welcome/welcome.component.ts index ef29266d1..d1a9c59eb 100644 --- a/src/Ombi/ClientApp/src/app/wizard/welcome/welcome.component.ts +++ b/src/Ombi/ClientApp/src/app/wizard/welcome/welcome.component.ts @@ -1,6 +1,7 @@ import { AfterViewInit, Component, OnInit, ViewChild } from "@angular/core"; import { IdentityService, NotificationService, SettingsService } from "../../services"; +import { CustomizationFacade } from "../../state/customization/customization.facade"; import { ICreateWizardUser } from "../../interfaces"; import { IOmbiConfigModel } from "../models/OmbiConfigModel"; import { MatHorizontalStepper } from'@angular/material/stepper'; @@ -19,7 +20,7 @@ export class WelcomeComponent implements OnInit { constructor(private router: Router, private identityService: IdentityService, private notificationService: NotificationService, private WizardService: WizardService, - private settingsService: SettingsService) { } + private settingsService: SettingsService, private customizationFacade: CustomizationFacade) { } public ngOnInit(): void { this.localUser = { @@ -55,6 +56,7 @@ export class WelcomeComponent implements OnInit { if(config != null) { this.identityService.createWizardUser(this.localUser).subscribe(x => { if (x.result) { + this.customizationFacade.loadCustomziationSettings().subscribe(); // save the config this.router.navigate(["login"]); } else {