From f9e0c23e625bdc5166efc88f933d8e75d236069a Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 12 Feb 2021 01:35:22 +0100 Subject: [PATCH] Better handling of current environement --- Kyoo/Program.cs | 28 ++++++++++++++++++++++---- Kyoo/Startup.cs | 6 ++---- Kyoo/Views/API/SubtitleApi.cs | 38 ----------------------------------- 3 files changed, 26 insertions(+), 46 deletions(-) diff --git a/Kyoo/Program.cs b/Kyoo/Program.cs index 5e5ff2c0..bc6ef89b 100644 --- a/Kyoo/Program.cs +++ b/Kyoo/Program.cs @@ -7,19 +7,39 @@ using Microsoft.VisualBasic.FileIO; namespace Kyoo { - public class Program + public static class Program { public static async Task Main(string[] args) { if (args.Length > 0) FileSystem.CurrentDirectory = args[0]; - Console.WriteLine($"Running as {Environment.UserName} in {FileSystem.CurrentDirectory}."); if (!File.Exists("./appsettings.json")) File.Copy(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"), "appsettings.json"); - await CreateWebHostBuilder(args).Build().RunAsync(); + + + bool? debug = Environment.GetEnvironmentVariable("ENVIRONEMENT")?.ToLowerInvariant() switch + { + "d" => true, + "dev" => true, + "debug" => true, + "development" => true, + "p" => false, + "prod" => false, + "production" => false, + _ => null + }; + + if (debug == null) + Console.WriteLine($"Invalid ENVIRONEMENT variable. Supported values are \"debug\" and \"prod\". Ignoring..."); + + Console.WriteLine($"Running as {Environment.UserName}."); + IWebHostBuilder host = CreateWebHostBuilder(args); + if (debug != null) + host = host.UseEnvironment(debug == true ? "Development" : "Production"); + await host.Build().RunAsync(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + private static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseKestrel(config => { config.AddServerHeader = false; }) .UseUrls("http://*:5000") diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index 06e9d09e..4eaa185c 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -34,7 +34,6 @@ namespace Kyoo _loggerFactory = loggerFactory; } - // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSpaStaticFiles(configuration => @@ -102,7 +101,7 @@ namespace Kyoo o.DefaultScheme = IdentityConstants.ApplicationScheme; o.DefaultSignInScheme = IdentityConstants.ExternalScheme; }) - .AddIdentityCookies(o => { }); + .AddIdentityCookies(_ => { }); services.AddAuthentication() .AddJwtBearer(options => { @@ -158,8 +157,7 @@ namespace Kyoo services.AddHostedService(provider => (TaskManager)provider.GetService()); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + public static void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { diff --git a/Kyoo/Views/API/SubtitleApi.cs b/Kyoo/Views/API/SubtitleApi.cs index 64238563..132b3b19 100644 --- a/Kyoo/Views/API/SubtitleApi.cs +++ b/Kyoo/Views/API/SubtitleApi.cs @@ -43,44 +43,6 @@ namespace Kyoo.Api string mime = subtitle.Codec == "ass" ? "text/x-ssa" : "application/x-subrip"; return PhysicalFile(subtitle.Path, mime); } - - // [HttpGet("extract/{showSlug}-s{seasonNumber}e{episodeNumber}")] - // [Authorize(Policy="Admin")] - // public async Task ExtractSubtitle(string showSlug, long seasonNumber, long episodeNumber) - // { - // Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber); - // episode.Tracks = null; - // - // Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path); - // foreach (Track track in tracks) - // { - // track.EpisodeID = episode.ID; - // _libraryManager.Register(track); - // } - // await _libraryManager.SaveChanges(); - // return "Done. " + tracks.Length + " track(s) extracted."; - // } - // - // [HttpGet("extract/{showSlug}")] - // [Authorize(Policy="Admin")] - // public async Task ExtractSubtitle(string showSlug) - // { - // IEnumerable episodes = _libraryManager.GetShow(showSlug).Episodes; - // foreach (Episode episode in episodes) - // { - // episode.Tracks = null; - // - // Track[] tracks = await _transcoder.ExtractSubtitles(episode.Path); - // foreach (Track track in tracks) - // { - // track.EpisodeID = episode.ID; - // _libraryManager.Register(track); - // } - // await _libraryManager.SaveChanges(); - // } - // - // return "Done."; - // } }