Finished #923 !!!

This commit is contained in:
tidusjar 2017-01-18 21:05:08 +00:00
commit 4926255094
18 changed files with 283 additions and 22 deletions

View file

@ -75,6 +75,7 @@ namespace Ombi.UI.Jobs
JobBuilder.Create<UserRequestLimitResetter>().WithIdentity("UserRequestLimiter", "Request").Build(),
JobBuilder.Create<RecentlyAdded>().WithIdentity("RecentlyAddedModel", "Email").Build(),
JobBuilder.Create<FaultQueueHandler>().WithIdentity("FaultQueueHandler", "Fault").Build(),
JobBuilder.Create<RadarrCacher>().WithIdentity("RadarrCacher", "Cache").Build(),
};
jobs.AddRange(jobList);
@ -170,6 +171,10 @@ namespace Ombi.UI.Jobs
{
s.PlexUserChecker = 24;
}
if (s.RadarrCacher == 0)
{
s.RadarrCacher = 60;
}
var triggers = new List<ITrigger>();
@ -222,6 +227,14 @@ namespace Ombi.UI.Jobs
.WithSimpleSchedule(x => x.WithIntervalInMinutes(s.WatcherCacher).RepeatForever())
.Build();
var radarrCacher =
TriggerBuilder.Create()
.WithIdentity("RadarrCacher", "Cache")
.StartNow()
//.StartAt(DateBuilder.FutureDate(2, IntervalUnit.Minute))
.WithSimpleSchedule(x => x.WithIntervalInMinutes(s.RadarrCacher).RepeatForever())
.Build();
var storeBackup =
TriggerBuilder.Create()
.WithIdentity("StoreBackup", "Database")
@ -280,6 +293,7 @@ namespace Ombi.UI.Jobs
triggers.Add(fault);
triggers.Add(plexCacher);
triggers.Add(plexUserChecker);
triggers.Add(radarrCacher);
return triggers;
}

View file

@ -175,7 +175,7 @@ namespace Ombi.UI.Modules.Admin
Get["/getusers"] = _ => GetUsers();
Get["/couchpotato"] = _ => CouchPotato();
Post["/couchpotato"] = _ => SaveCouchPotato();
Post["/couchpotato", true] = async (x, ct) => await SaveCouchPotato();
Get["/plex"] = _ => Plex();
Post["/plex", true] = async (x, ct) => await SavePlex();
@ -185,7 +185,7 @@ namespace Ombi.UI.Modules.Admin
Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
Get["/radarr", true] = async (x, ct) => await Radarr();
Post["/radarr"] = _ => SaveRadarr();
Post["/radarr", true] = async (x, ct) => await SaveRadarr();
Post["/radarrprofiles"] = _ => GetRadarrQualityProfiles();
Get["/sickrage"] = _ => Sickrage();
@ -385,7 +385,7 @@ namespace Ombi.UI.Modules.Admin
return View["CouchPotato", settings];
}
private Response SaveCouchPotato()
private async Task<Response> SaveCouchPotato()
{
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
var valid = this.Validate(couchPotatoSettings);
@ -394,7 +394,7 @@ namespace Ombi.UI.Modules.Admin
return Response.AsJson(valid.SendJsonError());
}
var watcherSettings = WatcherSettings.GetSettings();
var watcherSettings = await WatcherSettings.GetSettingsAsync();
if (watcherSettings.Enabled)
{
@ -406,8 +406,20 @@ namespace Ombi.UI.Modules.Admin
});
}
var radarrSettings = await RadarrSettings.GetSettingsAsync();
if (radarrSettings.Enabled)
{
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Cannot have Radarr and CouchPotato both enabled."
});
}
couchPotatoSettings.ApiKey = couchPotatoSettings.ApiKey.Trim();
var result = CpService.SaveSettings(couchPotatoSettings);
var result = await CpService.SaveSettingsAsync(couchPotatoSettings);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for CouchPotato!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
@ -465,6 +477,7 @@ namespace Ombi.UI.Modules.Admin
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "SickRage is enabled, we cannot enable Sonarr and SickRage" });
}
sonarrSettings.ApiKey = sonarrSettings.ApiKey.Trim();
var result = SonarrService.SaveSettings(sonarrSettings);
@ -480,25 +493,34 @@ namespace Ombi.UI.Modules.Admin
return View["Radarr", settings];
}
private Response SaveRadarr()
private async Task<Response> SaveRadarr()
{
var sonarrSettings = this.Bind<SonarrSettings>();
var radarrSettings = this.Bind<RadarrSettings>();
var valid = this.Validate(sonarrSettings);
//Check Watcher and CP make sure they are not enabled
var watcher = await WatcherSettings.GetSettingsAsync();
if (watcher.Enabled)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Watcher is enabled, we cannot enable Watcher and Radarr" });
}
var cp = await CpService.GetSettingsAsync();
if (cp.Enabled)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "CouchPotato is enabled, we cannot enable Watcher and CouchPotato" });
}
var valid = this.Validate(radarrSettings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
var sickRageEnabled = SickRageService.GetSettings().Enabled;
if (sickRageEnabled)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "SickRage is enabled, we cannot enable Sonarr and SickRage" });
}
sonarrSettings.ApiKey = sonarrSettings.ApiKey.Trim();
var result = SonarrService.SaveSettings(sonarrSettings);
radarrSettings.ApiKey = radarrSettings.ApiKey.Trim();
var result = await RadarrSettings.SaveSettingsAsync(radarrSettings);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Sonarr!" }
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Radarr!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}

View file

@ -97,6 +97,18 @@ namespace Ombi.UI.Modules.Admin
});
}
var watcherSettings = await WatcherSettings.GetSettingsAsync();
if (watcherSettings.Enabled)
{
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Cannot have Watcher and CouchPotato both enabled."
});
}
settings.ApiKey = settings.ApiKey.Trim();
var result = await WatcherSettings.SaveSettingsAsync(settings);
return Response.AsJson(result

View file

@ -76,7 +76,7 @@ namespace Ombi.UI.Modules
ISettingsService<PlexSettings> plexService, ISettingsService<AuthenticationSettings> auth,
IRepository<UsersToNotify> u, ISettingsService<EmailNotificationSettings> email,
IIssueService issue, IAnalytics a, IRepository<RequestLimit> rl, ITransientFaultQueue tfQueue, IRepository<PlexContent> content,
ISecurityExtensions security, IMovieSender movieSender)
ISecurityExtensions security, IMovieSender movieSender, IRadarrCacher radarrCacher)
: base("search", prSettings, security)
{
Auth = auth;
@ -108,6 +108,7 @@ namespace Ombi.UI.Modules
PlexContentRepository = content;
MovieSender = movieSender;
WatcherCacher = watcherCacher;
RadarrCacher = radarrCacher;
Get["SearchIndex", "/", true] = async (x, ct) => await RequestLoad();
@ -157,6 +158,7 @@ namespace Ombi.UI.Modules
private IAnalytics Analytics { get; }
private ITransientFaultQueue FaultQueue { get; }
private IRepository<RequestLimit> RequestLimitRepo { get; }
private IRadarrCacher RadarrCacher { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private async Task<Negotiator> RequestLoad()
@ -236,6 +238,7 @@ namespace Ombi.UI.Modules
var cpCached = CpCacher.QueuedIds();
var watcherCached = WatcherCacher.QueuedIds();
var radarrCached = RadarrCacher.QueuedIds();
var content = PlexContentRepository.GetAll();
var plexMovies = Checker.GetPlexMovies(content);
var viewMovies = new List<SearchMovieViewModel>();
@ -288,13 +291,19 @@ namespace Ombi.UI.Modules
}
else if (cpCached.Contains(movie.Id) && canSee) // compare to the couchpotato db
{
viewMovie.Approved = true;
viewMovie.Requested = true;
}
else if(watcherCached.Contains(imdbId) && canSee) // compare to the watcher db
{
viewMovie.Approved = true;
viewMovie.Requested = true;
}
else if (radarrCached.Contains(movie.Id) && canSee)
{
viewMovie.Approved = true;
viewMovie.Requested = true;
}
viewMovies.Add(viewMovie);
}

View file

@ -48,6 +48,7 @@ namespace Ombi.UI.NinjectModules
Bind<ISonarrCacher>().To<SonarrCacher>();
Bind<ISickRageCacher>().To<SickRageCacher>();
Bind<IRecentlyAdded>().To<RecentlyAdded>();
Bind<IRadarrCacher>().To<RadarrCacher>();
Bind<IPlexContentCacher>().To<PlexContentCacher>();
Bind<IJobFactory>().To<CustomJobFactory>();
Bind<IMovieSender>().To<MovieSender>();

View file

@ -288,6 +288,7 @@
</Compile>
<Compile Include="Start\StartupOptions.cs" />
<Compile Include="Start\UpdateValue.cs" />
<Compile Include="Validators\RadarrValidator.cs" />
<Compile Include="Validators\WatcherValidator.cs" />
<Compile Include="Validators\SlackSettingsValidator.cs" />
<Compile Include="Validators\UserViewModelValidator.cs" />

View file

@ -0,0 +1,43 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrValidator.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using FluentValidation;
using Ombi.Core.SettingModels;
namespace Ombi.UI.Validators
{
public class RadarrValidator : AbstractValidator<RadarrSettings>
{
public RadarrValidator()
{
RuleFor(request => request.ApiKey).NotEmpty().WithMessage("You must specify a Api Key.");
RuleFor(request => request.Ip).NotEmpty().WithMessage("You must specify a IP/Host name.");
RuleFor(request => request.Port).NotEmpty().WithMessage("You must specify a Port.");
RuleFor(request => request.QualityProfile).NotEmpty().WithMessage("You must specify a Quality Profile.");
}
}
}

View file

@ -73,7 +73,7 @@
<div class="form-group">
<div>
<button id="testSonarr" type="submit" class="btn btn-primary-outline">Test Connectivity <div id="spinner"/></button>
<button id="testRadarr" type="button" class="btn btn-primary-outline">Test Connectivity <div id="spinner"/></button>
</div>
</div>

View file

@ -45,6 +45,14 @@
<label for="CouchPotatoCacher" class="control-label">Couch Potato Cacher (min)</label>
<input type="text" class="form-control form-control-custom " id="CouchPotatoCacher" name="CouchPotatoCacher" value="@Model.CouchPotatoCacher">
</div>
<div class="form-group">
<label for="WatcherCacher" class="control-label">Wactcher Cacher (min)</label>
<input type="text" class="form-control form-control-custom " id="WatcherCacher" name="WatcherCacher" value="@Model.WatcherCacher">
</div>
<div class="form-group">
<label for="RadarrCacher" class="control-label">Radarr Cacher (min)</label>
<input type="text" class="form-control form-control-custom " id="RadarrCacher" name="RadarrCacher" value="@Model.RadarrCacher">
</div>
<small>Please note, the minimum time for this to run is 11 hours, if set below 11 then we will ignore that value. This is a very resource intensive job, the less we run it the better.</small>
<div class="form-group">