mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Just some more async changes
This commit is contained in:
parent
68648dcccf
commit
5bf557658d
9 changed files with 96 additions and 96 deletions
|
@ -51,7 +51,7 @@ namespace PlexRequests.Core
|
|||
return releases.FirstOrDefault();
|
||||
}
|
||||
|
||||
public StatusModel GetStatus()
|
||||
public async Task<StatusModel> GetStatus()
|
||||
{
|
||||
var assemblyVersion = AssemblyHelper.GetProductVersion();
|
||||
var model = new StatusModel
|
||||
|
@ -59,23 +59,23 @@ namespace PlexRequests.Core
|
|||
Version = assemblyVersion,
|
||||
};
|
||||
|
||||
var latestRelease = GetLatestRelease();
|
||||
if (latestRelease.Result == null)
|
||||
var latestRelease = await GetLatestRelease();
|
||||
if (latestRelease == null)
|
||||
{
|
||||
return new StatusModel { Version = "Unknown" };
|
||||
}
|
||||
var latestVersionArray = latestRelease.Result.Name.Split(new[] { 'v' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var latestVersionArray = latestRelease.Name.Split(new[] { 'v' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var latestVersion = latestVersionArray.Length > 1 ? latestVersionArray[1] : string.Empty;
|
||||
|
||||
if (!latestVersion.Equals(assemblyVersion, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
model.UpdateAvailable = true;
|
||||
model.UpdateUri = latestRelease.Result.HtmlUrl;
|
||||
model.UpdateUri = latestRelease.HtmlUrl;
|
||||
}
|
||||
|
||||
model.ReleaseNotes = latestRelease.Result.Body;
|
||||
model.DownloadUri = latestRelease.Result.Assets[0].BrowserDownloadUrl;
|
||||
model.ReleaseTitle = latestRelease.Result.Name;
|
||||
model.ReleaseNotes = latestRelease.Body;
|
||||
model.DownloadUri = latestRelease.Assets[0].BrowserDownloadUrl;
|
||||
model.ReleaseTitle = latestRelease.Name;
|
||||
|
||||
return model;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ using PlexRequests.UI.Modules;
|
|||
namespace PlexRequests.UI.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
//[Ignore("Needs some work")]
|
||||
public class UserLoginModuleTests
|
||||
{
|
||||
private Mock<ISettingsService<AuthenticationSettings>> AuthMock { get; set; }
|
||||
|
|
|
@ -23,42 +23,43 @@
|
|||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
using System.Net;
|
||||
using PlexRequests.Helpers.Exceptions;
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using MarkdownSharp;
|
||||
using System.Net;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.Extensions;
|
||||
using Nancy.ModelBinding;
|
||||
using Nancy.Responses.Negotiation;
|
||||
using Nancy.Validation;
|
||||
|
||||
using Nancy.Json;
|
||||
using Nancy.Security;
|
||||
using NLog;
|
||||
|
||||
using MarkdownSharp;
|
||||
|
||||
using PlexRequests.Api;
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Exceptions;
|
||||
using PlexRequests.Services.Interfaces;
|
||||
using PlexRequests.Services.Notification;
|
||||
using PlexRequests.Store.Models;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Nancy.Json;
|
||||
using Nancy.Security;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
@ -136,8 +137,8 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
Get["/"] = _ => Admin();
|
||||
|
||||
Get["/authentication"] = _ => Authentication();
|
||||
Post["/authentication"] = _ => SaveAuthentication();
|
||||
Get["/authentication", true] = async (x, ct) => await Authentication();
|
||||
Post["/authentication", true] = async (x, ct) => await SaveAuthentication();
|
||||
|
||||
Post["/"] = _ => SaveAdmin();
|
||||
|
||||
|
@ -163,7 +164,7 @@ namespace PlexRequests.UI.Modules
|
|||
Get["/emailnotification"] = _ => EmailNotifications();
|
||||
Post["/emailnotification"] = _ => SaveEmailNotifications();
|
||||
Post["/testemailnotification"] = _ => TestEmailNotifications();
|
||||
Get["/status"] = _ => Status();
|
||||
Get["/status", true] = async (x,ct) => await Status();
|
||||
|
||||
Get["/pushbulletnotification"] = _ => PushbulletNotifications();
|
||||
Post["/pushbulletnotification"] = _ => SavePushbulletNotifications();
|
||||
|
@ -190,22 +191,22 @@ namespace PlexRequests.UI.Modules
|
|||
Get["/slacknotification"] = _ => SlackNotifications();
|
||||
Post["/slacknotification"] = _ => SaveSlackNotifications();
|
||||
|
||||
Get["/landingpage", true] = async (x,ct) => await LandingPage();
|
||||
Get["/landingpage", true] = async (x, ct) => await LandingPage();
|
||||
Post["/landingpage", true] = async (x, ct) => await SaveLandingPage();
|
||||
}
|
||||
|
||||
private Negotiator Authentication()
|
||||
private async Task<Negotiator> Authentication()
|
||||
{
|
||||
var settings = AuthService.GetSettings();
|
||||
var settings = await AuthService.GetSettingsAsync();
|
||||
|
||||
return View["/Authentication", settings];
|
||||
}
|
||||
|
||||
private Response SaveAuthentication()
|
||||
private async Task<Response> SaveAuthentication()
|
||||
{
|
||||
var model = this.Bind<AuthenticationSettings>();
|
||||
|
||||
var result = AuthService.SaveSettings(model);
|
||||
var result = await AuthService.SaveSettingsAsync(model);
|
||||
if (result)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(BaseUrl))
|
||||
|
@ -231,23 +232,23 @@ namespace PlexRequests.UI.Modules
|
|||
private Response SaveAdmin()
|
||||
{
|
||||
var model = this.Bind<PlexRequestSettings>();
|
||||
var valid = this.Validate (model);
|
||||
if (!valid.IsValid) {
|
||||
var valid = this.Validate(model);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace (model.BaseUrl)) {
|
||||
if (model.BaseUrl.StartsWith ("/") || model.BaseUrl.StartsWith ("\\"))
|
||||
if (!string.IsNullOrWhiteSpace(model.BaseUrl))
|
||||
{
|
||||
model.BaseUrl = model.BaseUrl.Remove (0, 1);
|
||||
if (model.BaseUrl.StartsWith("/", StringComparison.CurrentCultureIgnoreCase) || model.BaseUrl.StartsWith("\\", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
model.BaseUrl = model.BaseUrl.Remove(0, 1);
|
||||
}
|
||||
}
|
||||
var result = PrService.SaveSettings(model);
|
||||
if (result) {
|
||||
return Response.AsJson (new JsonResponseModel{ Result = true });
|
||||
}
|
||||
|
||||
return Response.AsJson (new JsonResponseModel{ Result = false, Message = "We could not save to the database, please try again" });
|
||||
return Response.AsJson(result
|
||||
? new JsonResponseModel { Result = true }
|
||||
: new JsonResponseModel { Result = false, Message = "We could not save to the database, please try again" });
|
||||
}
|
||||
|
||||
private Response RequestAuthToken()
|
||||
|
@ -295,7 +296,8 @@ namespace PlexRequests.UI.Modules
|
|||
return Response.AsJson(new { Result = true, Users = string.Empty });
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
var users = PlexApi.GetUsers(token);
|
||||
if (users == null)
|
||||
{
|
||||
|
@ -307,28 +309,27 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
|
||||
var usernames = users.User.Select(x => x.Title);
|
||||
return Response.AsJson(new {Result = true, Users = usernames});
|
||||
} catch (Exception ex) {
|
||||
Log.Error (ex);
|
||||
if (ex is WebException || ex is ApiRequestException) {
|
||||
return Response.AsJson (new { Result = false, Message ="Could not load the user list! We have connectivity problems connecting to Plex, Please ensure we can access Plex.Tv, The error has been logged." });
|
||||
return Response.AsJson(new { Result = true, Users = usernames });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex);
|
||||
if (ex is WebException || ex is ApiRequestException)
|
||||
{
|
||||
return Response.AsJson(new { Result = false, Message = "Could not load the user list! We have connectivity problems connecting to Plex, Please ensure we can access Plex.Tv, The error has been logged." });
|
||||
}
|
||||
|
||||
return Response.AsJson (new { Result = false, Message = ex.Message});
|
||||
return Response.AsJson(new { Result = false, Message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
private Negotiator CouchPotato()
|
||||
{
|
||||
dynamic model = new ExpandoObject();
|
||||
var settings = CpService.GetSettings();
|
||||
model = settings;
|
||||
|
||||
return View["CouchPotato", model];
|
||||
return View["CouchPotato", settings];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Response SaveCouchPotato()
|
||||
{
|
||||
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
|
||||
|
@ -503,11 +504,11 @@ namespace PlexRequests.UI.Modules
|
|||
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
|
||||
}
|
||||
|
||||
private Negotiator Status()
|
||||
private async Task<Negotiator> Status()
|
||||
{
|
||||
var checker = new StatusChecker();
|
||||
var status = checker.GetStatus();
|
||||
var md = new Markdown(new MarkdownOptions { AutoNewLines = true });
|
||||
var status = await Cache.GetOrSetAsync(CacheKeys.LastestProductVersion, async () => await checker.GetStatus(), 30);
|
||||
var md = new Markdown(new MarkdownOptions { AutoNewLines = true, AutoHyperlink = true});
|
||||
status.ReleaseNotes = md.Transform(status.ReleaseNotes);
|
||||
return View["Status", status];
|
||||
}
|
||||
|
@ -825,14 +826,14 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
if (settings.Enabled && settings.EnabledNoticeTime && string.IsNullOrEmpty(settings.NoticeMessage))
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "If you are going to enabled the notice, then we need a message!"});
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "If you are going to enabled the notice, then we need a message!" });
|
||||
}
|
||||
|
||||
var result = await LandingSettings.SaveSettingsAsync(settings);
|
||||
|
||||
return Response.AsJson(result
|
||||
? new JsonResponseModel { Result = true }
|
||||
: new JsonResponseModel { Result = false, Message = "Could not save to Db Please check the logs"});
|
||||
: new JsonResponseModel { Result = false, Message = "Could not save to Db Please check the logs" });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -75,7 +75,7 @@ namespace PlexRequests.UI.Modules
|
|||
CpApi = cpApi;
|
||||
Cache = cache;
|
||||
|
||||
Get["/"] = _ => LoadRequests();
|
||||
Get["/", true] = async (x, ct) => await LoadRequests();
|
||||
Get["/movies", true] = async (x, ct) => await GetMovies();
|
||||
Get["/tvshows", true] = async (c, ct) => await GetTvShows();
|
||||
Get["/albums", true] = async (x, ct) => await GetAlbumRequests();
|
||||
|
@ -101,9 +101,9 @@ namespace PlexRequests.UI.Modules
|
|||
private ICouchPotatoApi CpApi { get; }
|
||||
private ICacheProvider Cache { get; }
|
||||
|
||||
private Negotiator LoadRequests()
|
||||
private async Task<Negotiator> LoadRequests()
|
||||
{
|
||||
var settings = PrSettings.GetSettings();
|
||||
var settings = await PrSettings.GetSettingsAsync();
|
||||
return View["Index", settings];
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Nancy;
|
||||
|
||||
|
@ -43,14 +44,14 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
Cache = provider;
|
||||
|
||||
Get["/"] = _ => CheckLatestVersion();
|
||||
Get["/", true] = async (x,ct) => await CheckLatestVersion();
|
||||
}
|
||||
|
||||
private ICacheProvider Cache { get; }
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private Response CheckLatestVersion()
|
||||
private async Task<Response> CheckLatestVersion()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -60,7 +61,7 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
|
||||
var checker = new StatusChecker();
|
||||
var release = Cache.GetOrSet(CacheKeys.LastestProductVersion, () => checker.GetStatus(), 30);
|
||||
var release = await Cache.GetOrSetAsync(CacheKeys.LastestProductVersion, async() => await checker.GetStatus(), 30);
|
||||
|
||||
return Response.AsJson(release.UpdateAvailable
|
||||
? new JsonUpdateAvailableModel { UpdateAvailable = true}
|
||||
|
|
|
@ -26,13 +26,11 @@
|
|||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.Extensions;
|
||||
using Nancy.Responses;
|
||||
using Nancy.Responses.Negotiation;
|
||||
|
||||
using NLog;
|
||||
|
@ -41,7 +39,6 @@ using PlexRequests.Api.Interfaces;
|
|||
using PlexRequests.Api.Models.Plex;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
@using PlexRequests.UI.Helpers
|
||||
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<PlexRequests.Core.SettingModels.CouchPotatoSettings>
|
||||
@Html.Partial("_Sidebar")
|
||||
@{
|
||||
int port;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
@using System.Linq
|
||||
@using PlexRequests.Core.Models
|
||||
@using PlexRequests.UI.Helpers
|
||||
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<IssuesModel>
|
||||
@{
|
||||
var baseUrl = Html.GetBaseUrl();
|
||||
var formAction = string.Empty;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue