Better handling of current environement

This commit is contained in:
Zoe Roux 2021-02-12 01:35:22 +01:00
parent 6db91bf3ae
commit f9e0c23e62
3 changed files with 26 additions and 46 deletions

View File

@ -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")

View File

@ -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<ITaskManager>());
}
// 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())
{

View File

@ -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<string> 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<string> ExtractSubtitle(string showSlug)
// {
// IEnumerable<Episode> 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.";
// }
}