From 3f62d0d5ecbece47dedbdf83f9ff166e07bb374c Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Tue, 18 Apr 2017 16:24:15 +0100 Subject: [PATCH] Added some sonarr stuff --- Ombi/Ombi.Api.Emby/EmbyApi.cs | 12 +-- Ombi/Ombi.Api.Emby/IEmbyApi.cs | 6 +- Ombi/Ombi.Api.Sonarr/ISonarrApi.cs | 12 +++ Ombi/Ombi.Api.Sonarr/Models/Cutoff.cs | 8 ++ Ombi/Ombi.Api.Sonarr/Models/Item.cs | 8 ++ Ombi/Ombi.Api.Sonarr/Models/Quality.cs | 8 ++ Ombi/Ombi.Api.Sonarr/Models/SonarrProfile.cs | 12 +++ .../Models/SonarrRootFolder.cs | 9 ++ Ombi/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj | 11 ++ Ombi/Ombi.Api.Sonarr/SonarrApi.cs | 37 +++++++ Ombi/Ombi.Api/ContentType.cs | 4 +- Ombi/Ombi.Api/Request.cs | 7 +- .../Models/External/ExternalSettings.cs | 6 +- .../Models/External/SonarrSettings.cs | 19 ++++ .../Ombi.DependencyInjection/IocExtensions.cs | 2 + .../Ombi.DependencyInjection.csproj | 1 + Ombi/Ombi.sln | 9 +- Ombi/Ombi/Attributes/AdminAttribute.cs | 13 +++ Ombi/Ombi/Attributes/PowerUserAttribute.cs | 12 +++ .../{ => External}/EmbyController.cs | 5 +- .../{ => External}/PlexController.cs | 13 +-- .../Controllers/External/SonarrController.cs | 37 +++++++ Ombi/Ombi/Controllers/IdentityController.cs | 3 +- Ombi/Ombi/Controllers/SearchController.cs | 2 + Ombi/Ombi/Controllers/SettingsController.cs | 5 +- Ombi/Ombi/Ombi.csproj | 6 ++ Ombi/Ombi/Startup.cs | 10 -- Ombi/Ombi/wwwroot/app/interfaces/ISettings.ts | 11 +- Ombi/Ombi/wwwroot/app/interfaces/ISonarr.ts | 27 +++++ .../services/applications/sonarr.service.ts | 21 ++++ .../wwwroot/app/services/settings.service.ts | 10 +- .../app/settings/emby/emby.component.html | 7 ++ .../app/settings/plex/plex.component.html | 8 ++ .../wwwroot/app/settings/settings.module.ts | 3 +- .../app/settings/sonarr/sonarr.component.html | 102 ++++++++++++++++++ .../app/settings/sonarr/sonarr.component.ts | 79 ++++++++++++++ Ombi/Ombi/wwwroot/systemjs.config.js | 14 +++ Ombi/Ombi/wwwroot/systemjs.config.js.map | 1 + 38 files changed, 517 insertions(+), 43 deletions(-) create mode 100644 Ombi/Ombi.Api.Sonarr/ISonarrApi.cs create mode 100644 Ombi/Ombi.Api.Sonarr/Models/Cutoff.cs create mode 100644 Ombi/Ombi.Api.Sonarr/Models/Item.cs create mode 100644 Ombi/Ombi.Api.Sonarr/Models/Quality.cs create mode 100644 Ombi/Ombi.Api.Sonarr/Models/SonarrProfile.cs create mode 100644 Ombi/Ombi.Api.Sonarr/Models/SonarrRootFolder.cs create mode 100644 Ombi/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj create mode 100644 Ombi/Ombi.Api.Sonarr/SonarrApi.cs create mode 100644 Ombi/Ombi.Core/Settings/Models/External/SonarrSettings.cs create mode 100644 Ombi/Ombi/Attributes/AdminAttribute.cs create mode 100644 Ombi/Ombi/Attributes/PowerUserAttribute.cs rename Ombi/Ombi/Controllers/{ => External}/EmbyController.cs (95%) rename Ombi/Ombi/Controllers/{ => External}/PlexController.cs (85%) create mode 100644 Ombi/Ombi/Controllers/External/SonarrController.cs create mode 100644 Ombi/Ombi/wwwroot/app/interfaces/ISonarr.ts create mode 100644 Ombi/Ombi/wwwroot/app/services/applications/sonarr.service.ts create mode 100644 Ombi/Ombi/wwwroot/app/settings/sonarr/sonarr.component.html create mode 100644 Ombi/Ombi/wwwroot/app/settings/sonarr/sonarr.component.ts create mode 100644 Ombi/Ombi/wwwroot/systemjs.config.js create mode 100644 Ombi/Ombi/wwwroot/systemjs.config.js.map diff --git a/Ombi/Ombi.Api.Emby/EmbyApi.cs b/Ombi/Ombi.Api.Emby/EmbyApi.cs index 91e1ab789..64a570322 100644 --- a/Ombi/Ombi.Api.Emby/EmbyApi.cs +++ b/Ombi/Ombi.Api.Emby/EmbyApi.cs @@ -21,9 +21,9 @@ namespace Ombi.Api.Emby /// /// /// - public async Task> GetUsers(Uri baseUri, string apiKey) + public async Task> GetUsers(string baseUri, string apiKey) { - var request = new Request("emby/users", baseUri.ToString(), HttpMethod.Get); + var request = new Request("emby/users", baseUri, HttpMethod.Get); AddHeaders(request, apiKey); var obj = await Api.Request>(request); @@ -31,9 +31,9 @@ namespace Ombi.Api.Emby return obj; } - public async Task GetSystemInformation(string apiKey, Uri baseUrl) + public async Task GetSystemInformation(string apiKey, string baseUrl) { - var request = new Request("emby/System/Info", baseUrl.ToString(), HttpMethod.Get); + var request = new Request("emby/System/Info", baseUrl, HttpMethod.Get); AddHeaders(request, apiKey); @@ -42,9 +42,9 @@ namespace Ombi.Api.Emby return obj; } - public async Task LogIn(string username, string password, string apiKey, Uri baseUri) + public async Task LogIn(string username, string password, string apiKey, string baseUri) { - var request = new Request("emby/users/authenticatebyname", baseUri.ToString(), HttpMethod.Post); + var request = new Request("emby/users/authenticatebyname", baseUri, HttpMethod.Post); var body = new diff --git a/Ombi/Ombi.Api.Emby/IEmbyApi.cs b/Ombi/Ombi.Api.Emby/IEmbyApi.cs index faecd238a..bfc9770cc 100644 --- a/Ombi/Ombi.Api.Emby/IEmbyApi.cs +++ b/Ombi/Ombi.Api.Emby/IEmbyApi.cs @@ -7,8 +7,8 @@ namespace Ombi.Api.Emby { public interface IEmbyApi { - Task GetSystemInformation(string apiKey, Uri baseUrl); - Task> GetUsers(Uri baseUri, string apiKey); - Task LogIn(string username, string password, string apiKey, Uri baseUri); + Task GetSystemInformation(string apiKey, string baseUrl); + Task> GetUsers(string baseUri, string apiKey); + Task LogIn(string username, string password, string apiKey, string baseUri); } } \ No newline at end of file diff --git a/Ombi/Ombi.Api.Sonarr/ISonarrApi.cs b/Ombi/Ombi.Api.Sonarr/ISonarrApi.cs new file mode 100644 index 000000000..2547ff750 --- /dev/null +++ b/Ombi/Ombi.Api.Sonarr/ISonarrApi.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Ombi.Api.Sonarr.Models; + +namespace Ombi.Api.Sonarr +{ + public interface ISonarrApi + { + Task> GetProfiles(string apiKey, string baseUrl); + Task> GetRootFolders(string apiKey, string baseUrl); + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Api.Sonarr/Models/Cutoff.cs b/Ombi/Ombi.Api.Sonarr/Models/Cutoff.cs new file mode 100644 index 000000000..14e7fe3ad --- /dev/null +++ b/Ombi/Ombi.Api.Sonarr/Models/Cutoff.cs @@ -0,0 +1,8 @@ +namespace Ombi.Api.Sonarr.Models +{ + public class Cutoff + { + public int id { get; set; } + public string name { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Api.Sonarr/Models/Item.cs b/Ombi/Ombi.Api.Sonarr/Models/Item.cs new file mode 100644 index 000000000..8937d761c --- /dev/null +++ b/Ombi/Ombi.Api.Sonarr/Models/Item.cs @@ -0,0 +1,8 @@ +namespace Ombi.Api.Sonarr.Models +{ + public class Item + { + public Quality quality { get; set; } + public bool allowed { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Api.Sonarr/Models/Quality.cs b/Ombi/Ombi.Api.Sonarr/Models/Quality.cs new file mode 100644 index 000000000..76a1c92d8 --- /dev/null +++ b/Ombi/Ombi.Api.Sonarr/Models/Quality.cs @@ -0,0 +1,8 @@ +namespace Ombi.Api.Sonarr.Models +{ + public class Quality + { + public int id { get; set; } + public string name { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Api.Sonarr/Models/SonarrProfile.cs b/Ombi/Ombi.Api.Sonarr/Models/SonarrProfile.cs new file mode 100644 index 000000000..179459c43 --- /dev/null +++ b/Ombi/Ombi.Api.Sonarr/Models/SonarrProfile.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace Ombi.Api.Sonarr.Models +{ + public class SonarrProfile + { + public string name { get; set; } + public Cutoff cutoff { get; set; } + public List items { get; set; } + public int id { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Api.Sonarr/Models/SonarrRootFolder.cs b/Ombi/Ombi.Api.Sonarr/Models/SonarrRootFolder.cs new file mode 100644 index 000000000..9c32091c0 --- /dev/null +++ b/Ombi/Ombi.Api.Sonarr/Models/SonarrRootFolder.cs @@ -0,0 +1,9 @@ +namespace Ombi.Api.Sonarr.Models +{ + public class SonarrRootFolder + { + public int id { get; set; } + public string path { get; set; } + public long freespace { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj b/Ombi/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj new file mode 100644 index 000000000..a8c3e7a4c --- /dev/null +++ b/Ombi/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj @@ -0,0 +1,11 @@ + + + + netstandard1.6 + + + + + + + \ No newline at end of file diff --git a/Ombi/Ombi.Api.Sonarr/SonarrApi.cs b/Ombi/Ombi.Api.Sonarr/SonarrApi.cs new file mode 100644 index 000000000..e05f9eec8 --- /dev/null +++ b/Ombi/Ombi.Api.Sonarr/SonarrApi.cs @@ -0,0 +1,37 @@ +using System.Net.Http; +using System.Collections.Generic; +using System.Threading.Tasks; + +using Ombi.Api.Sonarr.Models; + +namespace Ombi.Api.Sonarr +{ + public class SonarrApi : ISonarrApi + { + + public SonarrApi() + { + Api = new Api(); + } + + private Api Api { get; } + + public async Task> GetProfiles(string apiKey, string baseUrl) + { + var request = new Request(baseUrl, "/api/profile", HttpMethod.Get); + + request.AddHeader("X-Api-Key", apiKey); + + return await Api.Request>(request); + } + + public async Task> GetRootFolders(string apiKey, string baseUrl) + { + var request = new Request(baseUrl, "/api/rootfolder", HttpMethod.Get); + + request.AddHeader("X-Api-Key", apiKey); + + return await Api.Request>(request); + } + } +} diff --git a/Ombi/Ombi.Api/ContentType.cs b/Ombi/Ombi.Api/ContentType.cs index 7a2d8ca71..1f13e5a91 100644 --- a/Ombi/Ombi.Api/ContentType.cs +++ b/Ombi/Ombi.Api/ContentType.cs @@ -3,6 +3,8 @@ public enum ContentType { Json, - Xml + Xml, + Text, + Html, } } \ No newline at end of file diff --git a/Ombi/Ombi.Api/Request.cs b/Ombi/Ombi.Api/Request.cs index abc6a5669..2a1881140 100644 --- a/Ombi/Ombi.Api/Request.cs +++ b/Ombi/Ombi.Api/Request.cs @@ -2,13 +2,16 @@ using System.Collections.Generic; using System.Net.Http; using System.Text; -using Newtonsoft.Json; -using Newtonsoft.Json.Bson; namespace Ombi.Api { public class Request { + public Request() + { + + } + public Request(string endpoint, string baseUrl, HttpMethod http, ContentType contentType = ContentType.Json) { Endpoint = endpoint; diff --git a/Ombi/Ombi.Core/Settings/Models/External/ExternalSettings.cs b/Ombi/Ombi.Core/Settings/Models/External/ExternalSettings.cs index cdaf3158c..5470a20e8 100644 --- a/Ombi/Ombi.Core/Settings/Models/External/ExternalSettings.cs +++ b/Ombi/Ombi.Core/Settings/Models/External/ExternalSettings.cs @@ -12,17 +12,17 @@ namespace Ombi.Core.Settings.Models.External public int Port { get; set; } [JsonIgnore] - public virtual Uri FullUri + public virtual string FullUri { get { if (!string.IsNullOrEmpty(SubDir)) { var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); - return formattedSubDir; + return formattedSubDir.ToString(); } var formatted = Ip.ReturnUri(Port, Ssl); - return formatted; + return formatted.ToString(); } } } diff --git a/Ombi/Ombi.Core/Settings/Models/External/SonarrSettings.cs b/Ombi/Ombi.Core/Settings/Models/External/SonarrSettings.cs new file mode 100644 index 000000000..0438f111d --- /dev/null +++ b/Ombi/Ombi.Core/Settings/Models/External/SonarrSettings.cs @@ -0,0 +1,19 @@ +namespace Ombi.Core.Settings.Models.External +{ + public class SonarrSettings : ExternalSettings + { + public bool Enabled { get; set; } + public string ApiKey { get; set; } + public string QualityProfile { get; set; } + public bool SeasonFolders { get; set; } + /// + /// This is the root path ID + /// + /// + /// The root path. + /// + public string RootPath { get; set; } + public string FullRootPath { get; set; } + + } +} \ No newline at end of file diff --git a/Ombi/Ombi.DependencyInjection/IocExtensions.cs b/Ombi/Ombi.DependencyInjection/IocExtensions.cs index d3ad2f723..ed11ce162 100644 --- a/Ombi/Ombi.DependencyInjection/IocExtensions.cs +++ b/Ombi/Ombi.DependencyInjection/IocExtensions.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Ombi.Api.Emby; using Ombi.Api.Plex; +using Ombi.Api.Sonarr; using Ombi.Core; using Ombi.Core.Engine; using Ombi.Core.IdentityResolver; @@ -44,6 +45,7 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); return services; } diff --git a/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj b/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj index 358c86a80..b49771653 100644 --- a/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj +++ b/Ombi/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj @@ -13,6 +13,7 @@ + diff --git a/Ombi/Ombi.sln b/Ombi/Ombi.sln index 27fcb5cc4..03992f72f 100644 --- a/Ombi/Ombi.sln +++ b/Ombi/Ombi.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26403.3 +VisualStudioVersion = 15.0.26403.7 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi", "Ombi\Ombi.csproj", "{C987AA67-AFE1-468F-ACD3-EAD5A48E1F6A}" EndProject @@ -38,6 +38,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Schedule", "Ombi.Sched EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Api.Emby", "Ombi.Api.Emby\Ombi.Api.Emby.csproj", "{08FF107D-31E1-470D-AF86-E09B015CEE06}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Api.Sonarr", "Ombi.Api.Sonarr\Ombi.Api.Sonarr.csproj", "{CFB5E008-D0D0-43C0-AA06-89E49D17F384}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -88,6 +90,10 @@ Global {08FF107D-31E1-470D-AF86-E09B015CEE06}.Debug|Any CPU.Build.0 = Debug|Any CPU {08FF107D-31E1-470D-AF86-E09B015CEE06}.Release|Any CPU.ActiveCfg = Release|Any CPU {08FF107D-31E1-470D-AF86-E09B015CEE06}.Release|Any CPU.Build.0 = Release|Any CPU + {CFB5E008-D0D0-43C0-AA06-89E49D17F384}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFB5E008-D0D0-43C0-AA06-89E49D17F384}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFB5E008-D0D0-43C0-AA06-89E49D17F384}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFB5E008-D0D0-43C0-AA06-89E49D17F384}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -99,5 +105,6 @@ Global {63E63511-1C7F-4162-8F92-8F7391B3C8A3} = {025FB189-2FFB-4F43-A64B-6F1B5A0D2065} {2E1A7B91-F29B-42BC-8F1E-1CF2DCC389BA} = {9293CA11-360A-4C20-A674-B9E794431BF5} {08FF107D-31E1-470D-AF86-E09B015CEE06} = {9293CA11-360A-4C20-A674-B9E794431BF5} + {CFB5E008-D0D0-43C0-AA06-89E49D17F384} = {9293CA11-360A-4C20-A674-B9E794431BF5} EndGlobalSection EndGlobal diff --git a/Ombi/Ombi/Attributes/AdminAttribute.cs b/Ombi/Ombi/Attributes/AdminAttribute.cs new file mode 100644 index 000000000..8e5b91ebf --- /dev/null +++ b/Ombi/Ombi/Attributes/AdminAttribute.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Authorization; + +namespace Ombi.Attributes +{ + public class AdminAttribute : AuthorizeAttribute + { + public AdminAttribute() + { + base.Roles = "Admin"; + } + + } +} \ No newline at end of file diff --git a/Ombi/Ombi/Attributes/PowerUserAttribute.cs b/Ombi/Ombi/Attributes/PowerUserAttribute.cs new file mode 100644 index 000000000..7d6c2a0be --- /dev/null +++ b/Ombi/Ombi/Attributes/PowerUserAttribute.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Authorization; + +namespace Ombi.Attributes +{ + public class PowerUserAttribute : AuthorizeAttribute + { + public PowerUserAttribute() + { + Roles = "Admin, PowerUser"; + } + } +} \ No newline at end of file diff --git a/Ombi/Ombi/Controllers/EmbyController.cs b/Ombi/Ombi/Controllers/External/EmbyController.cs similarity index 95% rename from Ombi/Ombi/Controllers/EmbyController.cs rename to Ombi/Ombi/Controllers/External/EmbyController.cs index 5c0b778f2..2bca2337f 100644 --- a/Ombi/Ombi/Controllers/EmbyController.cs +++ b/Ombi/Ombi/Controllers/External/EmbyController.cs @@ -3,12 +3,13 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Ombi.Api.Emby; +using Ombi.Attributes; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; -namespace Ombi.Controllers +namespace Ombi.Controllers.External { - [Authorize] + [Admin] public class EmbyController : BaseV1ApiController { public EmbyController(IEmbyApi emby, ISettingsService embySettings) diff --git a/Ombi/Ombi/Controllers/PlexController.cs b/Ombi/Ombi/Controllers/External/PlexController.cs similarity index 85% rename from Ombi/Ombi/Controllers/PlexController.cs rename to Ombi/Ombi/Controllers/External/PlexController.cs index db93d91f9..62ce2c9e7 100644 --- a/Ombi/Ombi/Controllers/PlexController.cs +++ b/Ombi/Ombi/Controllers/External/PlexController.cs @@ -1,19 +1,16 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Ombi.Api.Plex; using Ombi.Api.Plex.Models; -using Ombi.Core.Engine; -using Ombi.Core.Models.Requests; -using Ombi.Core.Models.Search; +using Ombi.Attributes; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; -namespace Ombi.Controllers +namespace Ombi.Controllers.External { - [Authorize] + [Admin] public class PlexController : BaseV1ApiController { public PlexController(IPlexApi plexApi, ISettingsService plexSettings) @@ -31,7 +28,7 @@ namespace Ombi.Controllers { // Do we already have settings? var settings = await PlexSettings.GetSettingsAsync(); - if (settings != null && !string.IsNullOrEmpty(settings.PlexAuthToken)) return null; + if (!string.IsNullOrEmpty(settings?.PlexAuthToken)) return null; var result = await PlexApi.SignIn(request); if (!string.IsNullOrEmpty(result.user?.authentication_token)) diff --git a/Ombi/Ombi/Controllers/External/SonarrController.cs b/Ombi/Ombi/Controllers/External/SonarrController.cs new file mode 100644 index 000000000..7a8c271c3 --- /dev/null +++ b/Ombi/Ombi/Controllers/External/SonarrController.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Ombi.Api.Sonarr; +using Ombi.Api.Sonarr.Models; +using Ombi.Attributes; +using Ombi.Core.Settings; +using Ombi.Core.Settings.Models.External; + +namespace Ombi.Controllers.External +{ + [Admin] + public class SonarrController : BaseV1ApiController + { + public SonarrController(ISonarrApi sonarr, ISettingsService settings) + { + SonarrApi = sonarr; + SonarrSettings = settings; + } + + private ISonarrApi SonarrApi { get; } + private ISettingsService SonarrSettings { get; } + + [HttpPost("Profiles")] + public async Task> GetProfiles([FromBody] SonarrSettings settings) + { + return await SonarrApi.GetProfiles(settings.ApiKey, settings.FullUri); + } + + [HttpPost("RootFolders")] + public async Task> GetRootFolders([FromBody] SonarrSettings settings) + { + return await SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri); + } + } +} \ No newline at end of file diff --git a/Ombi/Ombi/Controllers/IdentityController.cs b/Ombi/Ombi/Controllers/IdentityController.cs index 6598f5310..efe8f10cb 100644 --- a/Ombi/Ombi/Controllers/IdentityController.cs +++ b/Ombi/Ombi/Controllers/IdentityController.cs @@ -4,6 +4,7 @@ using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Ombi.Attributes; using Ombi.Core.Claims; using Ombi.Core.IdentityResolver; using Ombi.Core.Models; @@ -11,7 +12,7 @@ using Ombi.Models; namespace Ombi.Controllers { - [Authorize] + [PowerUser] public class IdentityController : BaseV1ApiController { public IdentityController(IUserIdentityManager identity) diff --git a/Ombi/Ombi/Controllers/SearchController.cs b/Ombi/Ombi/Controllers/SearchController.cs index c7d48b8b9..ba80ff352 100644 --- a/Ombi/Ombi/Controllers/SearchController.cs +++ b/Ombi/Ombi/Controllers/SearchController.cs @@ -2,12 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Ombi.Core; using Ombi.Core.Models.Search; namespace Ombi.Controllers { + [Authorize] public class SearchController : BaseV1ApiController { public SearchController(IMovieEngine movie) diff --git a/Ombi/Ombi/Controllers/SettingsController.cs b/Ombi/Ombi/Controllers/SettingsController.cs index fdd5f4d31..e6a31bb19 100644 --- a/Ombi/Ombi/Controllers/SettingsController.cs +++ b/Ombi/Ombi/Controllers/SettingsController.cs @@ -2,13 +2,14 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Ombi.Attributes; using Ombi.Core.Settings; using Ombi.Core.Settings.Models; using Ombi.Core.Settings.Models.External; namespace Ombi.Controllers { - [Authorize(Roles = "Admin")] + [Admin] public class SettingsController : BaseV1ApiController { public SettingsController(ISettingsResolver resolver) @@ -30,7 +31,7 @@ namespace Ombi.Controllers return await Save(ombi); } - + [HttpGet("plex")] public async Task PlexSettings() { diff --git a/Ombi/Ombi/Ombi.csproj b/Ombi/Ombi/Ombi.csproj index 6f609d293..fcbe7d811 100644 --- a/Ombi/Ombi/Ombi.csproj +++ b/Ombi/Ombi/Ombi.csproj @@ -53,4 +53,10 @@ + + + + PreserveNewest + + diff --git a/Ombi/Ombi/Startup.cs b/Ombi/Ombi/Startup.cs index 822a5ab8e..f27763977 100644 --- a/Ombi/Ombi/Startup.cs +++ b/Ombi/Ombi/Startup.cs @@ -14,16 +14,6 @@ namespace Ombi { public partial class Startup { - - //public void ConfigureServices(IServiceCollection services) - //{ - //} - - //public void Configure(IApplicationBuilder app) - //{ - // app.UseHangfireServer(); - // app.UseHangfireDashboard(); - //} public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() diff --git a/Ombi/Ombi/wwwroot/app/interfaces/ISettings.ts b/Ombi/Ombi/wwwroot/app/interfaces/ISettings.ts index 7e45a6a95..db94a0313 100644 --- a/Ombi/Ombi/wwwroot/app/interfaces/ISettings.ts +++ b/Ombi/Ombi/wwwroot/app/interfaces/ISettings.ts @@ -4,6 +4,7 @@ export interface IExternalSettings extends ISettings { ssl: boolean, + enable:boolean, subDir: string, ip: string, port:number @@ -18,15 +19,21 @@ export interface IOmbiSettings extends ISettings { } export interface IEmbySettings extends IExternalSettings { - enable: boolean, apiKey: string, administratorId: string, enableEpisodeSearching:boolean } export interface IPlexSettings extends IExternalSettings { - enable: boolean, enableEpisodeSearching: boolean, plexAuthToken: string, machineIdentifier: string +} + +export interface ISonarrSettings extends IExternalSettings { + apiKey: string, + qualityProfile: string, + seasonFolders: boolean, + rootPath: string, + fullRootPath:string } \ No newline at end of file diff --git a/Ombi/Ombi/wwwroot/app/interfaces/ISonarr.ts b/Ombi/Ombi/wwwroot/app/interfaces/ISonarr.ts new file mode 100644 index 000000000..f4702683b --- /dev/null +++ b/Ombi/Ombi/wwwroot/app/interfaces/ISonarr.ts @@ -0,0 +1,27 @@ +export interface ISonarrRootFolder { + id: number, + path: string, + freespace:number, +} + +export interface ISonarrProfile { + name: string, + id: number, + cutoff: ICutoff, + items:IItem[], +} + +export interface ICutoff { + id: number, + name:string, +} + +export interface IItem { + allowed: boolean, + quality:IQuality, +} + +export interface IQuality { + id: number, + name:string, +} \ No newline at end of file diff --git a/Ombi/Ombi/wwwroot/app/services/applications/sonarr.service.ts b/Ombi/Ombi/wwwroot/app/services/applications/sonarr.service.ts new file mode 100644 index 000000000..93a7feb69 --- /dev/null +++ b/Ombi/Ombi/wwwroot/app/services/applications/sonarr.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { AuthHttp } from 'angular2-jwt'; +import { Observable } from 'rxjs/Rx'; + +import { ServiceAuthHelpers } from '../service.helpers'; +import { ISonarrSettings } from '../../interfaces/ISettings'; +import { ISonarrRootFolder, ISonarrProfile } from '../../interfaces/ISonarr'; + +@Injectable() +export class SonarrService extends ServiceAuthHelpers { + constructor(http: AuthHttp) { + super(http, '/api/v1/Sonarr/'); + } + + getRootFolders(settings: ISonarrSettings): Observable { + return this.http.post(`${this.url}/RootFolders/`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + } + getQualityProfiles(settings: ISonarrSettings): Observable { + return this.http.post(`${this.url}/Profiles/`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + } +} \ No newline at end of file diff --git a/Ombi/Ombi/wwwroot/app/services/settings.service.ts b/Ombi/Ombi/wwwroot/app/services/settings.service.ts index d8f51e590..d55333894 100644 --- a/Ombi/Ombi/wwwroot/app/services/settings.service.ts +++ b/Ombi/Ombi/wwwroot/app/services/settings.service.ts @@ -3,7 +3,7 @@ import { AuthHttp } from 'angular2-jwt'; import { Observable } from 'rxjs/Rx'; import { ServiceAuthHelpers } from './service.helpers'; -import { IOmbiSettings, IEmbySettings, IPlexSettings } from '../interfaces/ISettings'; +import { IOmbiSettings, IEmbySettings, IPlexSettings, ISonarrSettings } from '../interfaces/ISettings'; @Injectable() export class SettingsService extends ServiceAuthHelpers { @@ -35,4 +35,12 @@ export class SettingsService extends ServiceAuthHelpers { return this.http.post(`${this.url}/Plex/`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); } + getSonarr(): Observable { + return this.http.get(`${this.url}/Sonarr`).map(this.extractData); + } + + saveSonarr(settings: ISonarrSettings): Observable { + return this.http.post(`${this.url}/Sonarr`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + } + } \ No newline at end of file diff --git a/Ombi/Ombi/wwwroot/app/settings/emby/emby.component.html b/Ombi/Ombi/wwwroot/app/settings/emby/emby.component.html index a896e06dc..702372337 100644 --- a/Ombi/Ombi/wwwroot/app/settings/emby/emby.component.html +++ b/Ombi/Ombi/wwwroot/app/settings/emby/emby.component.html @@ -1,6 +1,13 @@ 
Emby Configuration + +
+
+ + +
+
diff --git a/Ombi/Ombi/wwwroot/app/settings/plex/plex.component.html b/Ombi/Ombi/wwwroot/app/settings/plex/plex.component.html index b48ff1fc0..b930623e5 100644 --- a/Ombi/Ombi/wwwroot/app/settings/plex/plex.component.html +++ b/Ombi/Ombi/wwwroot/app/settings/plex/plex.component.html @@ -1,6 +1,14 @@ 
Plex Configuration + +
+
+ + +
+
+
diff --git a/Ombi/Ombi/wwwroot/app/settings/settings.module.ts b/Ombi/Ombi/wwwroot/app/settings/settings.module.ts index 29665748b..10df7055f 100644 --- a/Ombi/Ombi/wwwroot/app/settings/settings.module.ts +++ b/Ombi/Ombi/wwwroot/app/settings/settings.module.ts @@ -6,6 +6,7 @@ import { RouterModule, Routes } from '@angular/router'; import { AuthService } from '../auth/auth.service'; import { AuthGuard } from '../auth/auth.guard'; import { AuthModule } from '../auth/auth.module'; +import { SonarrService } from '../services/applications/sonarr.service'; import { OmbiComponent } from './ombi/ombi.component' import { PlexComponent } from './plex/plex.component' @@ -41,7 +42,7 @@ const routes: Routes = [ RouterModule ], providers: [ - + SonarrService, AuthService, AuthGuard, ], diff --git a/Ombi/Ombi/wwwroot/app/settings/sonarr/sonarr.component.html b/Ombi/Ombi/wwwroot/app/settings/sonarr/sonarr.component.html new file mode 100644 index 000000000..9321bb908 --- /dev/null +++ b/Ombi/Ombi/wwwroot/app/settings/sonarr/sonarr.component.html @@ -0,0 +1,102 @@ +
+
+
+ Sonarr Settings + +
+
+ + +
+
+ + + +
+ +
+ +
+
+ +
+ + +
+ +
+
+ + +
+ +
+ +
+
+
+
+ + + +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+ +
+
+ + +
+ +
+
+ +
+ +
+
+ + +
+
+ + +
+ +
+
+
+ +
+
+ + +
+
+ +
+
+
+
+
diff --git a/Ombi/Ombi/wwwroot/app/settings/sonarr/sonarr.component.ts b/Ombi/Ombi/wwwroot/app/settings/sonarr/sonarr.component.ts new file mode 100644 index 000000000..ee82a4244 --- /dev/null +++ b/Ombi/Ombi/wwwroot/app/settings/sonarr/sonarr.component.ts @@ -0,0 +1,79 @@ +import { Component, OnInit } from '@angular/core'; + +import { ISonarrSettings } from '../../interfaces/ISettings' +import { ISonarrProfile, ISonarrRootFolder } from '../../interfaces/ISonarr' +import { SettingsService } from '../../services/settings.service'; +import { SonarrService } from '../../services/applications/sonarr.service'; +import { NotificationService } from "../../services/notification.service"; + +@Component({ + selector: 'ombi', + moduleId: module.id, + templateUrl: './sonarr.component.html', +}) +export class SonarrComponent implements OnInit { + + constructor(private settingsService: SettingsService, private sonarrService: SonarrService, private notificationService: NotificationService) { } + + settings: ISonarrSettings; + + qualities: ISonarrProfile[]; + rootFolders: ISonarrRootFolder[]; + + selectedRootFolder:ISonarrRootFolder; + selectedQuality: ISonarrProfile; + + profilesRunning: boolean; + rootFoldersRunning:boolean; + + ngOnInit(): void { + this.settings = { + apiKey: "", + port: 8081, + fullRootPath: "", + rootPath: "", + subDir: "", + ssl: false, + seasonFolders: false, + qualityProfile: "", + ip: "", + enable: false, + id: 0 + }; + } + + + getProfiles() { + this.profilesRunning = true; + this.sonarrService.getQualityProfiles(this.settings).subscribe(x => { + this.qualities = x; + + this.profilesRunning = false; + this.notificationService.success("Quality Profiles", "Successfully retrevied the Quality Profiles"); + }); + } + + getRootFolders() { + this.rootFoldersRunning = true; + this.sonarrService.getRootFolders(this.settings).subscribe(x => { + this.rootFolders = x; + + this.rootFoldersRunning = false; + this.notificationService.success("Settings Saved", "Successfully retrevied the Root Folders"); + }); + } + + test() { + // TODO + } + + save() { + this.settingsService.saveSonarr(this.settings).subscribe(x => { + if (x) { + this.notificationService.success("Settings Saved", "Successfully saved Ombi settings"); + } else { + this.notificationService.success("Settings Saved", "There was an error when saving the Ombi settings"); + } + }); + } +} \ No newline at end of file diff --git a/Ombi/Ombi/wwwroot/systemjs.config.js b/Ombi/Ombi/wwwroot/systemjs.config.js new file mode 100644 index 000000000..79a38f763 --- /dev/null +++ b/Ombi/Ombi/wwwroot/systemjs.config.js @@ -0,0 +1,14 @@ +"use strict"; +System.config({ + baseURL: '/lib', + packages: { + '.': { + defaultExtension: 'js' + } + }, + map: { app: '../app' } +}); +System.import('bundle').then(function () { + System.import('/app/main'); +}); +//# sourceMappingURL=systemjs.config.js.map \ No newline at end of file diff --git a/Ombi/Ombi/wwwroot/systemjs.config.js.map b/Ombi/Ombi/wwwroot/systemjs.config.js.map new file mode 100644 index 000000000..1a2f3a3c3 --- /dev/null +++ b/Ombi/Ombi/wwwroot/systemjs.config.js.map @@ -0,0 +1 @@ +{"version":3,"file":"systemjs.config.js","sourceRoot":"","sources":["systemjs.config.ts"],"names":[],"mappings":";AAAA,MAAM,CAAC,MAAM,CAAC;IACV,OAAO,EAAE,MAAM;IACf,QAAQ,EAAE;QACN,GAAG,EAAE;YACD,gBAAgB,EAAE,IAAI;SACzB;KACJ;IACD,GAAG,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE;CACzB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;IACzB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAA"} \ No newline at end of file