Drewster727 9 years ago
commit 20a18c516b

@ -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);
}
}
} }
} }

@ -66,10 +66,15 @@ namespace PlexRequests.UI.Modules
public async Task<Negotiator> Index() public async Task<Negotiator> Index()
{ {
var landingSettings = await LandingPageSettings.GetSettingsAsync(); var query = Request.Query["landing"];
if (landingSettings.Enabled) var landingCheck = (bool?)query ?? true;
if (landingCheck)
{ {
return View["Landing/Index",landingSettings]; var landingSettings = await LandingPageSettings.GetSettingsAsync();
if (landingSettings.Enabled)
{
return View["Landing/Index", landingSettings];
}
} }
var settings = await AuthService.GetSettingsAsync(); var settings = await AuthService.GetSettingsAsync();
return View["Index", settings]; return View["Index", settings];

Loading…
Cancel
Save