From 08b5527891d95aab02d1b945681310e08deb9db2 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 1 Aug 2017 23:02:14 +0100 Subject: [PATCH] Working on the landing page #1458 #865 --- src/Ombi/ClientApp/app/app.component.html | 6 +- src/Ombi/ClientApp/app/app.module.ts | 2 + src/Ombi/ClientApp/app/interfaces/IImages.ts | 3 + .../landingpage/landingpage.component.html | 72 ++++++++----------- .../app/landingpage/landingpage.component.ts | 12 +++- .../ClientApp/app/services/image.service.ts | 17 +++++ src/Ombi/Controllers/BaseV1ApiController.cs | 6 +- .../Controllers/External/EmbyController.cs | 3 +- .../Controllers/External/PlexController.cs | 3 +- .../Controllers/External/RadarrController.cs | 3 +- .../Controllers/External/SonarrController.cs | 3 +- .../Controllers/External/TesterController.cs | 3 +- src/Ombi/Controllers/IdentityController.cs | 3 +- src/Ombi/Controllers/ImagesController.cs | 47 ++++++++++++ src/Ombi/Controllers/LoggingController.cs | 3 +- src/Ombi/Controllers/RequestController.cs | 3 +- src/Ombi/Controllers/SearchController.cs | 3 +- src/Ombi/Controllers/SettingsController.cs | 3 +- src/Ombi/Controllers/StatusController.cs | 4 +- src/Ombi/Ombi.csproj | 1 + src/Ombi/Program.cs | 57 +++++++-------- src/Ombi/Startup.cs | 2 +- 22 files changed, 166 insertions(+), 93 deletions(-) create mode 100644 src/Ombi/ClientApp/app/interfaces/IImages.ts create mode 100644 src/Ombi/ClientApp/app/services/image.service.ts create mode 100644 src/Ombi/Controllers/ImagesController.cs diff --git a/src/Ombi/ClientApp/app/app.component.html b/src/Ombi/ClientApp/app/app.component.html index da74c36b7..8bf3b4969 100644 --- a/src/Ombi/ClientApp/app/app.component.html +++ b/src/Ombi/ClientApp/app/app.component.html @@ -44,7 +44,11 @@ -
+
+ +
+
+
diff --git a/src/Ombi/ClientApp/app/app.module.ts b/src/Ombi/ClientApp/app/app.module.ts index 8133929fd..87fe9f79e 100644 --- a/src/Ombi/ClientApp/app/app.module.ts +++ b/src/Ombi/ClientApp/app/app.module.ts @@ -31,6 +31,7 @@ import { AuthGuard } from './auth/auth.guard'; import { AuthModule } from './auth/auth.module'; import { IdentityService } from './services/identity.service'; import { StatusService } from './services/status.service'; +import { ImageService } from './services/image.service'; // Modules @@ -94,6 +95,7 @@ const routes: Routes = [ SettingsService, IdentityService, StatusService, +ImageService, //DragulaService ], bootstrap: [AppComponent] diff --git a/src/Ombi/ClientApp/app/interfaces/IImages.ts b/src/Ombi/ClientApp/app/interfaces/IImages.ts new file mode 100644 index 000000000..7b0eb2e05 --- /dev/null +++ b/src/Ombi/ClientApp/app/interfaces/IImages.ts @@ -0,0 +1,3 @@ +export interface IImages { + url: string +} \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/landingpage/landingpage.component.html b/src/Ombi/ClientApp/app/landingpage/landingpage.component.html index c22ffa3a6..deb35032e 100644 --- a/src/Ombi/ClientApp/app/landingpage/landingpage.component.html +++ b/src/Ombi/ClientApp/app/landingpage/landingpage.component.html @@ -1,51 +1,35 @@ -
+
- + + diff --git a/src/Ombi/ClientApp/app/landingpage/landingpage.component.ts b/src/Ombi/ClientApp/app/landingpage/landingpage.component.ts index d17a9384e..d12de8cdd 100644 --- a/src/Ombi/ClientApp/app/landingpage/landingpage.component.ts +++ b/src/Ombi/ClientApp/app/landingpage/landingpage.component.ts @@ -4,6 +4,9 @@ import { RequestService } from '../services/request.service'; import { ILandingPageSettings, ICustomizationSettings } from '../interfaces/ISettings'; import { IRequestCountModel } from '../interfaces/IRequestModel'; +import { DomSanitizer } from '@angular/platform-browser'; +import { ImageService } from '../services/image.service'; + @Component({ templateUrl: './landingpage.component.html', @@ -11,11 +14,13 @@ import { IRequestCountModel } from '../interfaces/IRequestModel'; }) export class LandingPageComponent implements OnInit { - constructor(private settingsService: SettingsService, private requestService : RequestService) { } + constructor(private settingsService: SettingsService, private requestService: RequestService, + private images: ImageService, private sanitizer: DomSanitizer) { } customizationSettings : ICustomizationSettings; landingPageSettings: ILandingPageSettings; requestCount: IRequestCountModel; + background: any; mediaServerStatus: boolean; @@ -23,7 +28,10 @@ export class LandingPageComponent implements OnInit { this.settingsService.getCustomization().subscribe(x => this.customizationSettings = x); this.settingsService.getLandingPage().subscribe(x => this.landingPageSettings = x); this.requestService.getRequestsCount().subscribe(x => this.requestCount = x); - + this.images.getRandomBackground().subscribe(x => { + this.background = this.sanitizer.bypassSecurityTrustStyle('url(' + x.url + ')'); + + }); this.mediaServerStatus = true; } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/services/image.service.ts b/src/Ombi/ClientApp/app/services/image.service.ts new file mode 100644 index 000000000..50c987aee --- /dev/null +++ b/src/Ombi/ClientApp/app/services/image.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@angular/core'; +import { Http } from '@angular/http'; +import { Observable } from 'rxjs/Rx'; + +import { ServiceHelpers } from './service.helpers'; +import { IImages } from '../interfaces/IImages'; + +@Injectable() +export class ImageService extends ServiceHelpers { + constructor(public http : Http) { + super(http, '/api/v1/Images/'); + } + + getRandomBackground(): Observable { + return this.http.get(`${this.url}background/`, { headers: this.headers }).map(this.extractData); + } +} \ No newline at end of file diff --git a/src/Ombi/Controllers/BaseV1ApiController.cs b/src/Ombi/Controllers/BaseV1ApiController.cs index f6ea39b27..61c01fb2e 100644 --- a/src/Ombi/Controllers/BaseV1ApiController.cs +++ b/src/Ombi/Controllers/BaseV1ApiController.cs @@ -3,8 +3,12 @@ namespace Ombi.Controllers { [Route(ApiBase)] - public class BaseV1ApiController : Controller + public class ApiV1Attribute : RouteAttribute { protected const string ApiBase = "api/v1/[controller]"; + + public ApiV1Attribute() : base(ApiBase) + { + } } } \ No newline at end of file diff --git a/src/Ombi/Controllers/External/EmbyController.cs b/src/Ombi/Controllers/External/EmbyController.cs index 6dc919737..48ab27152 100644 --- a/src/Ombi/Controllers/External/EmbyController.cs +++ b/src/Ombi/Controllers/External/EmbyController.cs @@ -13,7 +13,8 @@ namespace Ombi.Controllers.External /// /// [Admin] - public class EmbyController : BaseV1ApiController + [ApiV1] + public class EmbyController : Controller { /// /// diff --git a/src/Ombi/Controllers/External/PlexController.cs b/src/Ombi/Controllers/External/PlexController.cs index 744a85550..170df0451 100644 --- a/src/Ombi/Controllers/External/PlexController.cs +++ b/src/Ombi/Controllers/External/PlexController.cs @@ -14,7 +14,8 @@ using Ombi.Models.External; namespace Ombi.Controllers.External { [Admin] - public class PlexController : BaseV1ApiController + [ApiV1] + public class PlexController : Controller { public PlexController(IPlexApi plexApi, ISettingsService plexSettings) { diff --git a/src/Ombi/Controllers/External/RadarrController.cs b/src/Ombi/Controllers/External/RadarrController.cs index ea86cca66..849e6bdb3 100644 --- a/src/Ombi/Controllers/External/RadarrController.cs +++ b/src/Ombi/Controllers/External/RadarrController.cs @@ -10,7 +10,8 @@ using Ombi.Settings.Settings.Models.External; namespace Ombi.Controllers.External { [Admin] - public class RadarrController : BaseV1ApiController + [ApiV1] + public class RadarrController : Controller { public RadarrController(IRadarrApi radarr, ISettingsService settings) { diff --git a/src/Ombi/Controllers/External/SonarrController.cs b/src/Ombi/Controllers/External/SonarrController.cs index ac4bdfab0..6d2043a14 100644 --- a/src/Ombi/Controllers/External/SonarrController.cs +++ b/src/Ombi/Controllers/External/SonarrController.cs @@ -11,7 +11,8 @@ using Ombi.Core.Settings.Models.External; namespace Ombi.Controllers.External { [Admin] - public class SonarrController : BaseV1ApiController + [ApiV1] + public class SonarrController : Controller { public SonarrController(ISonarrApi sonarr, ISettingsService settings) { diff --git a/src/Ombi/Controllers/External/TesterController.cs b/src/Ombi/Controllers/External/TesterController.cs index 17ed01581..39ee39c13 100644 --- a/src/Ombi/Controllers/External/TesterController.cs +++ b/src/Ombi/Controllers/External/TesterController.cs @@ -15,7 +15,8 @@ namespace Ombi.Controllers.External /// /// [Admin] - public class TesterController : BaseV1ApiController + [ApiV1] + public class TesterController : Controller { /// /// Initializes a new instance of the class. diff --git a/src/Ombi/Controllers/IdentityController.cs b/src/Ombi/Controllers/IdentityController.cs index f4a342cf1..8a82d2d19 100644 --- a/src/Ombi/Controllers/IdentityController.cs +++ b/src/Ombi/Controllers/IdentityController.cs @@ -34,7 +34,8 @@ namespace Ombi.Controllers /// /// [PowerUser] - public class IdentityController : BaseV1ApiController + [ApiV1] + public class IdentityController : Controller { public IdentityController(UserManager user, IMapper mapper, RoleManager rm, IEmailProvider prov, ISettingsService s, diff --git a/src/Ombi/Controllers/ImagesController.cs b/src/Ombi/Controllers/ImagesController.cs new file mode 100644 index 000000000..d0ec27de9 --- /dev/null +++ b/src/Ombi/Controllers/ImagesController.cs @@ -0,0 +1,47 @@ +using Microsoft.AspNetCore.Mvc; +using Ombi.Api.FanartTv; +using Ombi.Store.Repository; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ombi.Controllers +{ + [ApiV1] + public class ImagesController : Controller + { + public ImagesController(IFanartTvApi api, IApplicationConfigRepository config) + { + Api = api; + Config = config; + } + + private IFanartTvApi Api { get; } + private IApplicationConfigRepository Config { get; } + + [HttpGet("background")] + public async Task GetBackgroundImage() + { + var moviesArray = new[]{ + 278, + 238, + 431483, + 372058, + 244786, + 680, + 155, + 13, + 1891, + 399106 + }; + + var key = await Config.Get(Store.Entities.ConfigurationTypes.FanartTv); + + var result = await Api.GetMovieImages(155, key.Value); + + return new { url = result.moviebackground[0].url }; + + } + } +} diff --git a/src/Ombi/Controllers/LoggingController.cs b/src/Ombi/Controllers/LoggingController.cs index 3b2a75ad4..dd12ae1a4 100644 --- a/src/Ombi/Controllers/LoggingController.cs +++ b/src/Ombi/Controllers/LoggingController.cs @@ -7,7 +7,8 @@ using System; namespace Ombi.Controllers { [Authorize] - public class LoggingController : BaseV1ApiController + [ApiV1] + public class LoggingController : Controller { public LoggingController(ILogger logger) { diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index bc51440b2..86602c01a 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -12,7 +12,8 @@ using System.Diagnostics; namespace Ombi.Controllers { [Authorize] - public class RequestController : BaseV1ApiController + [ApiV1] + public class RequestController : Controller { public RequestController(IMovieRequestEngine engine, ITvRequestEngine tvRequestEngine) { diff --git a/src/Ombi/Controllers/SearchController.cs b/src/Ombi/Controllers/SearchController.cs index 66a06c299..7150a423b 100644 --- a/src/Ombi/Controllers/SearchController.cs +++ b/src/Ombi/Controllers/SearchController.cs @@ -14,7 +14,8 @@ using StackExchange.Profiling; namespace Ombi.Controllers { [Authorize] - public class SearchController : BaseV1ApiController + [ApiV1] + public class SearchController : Controller { public SearchController(IMovieEngine movie, ITvSearchEngine tvEngine, ILogger logger) { diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index fce4d15fa..026fcf3ca 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -24,7 +24,8 @@ namespace Ombi.Controllers /// /// [Admin] - public class SettingsController : BaseV1ApiController + [ApiV1] + public class SettingsController : Controller { /// /// Initializes a new instance of the class. diff --git a/src/Ombi/Controllers/StatusController.cs b/src/Ombi/Controllers/StatusController.cs index 98f6dadbf..6a044cccb 100644 --- a/src/Ombi/Controllers/StatusController.cs +++ b/src/Ombi/Controllers/StatusController.cs @@ -36,8 +36,8 @@ using Ombi.Settings.Settings.Models; namespace Ombi.Controllers { - - public class StatusController : BaseV1ApiController + [ApiV1] + public class StatusController : Controller { public StatusController(ISettingsService ombi) { diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index 4e11e0fbd..bf24935db 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -40,6 +40,7 @@ + diff --git a/src/Ombi/Program.cs b/src/Ombi/Program.cs index 9e1d5c614..d0ba609ff 100644 --- a/src/Ombi/Program.cs +++ b/src/Ombi/Program.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Ombi.Store.Context; using Ombi.Store.Entities; +using CommandLine; namespace Ombi { @@ -13,35 +14,18 @@ namespace Ombi public static void Main(string[] args) { Console.Title = "Ombi"; - var port = 5000; - var urlArgs = $"http://*:{port}"; - if (args.Length <= 0) - { - Console.WriteLine("No URL provided, we will run on \"http://localhost:5000\""); - //Console.WriteLine("Please provider the argument -url e.g. \"ombi.exe -url http://ombi.io:80/\""); - } - else - { - if (args[0].Contains("-url")) + var options = new Options(); + int port = 0; + string host = string.Empty; + Parser.Default.ParseArguments(args) + .WithParsed(o => { - try - { - urlArgs = args[0].Replace("-url ", string.Empty); - var index = urlArgs.IndexOf(':', urlArgs.IndexOf(':') + 1); - var portString = urlArgs.Substring(index + 1, urlArgs.Length - index - 1); - port = int.Parse(portString); - - urlArgs = urlArgs.Substring(0, urlArgs.Length - portString.Length - 1); - } - catch (Exception e) - { - Console.WriteLine("Port is not defined or correctly formatted"); - Console.WriteLine(e.Message); - Console.ReadLine(); - Environment.Exit(1); - } - } - } + port = o.Port; + host = o.Host; + }); + + var urlArgs = $"{host}:{port}"; + var urlValue = string.Empty; using (var ctx = new OmbiContext()) { @@ -67,7 +51,7 @@ namespace Ombi urlValue = url.Value; port = int.Parse(dbPort.Value); } - else if (!url.Value.Equals(urlArgs)) + if (url != null && !url.Value.Equals(host)) { url.Value = urlArgs; ctx.SaveChanges(); @@ -84,16 +68,25 @@ namespace Ombi Console.WriteLine($"We are running on {urlValue}"); - var host = new WebHostBuilder() + var webHost = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() - .UseUrls($"{urlValue}:{port}") + .UseUrls(urlArgs) .UseStartup() .Build(); - host.Run(); + webHost.Run(); } } + + public class Options + { + [Option('h', "host", Required = false, HelpText = "The Hostname default is http://*", Default ="http://*")] + public string Host { get; set; } + + [Option('p', "port", Required = false, HelpText = "The port, default is 5000", Default =5000)] + public int Port { get; set; } + } } diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index 788525c7a..fa2100924 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -193,7 +193,7 @@ namespace Ombi app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions { #if !DEBUG - Authority = $"{url.Value}:{port.Value}", + Authority = $"http://localhost:{port.Value}", #else Authority = $"http://localhost:52038/", #endif