diff --git a/.env.example b/.env.example index 4a85ca47..e46503ed 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,12 @@ +# Useful config options +LIBRARY_ROOT=./video TVDB__APIKEY= THEMOVIEDB__APIKEY= -AUTHENTICATION_SECRET= PUBLIC_BACK_URL=http://localhost:5000 +AUTHENTICATION_SECRET= + +# To debug the front end, you can set the following to an external backend +KYOO_URL=https://kyoo.sdg.moe/api # Database things (optional) POSTGRES_USER=KyooUser diff --git a/back/Dockerfile b/back/Dockerfile index dcbd08ed..45e1ffb1 100644 --- a/back/Dockerfile +++ b/back/Dockerfile @@ -5,17 +5,15 @@ COPY src/Kyoo.Transcoder . RUN cmake . && make -j FROM mcr.microsoft.com/dotnet/sdk:6.0 as builder -WORKDIR /kyoo COPY Kyoo.sln ./Kyoo.sln COPY nuget.config ./nuget.config COPY src/Directory.Build.props src/Directory.Build.props COPY src/Kyoo.Authentication/Kyoo.Authentication.csproj src/Kyoo.Authentication/Kyoo.Authentication.csproj -COPY src/Kyoo.Host.Generic/Kyoo.Host.Generic.csproj src/Kyoo.Host.Generic/Kyoo.Host.Generic.csproj COPY src/Kyoo.TheMovieDb/Kyoo.TheMovieDb.csproj src/Kyoo.TheMovieDb/Kyoo.TheMovieDb.csproj COPY src/Kyoo.Abstractions/Kyoo.Abstractions.csproj src/Kyoo.Abstractions/Kyoo.Abstractions.csproj COPY src/Kyoo.Core/Kyoo.Core.csproj src/Kyoo.Core/Kyoo.Core.csproj -COPY src/Kyoo.Host.Console/Kyoo.Host.Console.csproj src/Kyoo.Host.Console/Kyoo.Host.Console.csproj +COPY src/Kyoo.Host/Kyoo.Host.csproj src/Kyoo.Host/Kyoo.Host.csproj COPY src/Kyoo.Postgresql/Kyoo.Postgresql.csproj src/Kyoo.Postgresql/Kyoo.Postgresql.csproj COPY src/Kyoo.Swagger/Kyoo.Swagger.csproj src/Kyoo.Swagger/Kyoo.Swagger.csproj COPY src/Kyoo.TheTvdb/Kyoo.TheTvdb.csproj src/Kyoo.TheTvdb/Kyoo.TheTvdb.csproj @@ -24,12 +22,14 @@ RUN dotnet restore COPY . . ARG VERSION -RUN dotnet publish --no-restore -c Release -o /opt/kyoo "-p:Version=${VERSION:-"0.0.0-dev"};SkipTranscoder=true" src/Kyoo.Host.Console +RUN dotnet publish --no-restore -c Release -o /app "-p:Version=${VERSION:-"0.0.0-dev"};SkipTranscoder=true" src/Kyoo.Host FROM mcr.microsoft.com/dotnet/aspnet:6.0 RUN apt-get update && apt-get install -y libavutil-dev libavcodec-dev libavformat-dev -EXPOSE 5000 -COPY --from=builder /opt/kyoo /usr/lib/kyoo +COPY --from=builder /app /app COPY --from=transcoder /transcoder/libtranscoder.so /usr/lib/kyoo -CMD ["/usr/lib/kyoo/Kyoo.Host.Console"] + +WORKDIR /kyoo +EXPOSE 5000 +CMD ["/app/Kyoo.Host"] diff --git a/back/Dockerfile.dev b/back/Dockerfile.dev index 00f0b274..9851073d 100644 --- a/back/Dockerfile.dev +++ b/back/Dockerfile.dev @@ -8,26 +8,24 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 RUN apt-get update && apt-get install -y libavutil-dev libavcodec-dev libavformat-dev WORKDIR /app - COPY Kyoo.sln ./Kyoo.sln COPY nuget.config ./nuget.config COPY src/Directory.Build.props src/Directory.Build.props COPY src/Kyoo.Authentication/Kyoo.Authentication.csproj src/Kyoo.Authentication/Kyoo.Authentication.csproj -COPY src/Kyoo.Host.Generic/Kyoo.Host.Generic.csproj src/Kyoo.Host.Generic/Kyoo.Host.Generic.csproj COPY src/Kyoo.TheMovieDb/Kyoo.TheMovieDb.csproj src/Kyoo.TheMovieDb/Kyoo.TheMovieDb.csproj COPY src/Kyoo.Abstractions/Kyoo.Abstractions.csproj src/Kyoo.Abstractions/Kyoo.Abstractions.csproj COPY src/Kyoo.Core/Kyoo.Core.csproj src/Kyoo.Core/Kyoo.Core.csproj -COPY src/Kyoo.Host.Console/Kyoo.Host.Console.csproj src/Kyoo.Host.Console/Kyoo.Host.Console.csproj +COPY src/Kyoo.Host/Kyoo.Host.csproj src/Kyoo.Host/Kyoo.Host.csproj COPY src/Kyoo.Postgresql/Kyoo.Postgresql.csproj src/Kyoo.Postgresql/Kyoo.Postgresql.csproj COPY src/Kyoo.Swagger/Kyoo.Swagger.csproj src/Kyoo.Swagger/Kyoo.Swagger.csproj COPY src/Kyoo.TheTvdb/Kyoo.TheTvdb.csproj src/Kyoo.TheTvdb/Kyoo.TheTvdb.csproj COPY tests/Kyoo.Tests/Kyoo.Tests.csproj tests/Kyoo.Tests/Kyoo.Tests.csproj - RUN dotnet restore COPY --from=transcoder /transcoder/libtranscoder.so /usr/lib/ +WORKDIR /kyoo EXPOSE 5000 ENV DOTNET_USE_POLLING_FILE_WATCHER 1 -CMD ["dotnet", "watch", "run", "--no-restore", "--project", "src/Kyoo.Host.Console"] +CMD ["dotnet", "watch", "run", "--no-restore", "--project", "/app/src/Kyoo.Host"] diff --git a/back/Kyoo.sln b/back/Kyoo.sln index 6a618cb7..134e4daa 100644 --- a/back/Kyoo.sln +++ b/back/Kyoo.sln @@ -13,19 +13,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.TheMovieDb", "src\Kyoo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Tests", "tests\Kyoo.Tests\Kyoo.Tests.csproj", "{0C8AA7EA-E723-4532-852F-35AA4E8AFED5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Host.Console", "src\Kyoo.Host.Console\Kyoo.Host.Console.csproj", "{D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Swagger", "src\Kyoo.Swagger\Kyoo.Swagger.csproj", "{7D1A7596-73F6-4D35-842E-A5AD9C620596}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{FEAE1B0E-D797-470F-9030-0EF743575ECC}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Providers", "Providers", "{8D28F5EF-0CD7-4697-A2A7-24EC31A48F21}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Databases", "Databases", "{865461CA-EC06-4B42-91CF-8723B0A9BB67}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosts", "Hosts", "{C569FF25-7E01-484C-9F72-5B99845AD94B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Host.Generic", "src\Kyoo.Host.Generic\Kyoo.Host.Generic.csproj", "{0938459E-2E2B-457F-8120-7D8CA93866A6}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Host", "src\Kyoo.Host\Kyoo.Host.csproj", "{0938459E-2E2B-457F-8120-7D8CA93866A6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -73,10 +67,6 @@ Global {4FF1ECD9-6EEF-4440-B037-A661D78FB04D}.Debug|Any CPU.Build.0 = Debug|Any CPU {4FF1ECD9-6EEF-4440-B037-A661D78FB04D}.Release|Any CPU.ActiveCfg = Release|Any CPU {4FF1ECD9-6EEF-4440-B037-A661D78FB04D}.Release|Any CPU.Build.0 = Release|Any CPU - {D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Release|Any CPU.Build.0 = Release|Any CPU {7D1A7596-73F6-4D35-842E-A5AD9C620596}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7D1A7596-73F6-4D35-842E-A5AD9C620596}.Debug|Any CPU.Build.0 = Debug|Any CPU {7D1A7596-73F6-4D35-842E-A5AD9C620596}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -90,9 +80,5 @@ Global {0C8AA7EA-E723-4532-852F-35AA4E8AFED5} = {FEAE1B0E-D797-470F-9030-0EF743575ECC} {BAB270D4-E0EA-4329-BA65-512FDAB01001} = {8D28F5EF-0CD7-4697-A2A7-24EC31A48F21} {D06BF829-23F5-40F3-A62D-627D9F4B4D6C} = {8D28F5EF-0CD7-4697-A2A7-24EC31A48F21} - {3213C96D-0BF3-460B-A8B5-B9977229408A} = {865461CA-EC06-4B42-91CF-8723B0A9BB67} - {6515380E-1E57-42DA-B6E3-E1C8A848818A} = {865461CA-EC06-4B42-91CF-8723B0A9BB67} - {D8658BEA-8949-45AC-BEBB-A4FFC4F800F5} = {C569FF25-7E01-484C-9F72-5B99845AD94B} - {0938459E-2E2B-457F-8120-7D8CA93866A6} = {C569FF25-7E01-484C-9F72-5B99845AD94B} EndGlobalSection EndGlobal diff --git a/back/src/Kyoo.Abstractions/Controllers/IApplication.cs b/back/src/Kyoo.Abstractions/Controllers/IApplication.cs deleted file mode 100644 index 11c396dd..00000000 --- a/back/src/Kyoo.Abstractions/Controllers/IApplication.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Kyoo - A portable and vast media library solution. -// Copyright (c) Kyoo. -// -// See AUTHORS.md and LICENSE file in the project root for full license information. -// -// Kyoo is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// any later version. -// -// Kyoo is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Kyoo. If not, see . - -namespace Kyoo.Abstractions.Controllers -{ - /// - /// An interface that allow one to interact with the host and shutdown or restart the app. - /// - public interface IApplication - { - /// - /// Shutdown the process and stop gracefully. - /// - void Shutdown(); - - /// - /// Restart Kyoo from scratch, reload plugins, configurations and restart the web server. - /// - void Restart(); - - /// - /// Get the data directory. - /// - /// Retrieve the data directory where runtime data should be stored. - string GetDataDirectory(); - - /// - /// Retrieve the path of the json configuration file - /// (relative to the data directory, see ). - /// - /// The configuration file name. - string GetConfigFile(); - } -} diff --git a/back/src/Kyoo.Abstractions/Controllers/IConfigurationManager.cs b/back/src/Kyoo.Abstractions/Controllers/IConfigurationManager.cs deleted file mode 100644 index b5c57565..00000000 --- a/back/src/Kyoo.Abstractions/Controllers/IConfigurationManager.cs +++ /dev/null @@ -1,86 +0,0 @@ -// Kyoo - A portable and vast media library solution. -// Copyright (c) Kyoo. -// -// See AUTHORS.md and LICENSE file in the project root for full license information. -// -// Kyoo is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// any later version. -// -// Kyoo is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Kyoo. If not, see . - -using System; -using System.Threading.Tasks; -using JetBrains.Annotations; -using Kyoo.Abstractions.Models; -using Kyoo.Abstractions.Models.Exceptions; - -namespace Kyoo.Abstractions.Controllers -{ - /// - /// A class to ease configuration management. This work WITH Microsoft's package, you can still use IOptions patterns - /// to access your options, this manager ease dynamic work and editing. - /// It works with . - /// - public interface IConfigurationManager - { - /// - /// Add an editable configuration to the editable configuration list. - /// - /// The root path of the editable configuration. It should not be a nested type. - /// The type of the configuration. - void AddTyped(string path); - - /// - /// Add an editable configuration to the editable configuration list. - /// WARNING: this method allow you to add an unmanaged type. This type won't be editable. This can be used - /// for external libraries or variable arguments. - /// - /// The root path of the editable configuration. It should not be a nested type. - void AddUntyped(string path); - - /// - /// An helper method of and . - /// This register a typed value if is not null and registers an untyped type - /// if is null. - /// - /// The root path of the editable configuration. It should not be a nested type. - /// The type of the configuration or null. - void Register(string path, [CanBeNull] Type type); - - /// - /// Get the value of a setting using it's path. - /// - /// The path of the resource (can be separated by ':' or '__'). - /// No setting found at the given path. - /// The value of the settings (if it's a strongly typed one, the given type is instantiated. - object GetValue(string path); - - /// - /// Get the value of a setting using it's path. - /// If your don't need a strongly typed value, see . - /// - /// The path of the resource (can be separated by ':' or '__'). - /// A type to strongly type your option. - /// If your type is not the same as the registered type. - /// No setting found at the given path. - /// The value of the settings (if it's a strongly typed one, the given type is instantiated. - T GetValue(string path); - - /// - /// Edit the value of a setting using it's path. Save it to the json file. - /// - /// The path of the resource (can be separated by ':' or '__'). - /// The new value of the resource. - /// No setting found at the given path. - /// A representing the asynchronous operation. - Task EditValue(string path, object value); - } -} diff --git a/back/src/Kyoo.Core/Controllers/ConfigurationManager.cs b/back/src/Kyoo.Core/Controllers/ConfigurationManager.cs deleted file mode 100644 index ba3372ad..00000000 --- a/back/src/Kyoo.Core/Controllers/ConfigurationManager.cs +++ /dev/null @@ -1,220 +0,0 @@ -// Kyoo - A portable and vast media library solution. -// Copyright (c) Kyoo. -// -// See AUTHORS.md and LICENSE file in the project root for full license information. -// -// Kyoo is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// any later version. -// -// Kyoo is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Kyoo. If not, see . - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Dynamic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Kyoo.Abstractions.Controllers; -using Kyoo.Abstractions.Models; -using Kyoo.Abstractions.Models.Exceptions; -using Kyoo.Core.Api; -using Microsoft.Extensions.Configuration; -using Newtonsoft.Json.Linq; - -namespace Kyoo.Core.Controllers -{ - /// - /// A class to ease configuration management. This work WITH Microsoft's package, you can still use IOptions patterns - /// to access your options, this manager ease dynamic work and editing. - /// It works with . - /// - public class ConfigurationManager : IConfigurationManager - { - /// - /// The configuration to retrieve and edit. - /// - private readonly IConfiguration _configuration; - - /// - /// The application running Kyoo, it is used to retrieve the configuration file. - /// - private readonly IApplication _application; - - /// - /// The strongly typed list of options - /// - private readonly Dictionary _references; - - /// - /// Create a new using the given configuration. - /// - /// The configuration to use. - /// The strongly typed option list. - /// The application running Kyoo, it is used to retrieve the configuration file. - public ConfigurationManager(IConfiguration configuration, IEnumerable references, IApplication application) - { - _configuration = configuration; - _application = application; - _references = references.ToDictionary(x => x.Path, x => x.Type, StringComparer.OrdinalIgnoreCase); - } - - /// - /// Transform the configuration section in nested expando objects. - /// - /// The section to convert - /// The converted section - private static object _ToUntyped(IConfigurationSection config) - { - ExpandoObject obj = new(); - - foreach (IConfigurationSection section in config.GetChildren()) - { - obj.TryAdd(section.Key, _ToUntyped(section)); - } - - if (!obj.Any()) - return config.Value; - return obj; - } - - /// - public void AddTyped(string path) - { - foreach (ConfigurationReference confRef in ConfigurationReference.CreateReference(path)) - _references.Add(confRef.Path, confRef.Type); - } - - /// - public void AddUntyped(string path) - { - ConfigurationReference config = ConfigurationReference.CreateUntyped(path); - _references.Add(config.Path, config.Type); - } - - /// - public void Register(string path, Type type) - { - if (type == null) - { - ConfigurationReference config = ConfigurationReference.CreateUntyped(path); - _references.Add(config.Path, config.Type); - } - else - { - foreach (ConfigurationReference confRef in ConfigurationReference.CreateReference(path, type)) - _references.Add(confRef.Path, confRef.Type); - } - } - - /// - /// Get the type of the resource at the given path - /// - /// The path of the resource - /// The path is not editable or readable - /// No configuration exists for the given path - /// The type of the resource at the given path - private Type _GetType(string path) - { - path = path.Replace("__", ":"); - - // TODO handle lists and dictionaries. - if (_references.TryGetValue(path, out Type type)) - { - if (type != null) - return type; - throw new ArgumentException($"The configuration at {path} is not editable or readable."); - } - - string parent = path.Contains(':') ? path[..path.IndexOf(':')] : null; - if (parent != null && _references.TryGetValue(parent, out type) && type == null) - throw new ArgumentException($"The configuration at {path} is not editable or readable."); - throw new ItemNotFoundException($"No configuration exists for the name: {path}"); - } - - /// - public object GetValue(string path) - { - path = path.Replace("__", ":"); - // TODO handle lists and dictionaries. - Type type = _GetType(path); - object ret = _configuration.GetValue(type, path); - if (ret != null) - return ret; - object option = Activator.CreateInstance(type); - _configuration.Bind(path, option); - return option; - } - - /// - public T GetValue(string path) - { - path = path.Replace("__", ":"); - // TODO handle lists and dictionaries. - Type type = _GetType(path); - if (typeof(T).IsAssignableFrom(type)) - { - throw new InvalidCastException($"The type {typeof(T).Name} is not valid for " + - $"a resource of type {type.Name}."); - } - return (T)GetValue(path); - } - - /// - public async Task EditValue(string path, object value) - { - path = path.Replace("__", ":"); - Type type = _GetType(path); - value = JObject.FromObject(value).ToObject(type); - if (value == null) - throw new ArgumentException("Invalid value format."); - - ExpandoObject config = _ToObject(_configuration); - IDictionary configDic = config; - configDic[path] = value; - JObject obj = JObject.FromObject(config); - await using StreamWriter writer = new(_application.GetConfigFile()); - await writer.WriteAsync(obj.ToString()); - } - - /// - /// Transform a configuration to a strongly typed object (the root configuration is an - /// but child elements are using strong types. - /// - /// The configuration to transform - /// A strongly typed representation of the configuration. - [SuppressMessage("ReSharper", "RedundantJumpStatement", - Justification = "A catch block should not be empty.")] - private ExpandoObject _ToObject(IConfiguration config) - { - ExpandoObject obj = new(); - - foreach (IConfigurationSection section in config.GetChildren()) - { - try - { - Type type = _GetType(section.Path); - obj.TryAdd(section.Key, section.Get(type)); - } - catch (ArgumentException) - { - obj.TryAdd(section.Key, _ToUntyped(section)); - } - catch - { - continue; - } - } - - return obj; - } - } -} diff --git a/back/src/Kyoo.Core/CoreModule.cs b/back/src/Kyoo.Core/CoreModule.cs index 3366c80b..0436779b 100644 --- a/back/src/Kyoo.Core/CoreModule.cs +++ b/back/src/Kyoo.Core/CoreModule.cs @@ -66,7 +66,6 @@ namespace Kyoo.Core builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); - builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); diff --git a/back/src/Kyoo.Core/Views/Admin/ConfigurationApi.cs b/back/src/Kyoo.Core/Views/Admin/ConfigurationApi.cs deleted file mode 100644 index e1d51bb7..00000000 --- a/back/src/Kyoo.Core/Views/Admin/ConfigurationApi.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Kyoo - A portable and vast media library solution. -// Copyright (c) Kyoo. -// -// See AUTHORS.md and LICENSE file in the project root for full license information. -// -// Kyoo is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// any later version. -// -// Kyoo is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Kyoo. If not, see . - -using System.Threading.Tasks; -using Kyoo.Abstractions.Controllers; -using Kyoo.Abstractions.Models.Attributes; -using Kyoo.Abstractions.Models.Permissions; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using static Kyoo.Abstractions.Models.Utils.Constants; - -namespace Kyoo.Core.Api -{ - /// - /// An API to retrieve or edit configuration settings - /// - [Route("configuration")] - [Route("config", Order = AlternativeRoute)] - [ApiController] - [PartialPermission("Configuration", Group = Group.Admin)] - [ApiDefinition("Configuration", Group = AdminGroup)] - public class ConfigurationApi : Controller - { - /// - /// The configuration manager used to retrieve and edit configuration values (while being type safe). - /// - private readonly IConfigurationManager _manager; - - /// - /// Create a new using the given configuration. - /// - /// The configuration manager used to retrieve and edit configuration values - public ConfigurationApi(IConfigurationManager manager) - { - _manager = manager; - } - - /// - /// Get config value - /// - /// - /// Retrieve a configuration's value from it's slug. - /// - /// The permission to retrieve. You can use ':' or "__" to get a child value. - /// The associate value or list of values. - /// Return the configuration value or the list of configurations - /// No configuration exists for the given slug - [HttpGet("{slug}")] - [PartialPermission(Kind.Read)] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GetConfiguration(string slug) - { - return _manager.GetValue(slug); - } - - /// - /// Edit config - /// - /// - /// Edit a configuration's value from it's slug. - /// - /// The permission to edit. You can use ':' or "__" to get a child value. - /// The new value of the configuration - /// The edited value. - /// Return the edited value - /// No configuration exists for the given slug - [HttpPut("{slug}")] - [PartialPermission(Kind.Write)] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task> EditConfiguration(string slug, [FromBody] object newValue) - { - await _manager.EditValue(slug, newValue); - return newValue; - } - } -} diff --git a/back/src/Kyoo.Host.Console/Kyoo.Host.Console.csproj b/back/src/Kyoo.Host.Console/Kyoo.Host.Console.csproj deleted file mode 100644 index a06806f3..00000000 --- a/back/src/Kyoo.Host.Console/Kyoo.Host.Console.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - Exe - Kyoo.Host.Console - Kyoo.Host.Console - Kyoo.Host.Console.Program - - - - - - diff --git a/back/src/Kyoo.Host.Generic/Application.cs b/back/src/Kyoo.Host/Application.cs similarity index 59% rename from back/src/Kyoo.Host.Generic/Application.cs rename to back/src/Kyoo.Host/Application.cs index cb1e0f9b..df492c0c 100644 --- a/back/src/Kyoo.Host.Generic/Application.cs +++ b/back/src/Kyoo.Host/Application.cs @@ -23,43 +23,29 @@ using System.Threading; using System.Threading.Tasks; using Autofac; using Autofac.Extensions.DependencyInjection; -using JetBrains.Annotations; -using Kyoo.Abstractions.Controllers; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Hosting.Systemd; using Microsoft.Extensions.Logging; using Serilog; using Serilog.Templates; using Serilog.Templates.Themes; using ILogger = Serilog.ILogger; -namespace Kyoo.Host.Generic +namespace Kyoo.Host { /// - /// The main implementation of . /// Hosts of kyoo (main functions) generally only create a new /// and return . /// - public class Application : IApplication, IDisposable + public class Application : IDisposable { /// /// The environment in witch Kyoo will run (ether "Production" or "Development"). /// private readonly string _environment; - /// - /// The path to the data directory. - /// - private string _dataDir; - - /// - /// Should the application restart after a shutdown? - /// - private bool _shouldRestart; - /// /// The cancellation token source used to allow the app to be shutdown or restarted. /// @@ -99,10 +85,8 @@ namespace Kyoo.Host.Generic /// A task representing the whole process public async Task Start(string[] args, Action configure) { - _dataDir = _SetupDataDir(args); - LoggerConfiguration config = new(); - _ConfigureLogging(config, null, null); + _ConfigureLogging(config); Log.Logger = config.CreateBootstrapLogger(); _logger = Log.Logger.ForContext(); @@ -110,76 +94,12 @@ namespace Kyoo.Host.Generic AppDomain.CurrentDomain.UnhandledException += (_, ex) => Log.Fatal(ex.ExceptionObject as Exception, "Unhandled exception"); - do - { - IHost host = _CreateWebHostBuilder(args) - .ConfigureContainer(configure) - .Build(); - - _tokenSource = new CancellationTokenSource(); - await _StartWithHost(host, _tokenSource.Token); - } - while (_shouldRestart); - } - - /// - public void Shutdown() - { - _shouldRestart = false; - _tokenSource.Cancel(); - } - - /// - public void Restart() - { - _shouldRestart = true; - _tokenSource.Cancel(); - } - - /// - public string GetDataDirectory() - { - return _dataDir; - } - - /// - public string GetConfigFile() - { - return "./settings.json"; - } - - /// - /// Parse the data directory from environment variables and command line arguments, create it if necessary. - /// Set the current directory to said data folder and place a default configuration file if it does not already - /// exists. - /// - /// The command line arguments - /// The current data directory. - private string _SetupDataDir(string[] args) - { - IConfiguration parsed = new ConfigurationBuilder() - .AddEnvironmentVariables() - .AddEnvironmentVariables("KYOO_") - .AddCommandLine(args) + IHost host = _CreateWebHostBuilder(args) + .ConfigureContainer(configure) .Build(); - string path = parsed.GetValue("datadir"); - path ??= Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Kyoo"); - path = Path.GetFullPath(path); - - if (!Directory.Exists(path)) - Directory.CreateDirectory(path); - Environment.CurrentDirectory = path; - - if (!File.Exists(GetConfigFile())) - { - File.Copy( - Path.Join(AppDomain.CurrentDomain.BaseDirectory, GetConfigFile()), - GetConfigFile() - ); - } - - return path; + _tokenSource = new CancellationTokenSource(); + await _StartWithHost(host, _tokenSource.Token); } /// @@ -191,9 +111,7 @@ namespace Kyoo.Host.Generic { try { - _logger.Information("Running as {Name}", Environment.UserName); _logger.Information("Version: {Version}", Assembly.GetExecutingAssembly().GetName().Version.ToString(3)); - _logger.Information("Data directory: {DataDirectory}", GetDataDirectory()); await host.RunAsync(cancellationToken); } catch (Exception ex) @@ -209,25 +127,18 @@ namespace Kyoo.Host.Generic /// A new web host instance private IHostBuilder _CreateWebHostBuilder(string[] args) { - IConfiguration configuration = _SetupConfig(new ConfigurationBuilder(), args).Build(); - return new HostBuilder() .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .UseContentRoot(AppDomain.CurrentDomain.BaseDirectory) .UseEnvironment(_environment) - .UseSystemd() .ConfigureAppConfiguration(x => _SetupConfig(x, args)) - .UseSerilog((host, services, builder) => _ConfigureLogging(builder, host.Configuration, services)) + .UseSerilog((host, services, builder) => _ConfigureLogging(builder)) .ConfigureServices(x => x.AddRouting()) - .ConfigureContainer(x => - { - x.RegisterInstance(this).As().SingleInstance().ExternallyOwned(); - }) .ConfigureWebHost(x => x .UseKestrel(options => { options.AddServerHeader = false; }) .UseIIS() .UseIISIntegration() - .UseUrls(configuration.GetValue("basics:url")) + .UseUrls("http://*:5000") .UseStartup(host => PluginsStartup.FromWebHost(host, new LoggerFactory().AddSerilog())) ); } @@ -240,9 +151,8 @@ namespace Kyoo.Host.Generic /// The modified configuration builder private IConfigurationBuilder _SetupConfig(IConfigurationBuilder builder, string[] args) { - return builder.SetBasePath(GetDataDirectory()) - .AddJsonFile(Path.Join(AppDomain.CurrentDomain.BaseDirectory, GetConfigFile()), false, true) - .AddJsonFile(GetConfigFile(), false, true) + return builder + .AddJsonFile(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "./settings.json"), false, true) .AddEnvironmentVariables() .AddEnvironmentVariables("KYOO_") .AddCommandLine(args); @@ -252,51 +162,13 @@ namespace Kyoo.Host.Generic /// Configure the logging. /// /// The logger builder to configure. - /// The configuration to read settings from. - /// The services to read configuration from. - private void _ConfigureLogging(LoggerConfiguration builder, - [CanBeNull] IConfiguration configuration, - [CanBeNull] IServiceProvider services) + private void _ConfigureLogging(LoggerConfiguration builder) { - if (configuration != null) - { - try - { - builder.ReadFrom.Configuration(configuration, "logging"); - } - catch (Exception ex) - { - _logger.Fatal(ex, "Could not read serilog configuration"); - } - } - - if (services != null) - builder.ReadFrom.Services(services); - const string template = "[{@t:HH:mm:ss} {@l:u3} {Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), 25} " + "({@i:D10})] {@m}{#if not EndsWith(@m, '\n')}\n{#end}{@x}"; - - if (SystemdHelpers.IsSystemdService()) - { - const string syslogTemplate = "[{SourceContext,-35}] {Message:lj}{NewLine}{Exception}"; - - builder - .WriteTo.Console(new ExpressionTemplate(template, theme: TemplateTheme.Code)) - .WriteTo.LocalSyslog("Kyoo", outputTemplate: syslogTemplate) - .Enrich.WithThreadId() - .Enrich.FromLogContext(); - return; - } - builder .WriteTo.Console(new ExpressionTemplate(template, theme: TemplateTheme.Code)) - .WriteTo.File( - path: Path.Combine(GetDataDirectory(), "logs", "log-.log"), - formatter: new ExpressionTemplate(template), - rollingInterval: RollingInterval.Day, - rollOnFileSizeLimit: true - ) .Enrich.WithThreadId() .Enrich.FromLogContext(); } diff --git a/back/src/Kyoo.Host.Generic/Contollers/FileSystemComposite.cs b/back/src/Kyoo.Host/Contollers/FileSystemComposite.cs similarity index 99% rename from back/src/Kyoo.Host.Generic/Contollers/FileSystemComposite.cs rename to back/src/Kyoo.Host/Contollers/FileSystemComposite.cs index d2445d23..71e5ff22 100644 --- a/back/src/Kyoo.Host.Generic/Contollers/FileSystemComposite.cs +++ b/back/src/Kyoo.Host/Contollers/FileSystemComposite.cs @@ -31,7 +31,7 @@ using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -namespace Kyoo.Host.Generic.Controllers +namespace Kyoo.Host.Controllers { /// /// A composite that merge every available diff --git a/back/src/Kyoo.Host.Generic/Contollers/PluginManager.cs b/back/src/Kyoo.Host/Contollers/PluginManager.cs similarity index 99% rename from back/src/Kyoo.Host.Generic/Contollers/PluginManager.cs rename to back/src/Kyoo.Host/Contollers/PluginManager.cs index 72f7bb08..1a9ee933 100644 --- a/back/src/Kyoo.Host.Generic/Contollers/PluginManager.cs +++ b/back/src/Kyoo.Host/Contollers/PluginManager.cs @@ -28,7 +28,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Kyoo.Host.Generic.Controllers +namespace Kyoo.Host.Controllers { /// /// An implementation of . diff --git a/back/src/Kyoo.Host.Generic/Contollers/TaskManager.cs b/back/src/Kyoo.Host/Contollers/TaskManager.cs similarity index 99% rename from back/src/Kyoo.Host.Generic/Contollers/TaskManager.cs rename to back/src/Kyoo.Host/Contollers/TaskManager.cs index e036cae4..45f48040 100644 --- a/back/src/Kyoo.Host.Generic/Contollers/TaskManager.cs +++ b/back/src/Kyoo.Host/Contollers/TaskManager.cs @@ -33,7 +33,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Kyoo.Host.Generic.Controllers +namespace Kyoo.Host.Controllers { /// /// A service to handle long running tasks and a background runner. diff --git a/back/src/Kyoo.Host.Generic/HostModule.cs b/back/src/Kyoo.Host/HostModule.cs similarity index 97% rename from back/src/Kyoo.Host.Generic/HostModule.cs rename to back/src/Kyoo.Host/HostModule.cs index a6538d1b..5c3599b9 100644 --- a/back/src/Kyoo.Host.Generic/HostModule.cs +++ b/back/src/Kyoo.Host/HostModule.cs @@ -24,12 +24,12 @@ using Kyoo.Abstractions; using Kyoo.Abstractions.Controllers; using Kyoo.Core.Models.Options; using Kyoo.Core.Tasks; -using Kyoo.Host.Generic.Controllers; +using Kyoo.Host.Controllers; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; using Serilog; -namespace Kyoo.Host.Generic +namespace Kyoo.Host { /// /// A module that registers host controllers and other needed things. diff --git a/back/src/Kyoo.Host.Generic/Kyoo.Host.Generic.csproj b/back/src/Kyoo.Host/Kyoo.Host.csproj similarity index 88% rename from back/src/Kyoo.Host.Generic/Kyoo.Host.Generic.csproj rename to back/src/Kyoo.Host/Kyoo.Host.csproj index ae348c63..6d391737 100644 --- a/back/src/Kyoo.Host.Generic/Kyoo.Host.Generic.csproj +++ b/back/src/Kyoo.Host/Kyoo.Host.csproj @@ -1,12 +1,10 @@ - Kyoo.Host.Generic - Kyoo.Host.Generic + Kyoo.Host - diff --git a/back/src/Kyoo.Host.Generic/PluginsStartup.cs b/back/src/Kyoo.Host/PluginsStartup.cs similarity index 93% rename from back/src/Kyoo.Host.Generic/PluginsStartup.cs rename to back/src/Kyoo.Host/PluginsStartup.cs index 63bc88cc..4ac46ae3 100644 --- a/back/src/Kyoo.Host.Generic/PluginsStartup.cs +++ b/back/src/Kyoo.Host/PluginsStartup.cs @@ -25,7 +25,7 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Authentication; using Kyoo.Core; using Kyoo.Core.Models.Options; -using Kyoo.Host.Generic.Controllers; +using Kyoo.Host.Controllers; using Kyoo.Postgresql; using Kyoo.Swagger; using Kyoo.TheMovieDb; @@ -39,7 +39,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Kyoo.Host.Generic +namespace Kyoo.Host { /// /// The Startup class is used to configure the AspNet's webhost. @@ -148,8 +148,7 @@ namespace Kyoo.Host.Generic /// /// The asp net host to configure /// An autofac container used to create a new scope to configure asp-net. - /// The configuration manager used to register strongly typed config. - public void Configure(IApplicationBuilder app, ILifetimeScope container, IConfigurationManager config) + public void Configure(IApplicationBuilder app, ILifetimeScope container) { IEnumerable steps = _plugins.GetAllPlugins() .Append(_hostModule) @@ -162,17 +161,6 @@ namespace Kyoo.Host.Generic IServiceProvider provider = scope.Resolve(); foreach (IStartupAction step in steps) step.Run(provider); - - IEnumerable> pluginConfig = _plugins.GetAllPlugins() - .Append(_hostModule) - .SelectMany(x => x.Configuration) - .GroupBy(x => x.Key.Split(':').First()) - .Select(x => x - .OrderBy(y => y.Key.Length) - .First() - ); - foreach ((string path, Type type) in pluginConfig) - config.Register(path, type); } /// diff --git a/back/src/Kyoo.Host.Console/Program.cs b/back/src/Kyoo.Host/Program.cs similarity index 96% rename from back/src/Kyoo.Host.Console/Program.cs rename to back/src/Kyoo.Host/Program.cs index 92b7f673..730553f0 100644 --- a/back/src/Kyoo.Host.Console/Program.cs +++ b/back/src/Kyoo.Host/Program.cs @@ -17,10 +17,10 @@ // along with Kyoo. If not, see . using System.Threading.Tasks; -using Kyoo.Host.Generic; +using Kyoo.Host; using Microsoft.AspNetCore.Hosting; -namespace Kyoo.Host.Console +namespace Kyoo.Host { /// /// Program entrypoint. diff --git a/back/src/Kyoo.Host.Generic/Tasks/PluginInitializer.cs b/back/src/Kyoo.Host/Tasks/PluginInitializer.cs similarity index 100% rename from back/src/Kyoo.Host.Generic/Tasks/PluginInitializer.cs rename to back/src/Kyoo.Host/Tasks/PluginInitializer.cs diff --git a/back/src/Kyoo.Host.Generic/settings.json b/back/src/Kyoo.Host/settings.json similarity index 93% rename from back/src/Kyoo.Host.Generic/settings.json rename to back/src/Kyoo.Host/settings.json index 0d5390cf..04378c12 100644 --- a/back/src/Kyoo.Host.Generic/settings.json +++ b/back/src/Kyoo.Host/settings.json @@ -1,6 +1,5 @@ { "basics": { - "url": "http://*:5000", "pluginsPath": "plugins/", "transmuxPath": "cached/transmux", "transcodePath": "cached/transcode", @@ -44,12 +43,5 @@ }, "profilePicturePath": "users/", "secret": "4c@mraGB!KRfF@kpS8740y9FcHemKxBsqqxLbdR?" - }, - - "tvdb": { - "apiKey": "" - }, - "themoviedb": { - "apiKey": "" } } diff --git a/back/src/Kyoo.Postgresql/Kyoo.Postgresql.csproj b/back/src/Kyoo.Postgresql/Kyoo.Postgresql.csproj index 442c8c8f..54e34601 100644 --- a/back/src/Kyoo.Postgresql/Kyoo.Postgresql.csproj +++ b/back/src/Kyoo.Postgresql/Kyoo.Postgresql.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/back/tests/Kyoo.Tests/Database/TestContext.cs b/back/tests/Kyoo.Tests/Database/TestContext.cs index 339bc1ee..71b947ac 100644 --- a/back/tests/Kyoo.Tests/Database/TestContext.cs +++ b/back/tests/Kyoo.Tests/Database/TestContext.cs @@ -19,7 +19,6 @@ using System; using System.Threading.Tasks; using Kyoo.Postgresql; -using Kyoo.Postgresql; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Npgsql; diff --git a/back/tests/Kyoo.Tests/Kyoo.Tests.csproj b/back/tests/Kyoo.Tests/Kyoo.Tests.csproj index 06e07d29..b849a4a6 100644 --- a/back/tests/Kyoo.Tests/Kyoo.Tests.csproj +++ b/back/tests/Kyoo.Tests/Kyoo.Tests.csproj @@ -30,7 +30,7 @@ - + diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index ef30fa2f..c5b784db 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -8,15 +8,8 @@ services: ports: - "5000:5000" restart: on-failure - environment: - - KYOO_DATADIR=/var/lib/kyoo - - DATABASE__ENABLED=postgres - - DATABASE__CONFIGURATIONS__POSTGRES__SERVER=postgres - - DATABASE__CONFIGURATIONS__POSTGRES__USER=${POSTGRES_USER} - - DATABASE__CONFIGURATIONS__POSTGRES__PASSWORD=${POSTGRES_PASSWORD} - - TVDB__APIKEY=${TVDB__APIKEY} - - THEMOVIEDB__APIKEY=${THEMOVIEDB__APIKEY} - - LIBRARY_ROOT=/video + env_file: + - ./.env depends_on: - postgres volumes: @@ -58,10 +51,8 @@ services: postgres: image: "postgres" restart: on-failure - environment: - - POSTGRES_USER=${POSTGRES_USER} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - - POSTGRES_DB=${POSTGRES_DB} + env_file: + - ./.env volumes: - db:/var/lib/postgresql/data diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index e3299214..a8547b81 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -4,21 +4,13 @@ services: back: image: zoriya/kyoo_back:edge restart: on-failure - environment: - - KYOO_DATADIR=/var/lib/kyoo - - DATABASE__ENABLED=postgres - - DATABASE__CONFIGURATIONS__POSTGRES__SERVER=postgres - - DATABASE__CONFIGURATIONS__POSTGRES__USER=${POSTGRES_USER} - - DATABASE__CONFIGURATIONS__POSTGRES__PASSWORD=${POSTGRES_PASSWORD} - - DATABASE__CONFIGURATIONS__POSTGRES__DATABASE=${POSTGRES_DB} - - TVDB__APIKEY=${TVDB__APIKEY} - - THEMOVIEDB__APIKEY=${THEMOVIEDB__APIKEY} - - LIBRARY_ROOT=/video + env_file: + - ./.env depends_on: - postgres volumes: - - kyoo:/var/lib/kyoo - - ./cache:/var/lib/kyoo/cached + - kyoo:/kyoo + - ./cache:/kyoo/cached - ./video:/video front: image: zoriya/kyoo_front:edge @@ -43,10 +35,8 @@ services: postgres: image: postgres restart: on-failure - environment: - - POSTGRES_USER=${POSTGRES_USER} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - - POSTGRES_DB=${POSTGRES_DB} + env_file: + - ./.env volumes: - db:/var/lib/postgresql/data diff --git a/docker-compose.yml b/docker-compose.yml index 8122d812..2450611e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,15 +6,11 @@ services: restart: on-failure env_file: - ./.env - - KYOO_DATADIR=/var/lib/kyoo - - TVDB__APIKEY=${TVDB__APIKEY} - - THEMOVIEDB__APIKEY=${THEMOVIEDB__APIKEY} - - LIBRARY_ROOT=/video depends_on: - postgres volumes: - - kyoo:/var/lib/kyoo - - ./cache:/var/lib/kyoo/cached + - kyoo:/kyoo + - ./cache:/kyoo/cached - ./video:/video front: build: ./front