Cleanup config options

This commit is contained in:
Zoe Roux 2023-03-16 14:47:18 +09:00
parent 03bd5b4c78
commit e17b4c6e23
6 changed files with 21 additions and 32 deletions

View File

@ -1,5 +1,5 @@
# Useful config options # Useful config options
LIBRARY_ROOT=./video LIBRARY_ROOT=/video
TVDB__APIKEY= TVDB__APIKEY=
THEMOVIEDB__APIKEY= THEMOVIEDB__APIKEY=
PUBLIC_BACK_URL=http://localhost:5000 PUBLIC_BACK_URL=http://localhost:5000

View File

@ -66,14 +66,7 @@ namespace Kyoo.Abstractions.Controllers
/// ///
/// If a field should be loosely typed, <see cref="Dictionary{TKey,TValue}"/> or <c>null</c> /// If a field should be loosely typed, <see cref="Dictionary{TKey,TValue}"/> or <c>null</c>
/// can be specified. /// can be specified.
/// WARNING: null means an unmanaged type that won't be editable. This can be used
/// for external libraries or variable arguments.
/// </summary> /// </summary>
/// <remarks>
/// All use of the configuration must be specified here and not registered elsewhere, if a type is registered
/// elsewhere the configuration won't be editable via the <see cref="IConfigurationManager"/> and all values
/// will be discarded on edit.
/// </remarks>
Dictionary<string, Type> Configuration { get; } Dictionary<string, Type> Configuration { get; }
/// <summary> /// <summary>

View File

@ -28,11 +28,6 @@ namespace Kyoo.Core.Models.Options
/// </summary> /// </summary>
public const string Path = "Basics"; public const string Path = "Basics";
/// <summary>
/// The internal url where the server will listen. It supports globing.
/// </summary>
public string Url { get; set; } = "http://*:5000";
/// <summary> /// <summary>
/// The path of the plugin directory. /// The path of the plugin directory.
/// </summary> /// </summary>

View File

@ -29,6 +29,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Serilog; using Serilog;
using Serilog.Events;
using Serilog.Templates; using Serilog.Templates;
using Serilog.Templates.Themes; using Serilog.Templates.Themes;
using ILogger = Serilog.ILogger; using ILogger = Serilog.ILogger;
@ -85,6 +86,16 @@ namespace Kyoo.Host
/// <returns>A task representing the whole process</returns> /// <returns>A task representing the whole process</returns>
public async Task Start(string[] args, Action<ContainerBuilder> configure) public async Task Start(string[] args, Action<ContainerBuilder> configure)
{ {
IConfiguration parsed = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddEnvironmentVariables("KYOO_")
.AddCommandLine(args)
.Build();
string path = Path.GetFullPath(parsed.GetValue("DATADIR", "/kyoo"));
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
Environment.CurrentDirectory = path;
LoggerConfiguration config = new(); LoggerConfiguration config = new();
_ConfigureLogging(config); _ConfigureLogging(config);
Log.Logger = config.CreateBootstrapLogger(); Log.Logger = config.CreateBootstrapLogger();
@ -112,6 +123,7 @@ namespace Kyoo.Host
try try
{ {
_logger.Information("Version: {Version}", Assembly.GetExecutingAssembly().GetName().Version.ToString(3)); _logger.Information("Version: {Version}", Assembly.GetExecutingAssembly().GetName().Version.ToString(3));
_logger.Information("Data directory: {DataDirectory}", Environment.CurrentDirectory);
await host.RunAsync(cancellationToken); await host.RunAsync(cancellationToken);
} }
catch (Exception ex) catch (Exception ex)
@ -168,6 +180,9 @@ namespace Kyoo.Host
"[{@t:HH:mm:ss} {@l:u3} {Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), 25} " "[{@t:HH:mm:ss} {@l:u3} {Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), 25} "
+ "({@i:D10})] {@m}{#if not EndsWith(@m, '\n')}\n{#end}{@x}"; + "({@i:D10})] {@m}{#if not EndsWith(@m, '\n')}\n{#end}{@x}";
builder builder
.MinimumLevel.Warning()
.MinimumLevel.Override("Kyoo", LogEventLevel.Verbose)
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Verbose)
.WriteTo.Console(new ExpressionTemplate(template, theme: TemplateTheme.Code)) .WriteTo.Console(new ExpressionTemplate(template, theme: TemplateTheme.Code))
.Enrich.WithThreadId() .Enrich.WithThreadId()
.Enrich.FromLogContext(); .Enrich.FromLogContext();

View File

@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<PackageId>Kyoo.Host</PackageId> <OutputType>Exe</OutputType>
<AssemblyName>Kyoo.Host</AssemblyName>
<RootNamespace>Kyoo.Host</RootNamespace>
<StartupObject>Kyoo.Host.Program</StartupObject>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -25,8 +27,4 @@
<ProjectReference Include="../Kyoo.Authentication/Kyoo.Authentication.csproj" /> <ProjectReference Include="../Kyoo.Authentication/Kyoo.Authentication.csproj" />
<ProjectReference Include="../Kyoo.Swagger/Kyoo.Swagger.csproj" /> <ProjectReference Include="../Kyoo.Swagger/Kyoo.Swagger.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="settings.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project> </Project>

View File

@ -6,18 +6,6 @@
"metadataPath": "metadata/" "metadataPath": "metadata/"
}, },
"logging": {
"MinimumLevel": {
"Default": "Warning",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.EntityFrameworkCore": "Fatal",
"Kyoo": "Verbose"
}
}
},
"tasks": { "tasks": {
"parallels": "1", "parallels": "1",
"scheduled": { "scheduled": {