mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-07 21:51:13 -07:00
Added test button to Plex. That's fixed #9
This commit is contained in:
parent
fd36df091d
commit
d0bfe95402
9 changed files with 185 additions and 6 deletions
|
@ -33,6 +33,7 @@ using Nancy.Security;
|
|||
using NLog;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
|
@ -41,22 +42,27 @@ namespace PlexRequests.UI.Modules
|
|||
public class ApplicationTesterModule : BaseModule
|
||||
{
|
||||
|
||||
public ApplicationTesterModule(ICouchPotatoApi cpApi, ISonarrApi sonarrApi) : base("test")
|
||||
public ApplicationTesterModule(ICouchPotatoApi cpApi, ISonarrApi sonarrApi, IPlexApi plexApi,
|
||||
ISettingsService<AuthenticationSettings> authSettings) : base("test")
|
||||
{
|
||||
this.RequiresAuthentication();
|
||||
|
||||
CpApi = cpApi;
|
||||
SonarrApi = sonarrApi;
|
||||
|
||||
PlexApi = plexApi;
|
||||
AuthSettings = authSettings;
|
||||
|
||||
Post["/cp"] = _ => CouchPotatoTest();
|
||||
Post["/sonarr"] = _ => SonarrTest();
|
||||
Post["/plex"] = _ => PlexTest();
|
||||
|
||||
}
|
||||
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private ISonarrApi SonarrApi { get; set; }
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
|
||||
|
||||
private Response CouchPotatoTest()
|
||||
{
|
||||
|
@ -105,5 +111,34 @@ namespace PlexRequests.UI.Modules
|
|||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response PlexTest()
|
||||
{
|
||||
var plexSettings = this.Bind<PlexSettings>();
|
||||
var settings = AuthSettings.GetSettings();
|
||||
if (settings?.PlexAuthToken == null)
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Plex is not setup yet, we need " });
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = PlexApi.GetStatus(settings.PlexAuthToken, plexSettings.FullUri);
|
||||
return status != null
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Plex successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Plex, please check your settings." });
|
||||
|
||||
}
|
||||
catch (ApplicationException e) // Exceptions are expected if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get Plex's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to Plex, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to Plex, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue