mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 10:36:54 -07:00
More for #923
This commit is contained in:
parent
5e06d9bd26
commit
02a1770b31
7 changed files with 99 additions and 25 deletions
|
@ -95,6 +95,8 @@ namespace Ombi.UI.Modules.Admin
|
|||
private ISettingsService<NotificationSettingsV2> NotifySettings { get; }
|
||||
private ISettingsService<DiscordNotificationSettings> DiscordSettings { get; }
|
||||
private IDiscordApi DiscordApi { get; }
|
||||
private ISettingsService<RadarrSettings> RadarrSettings { get; }
|
||||
private IRadarrApi RadarrApi { get; }
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
public AdminModule(ISettingsService<PlexRequestSettings> prService,
|
||||
|
@ -122,7 +124,7 @@ namespace Ombi.UI.Modules.Admin
|
|||
ISettingsService<NotificationSettingsV2> notifyService, IRecentlyAdded recentlyAdded,
|
||||
ISettingsService<WatcherSettings> watcherSettings ,
|
||||
ISettingsService<DiscordNotificationSettings> discord,
|
||||
IDiscordApi discordapi
|
||||
IDiscordApi discordapi, ISettingsService<RadarrSettings> settings, IRadarrApi radarrApi
|
||||
, ISecurityExtensions security) : base("admin", prService, security)
|
||||
{
|
||||
PrService = prService;
|
||||
|
@ -156,6 +158,8 @@ namespace Ombi.UI.Modules.Admin
|
|||
WatcherSettings = watcherSettings;
|
||||
DiscordSettings = discord;
|
||||
DiscordApi = discordapi;
|
||||
RadarrSettings = settings;
|
||||
RadarrApi = radarrApi;
|
||||
|
||||
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
|
||||
|
||||
|
@ -178,11 +182,15 @@ namespace Ombi.UI.Modules.Admin
|
|||
|
||||
Get["/sonarr"] = _ => Sonarr();
|
||||
Post["/sonarr"] = _ => SaveSonarr();
|
||||
Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
|
||||
|
||||
Get["/radarr", true] = async (x, ct) => await Radarr();
|
||||
Post["/radarr"] = _ => SaveRadarr();
|
||||
Post["/radarrprofiles"] = _ => GetRadarrQualityProfiles();
|
||||
|
||||
Get["/sickrage"] = _ => Sickrage();
|
||||
Post["/sickrage"] = _ => SaveSickrage();
|
||||
|
||||
Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
|
||||
Post["/cpprofiles", true] = async (x, ct) => await GetCpProfiles();
|
||||
Post["/cpapikey"] = x => GetCpApiKey();
|
||||
|
||||
|
@ -465,6 +473,49 @@ namespace Ombi.UI.Modules.Admin
|
|||
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
|
||||
}
|
||||
|
||||
private async Task<Negotiator> Radarr()
|
||||
{
|
||||
var settings = await RadarrSettings.GetSettingsAsync();
|
||||
|
||||
return View["Radarr", settings];
|
||||
}
|
||||
|
||||
private Response SaveRadarr()
|
||||
{
|
||||
var sonarrSettings = this.Bind<SonarrSettings>();
|
||||
|
||||
var valid = this.Validate(sonarrSettings);
|
||||
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);
|
||||
|
||||
return Response.AsJson(result
|
||||
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Sonarr!" }
|
||||
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
|
||||
}
|
||||
|
||||
private Response GetRadarrQualityProfiles()
|
||||
{
|
||||
var settings = this.Bind<RadarrSettings>();
|
||||
var profiles = RadarrApi.GetProfiles(settings.ApiKey, settings.FullUri);
|
||||
|
||||
// set the cache
|
||||
if (profiles != null)
|
||||
{
|
||||
Cache.Set(CacheKeys.RadarrQualityProfiles, profiles);
|
||||
}
|
||||
|
||||
return Response.AsJson(profiles);
|
||||
}
|
||||
|
||||
private Negotiator Sickrage()
|
||||
{
|
||||
var settings = SickRageService.GetSettings();
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Ombi.UI.Modules
|
|||
|
||||
public ApplicationTesterModule(ICouchPotatoApi cpApi, ISonarrApi sonarrApi, IPlexApi plexApi,
|
||||
ISickRageApi srApi, IHeadphonesApi hpApi, ISettingsService<PlexRequestSettings> pr, ISecurityExtensions security,
|
||||
IWatcherApi watcherApi) : base("test", pr, security)
|
||||
IWatcherApi watcherApi, IRadarrApi radarrApi) : base("test", pr, security)
|
||||
{
|
||||
this.RequiresAuthentication();
|
||||
|
||||
|
@ -56,9 +56,11 @@ namespace Ombi.UI.Modules
|
|||
SickRageApi = srApi;
|
||||
HeadphonesApi = hpApi;
|
||||
WatcherApi = watcherApi;
|
||||
RadarrApi = radarrApi;
|
||||
|
||||
Post["/cp"] = _ => CouchPotatoTest();
|
||||
Post["/sonarr"] = _ => SonarrTest();
|
||||
Post["/radarr"] = _ => RadarrTest();
|
||||
Post["/plex"] = _ => PlexTest();
|
||||
Post["/sickrage"] = _ => SickRageTest();
|
||||
Post["/headphones"] = _ => HeadphonesTest();
|
||||
|
@ -73,6 +75,7 @@ namespace Ombi.UI.Modules
|
|||
private ISickRageApi SickRageApi { get; }
|
||||
private IHeadphonesApi HeadphonesApi { get; }
|
||||
private IWatcherApi WatcherApi { get; }
|
||||
private IRadarrApi RadarrApi { get; }
|
||||
|
||||
private Response CouchPotatoTest()
|
||||
{
|
||||
|
@ -148,7 +151,7 @@ namespace Ombi.UI.Modules
|
|||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Sonarr, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
|
||||
catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get Sonarr's status: ");
|
||||
Log.Warn(e);
|
||||
|
@ -161,6 +164,35 @@ namespace Ombi.UI.Modules
|
|||
}
|
||||
}
|
||||
|
||||
private Response RadarrTest()
|
||||
{
|
||||
var radarrSettings = this.Bind<RadarrSettings>();
|
||||
var valid = this.Validate(radarrSettings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = RadarrApi.SystemStatus(radarrSettings.ApiKey, radarrSettings.FullUri);
|
||||
return status?.version != null
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Radarr successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Radarr, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get Radarr's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to Radarr, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to Radarr, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response PlexTest()
|
||||
{
|
||||
var plexSettings = this.Bind<PlexSettings>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue