|
|
@ -24,10 +24,13 @@
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
// ************************************************************************/
|
|
|
|
// ************************************************************************/
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Nancy;
|
|
|
|
using Nancy.Responses.Negotiation;
|
|
|
|
using Nancy.Responses.Negotiation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using PlexRequests.Api.Interfaces;
|
|
|
|
using PlexRequests.Core;
|
|
|
|
using PlexRequests.Core;
|
|
|
|
using PlexRequests.Core.SettingModels;
|
|
|
|
using PlexRequests.Core.SettingModels;
|
|
|
|
|
|
|
|
|
|
|
@ -35,19 +38,47 @@ namespace PlexRequests.UI.Modules
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class LandingPageModule : BaseModule
|
|
|
|
public class LandingPageModule : BaseModule
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public LandingPageModule(ISettingsService<PlexRequestSettings> settingsService, ISettingsService<LandingPageSettings> landing) : base("landing", settingsService)
|
|
|
|
public LandingPageModule(ISettingsService<PlexRequestSettings> settingsService, ISettingsService<LandingPageSettings> landing,
|
|
|
|
|
|
|
|
ISettingsService<PlexSettings> ps, IPlexApi pApi, ISettingsService<AuthenticationSettings> auth) : base("landing", settingsService)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LandingSettings = landing;
|
|
|
|
LandingSettings = landing;
|
|
|
|
|
|
|
|
PlexSettings = ps;
|
|
|
|
|
|
|
|
PlexApi = pApi;
|
|
|
|
|
|
|
|
AuthSettings = auth;
|
|
|
|
|
|
|
|
|
|
|
|
Get["/", true] = async (x, ct) => await Index();
|
|
|
|
Get["/", true] = async (x, ct) => await Index();
|
|
|
|
|
|
|
|
Get["/status", true] = async (x, ct) => await CheckStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ISettingsService<LandingPageSettings> LandingSettings { get; }
|
|
|
|
private ISettingsService<LandingPageSettings> LandingSettings { get; }
|
|
|
|
|
|
|
|
private ISettingsService<PlexSettings> PlexSettings { get; }
|
|
|
|
|
|
|
|
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
|
|
|
|
|
|
|
|
private IPlexApi PlexApi { get; }
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<Negotiator> Index()
|
|
|
|
private async Task<Negotiator> Index()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var model = await LandingSettings.GetSettingsAsync();
|
|
|
|
var model = await LandingSettings.GetSettingsAsync();
|
|
|
|
return View["Index", model];
|
|
|
|
return View["Index", model];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<Response> CheckStatus()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var auth = await AuthSettings.GetSettingsAsync();
|
|
|
|
|
|
|
|
var plexSettings = await PlexSettings.GetSettingsAsync();
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(auth.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Response.AsJson(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var status = PlexApi.GetStatus(auth.PlexAuthToken, plexSettings.FullUri);
|
|
|
|
|
|
|
|
return Response.AsJson(status != null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Response.AsJson(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|