mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Adding strongly typed options
This commit is contained in:
parent
fcd419993a
commit
dcfb1e538c
@ -84,7 +84,7 @@ namespace Kyoo.Authentication
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Configure(IServiceCollection services, ICollection<Type> availableTypes)
|
public void Configure(IServiceCollection services, ICollection<Type> availableTypes)
|
||||||
{
|
{
|
||||||
string publicUrl = _configuration.GetValue<string>("publicUrl").TrimEnd('/');
|
string publicUrl = _configuration.GetPublicUrl();
|
||||||
|
|
||||||
if (_environment.IsDevelopment())
|
if (_environment.IsDevelopment())
|
||||||
IdentityModelEventSource.ShowPII = true;
|
IdentityModelEventSource.ShowPII = true;
|
||||||
@ -146,7 +146,7 @@ namespace Kyoo.Authentication
|
|||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.Use((ctx, next) =>
|
app.Use((ctx, next) =>
|
||||||
{
|
{
|
||||||
ctx.SetIdentityServerOrigin(_configuration.GetValue<string>("publicUrl").TrimEnd('/'));
|
ctx.SetIdentityServerOrigin(_configuration.GetPublicUrl());
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
app.UseIdentityServer();
|
app.UseIdentityServer();
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
@ -11,6 +12,25 @@ namespace Kyoo.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IConfigurationManager
|
public interface IConfigurationManager
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get the value of a setting using it's path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path of the resource (can be separated by ':' or '__')</param>
|
||||||
|
/// <exception cref="ItemNotFoundException">No setting found at the given path.</exception>
|
||||||
|
/// <returns>The value of the settings (if it's a strongly typed one, the given type is instantiated</returns>
|
||||||
|
object GetValue(string path);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the value of a setting using it's path.
|
||||||
|
/// If your don't need a strongly typed value, see <see cref="GetValue"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path of the resource (can be separated by ':' or '__')</param>
|
||||||
|
/// <typeparam name="T">A type to strongly type your option.</typeparam>
|
||||||
|
/// <exception cref="InvalidCastException">If your type is not the same as the registered type</exception>
|
||||||
|
/// <exception cref="ItemNotFoundException">No setting found at the given path.</exception>
|
||||||
|
/// <returns>The value of the settings (if it's a strongly typed one, the given type is instantiated</returns>
|
||||||
|
T GetValue<T>(string path);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Edit the value of a setting using it's path. Save it to the json file.
|
/// Edit the value of a setting using it's path. Save it to the json file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Kyoo
|
namespace Kyoo
|
||||||
@ -81,5 +82,15 @@ namespace Kyoo
|
|||||||
services.AddSingleton(confRef);
|
services.AddSingleton(confRef);
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the public URL of kyoo using the given configuration instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="configuration">The configuration instance</param>
|
||||||
|
/// <returns>The public URl of kyoo (without a slash at the end)</returns>
|
||||||
|
public static string GetPublicUrl(this IConfiguration configuration)
|
||||||
|
{
|
||||||
|
return configuration["basics:publicUrl"]?.TrimEnd('/') ?? "http://localhost:5000";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,6 @@ using Kyoo.Models;
|
|||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
|
|
||||||
namespace Kyoo.CommonApi
|
namespace Kyoo.CommonApi
|
||||||
{
|
{
|
||||||
@ -18,10 +17,10 @@ namespace Kyoo.CommonApi
|
|||||||
private readonly IRepository<T> _repository;
|
private readonly IRepository<T> _repository;
|
||||||
protected readonly string BaseURL;
|
protected readonly string BaseURL;
|
||||||
|
|
||||||
public CrudApi(IRepository<T> repository, IConfiguration configuration)
|
public CrudApi(IRepository<T> repository, string baseURL)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
BaseURL = configuration.GetValue<string>("publicUrl").TrimEnd('/');
|
BaseURL = baseURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,10 +66,6 @@ namespace Kyoo.Postgresql
|
|||||||
if (_environment.IsDevelopment())
|
if (_environment.IsDevelopment())
|
||||||
x.EnableDetailedErrors().EnableSensitiveDataLogging();
|
x.EnableDetailedErrors().EnableSensitiveDataLogging();
|
||||||
});
|
});
|
||||||
// services.AddScoped<DatabaseContext>(_ => new PostgresContext(
|
|
||||||
// _configuration.GetDatabaseConnection("postgres"),
|
|
||||||
// _environment.IsDevelopment()));
|
|
||||||
// services.AddScoped<DbContext>(x => x.GetRequiredService<PostgresContext>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -35,6 +35,34 @@ namespace Kyoo.Controllers
|
|||||||
_references = references.ToDictionary(x => x.Path, x => x.Type, StringComparer.OrdinalIgnoreCase);
|
_references = references.ToDictionary(x => x.Path, x => x.Type, StringComparer.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public object GetValue(string path)
|
||||||
|
{
|
||||||
|
path = path.Replace("__", ":");
|
||||||
|
// TODO handle lists and dictionaries.
|
||||||
|
if (!_references.TryGetValue(path, out Type type))
|
||||||
|
throw new ItemNotFoundException($"No configuration exists for the name: {path}");
|
||||||
|
object ret = _configuration.GetValue(type, path);
|
||||||
|
if (ret != null)
|
||||||
|
return ret;
|
||||||
|
object option = Activator.CreateInstance(type);
|
||||||
|
_configuration.Bind(path, option);
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public T GetValue<T>(string path)
|
||||||
|
{
|
||||||
|
path = path.Replace("__", ":");
|
||||||
|
// TODO handle lists and dictionaries.
|
||||||
|
if (!_references.TryGetValue(path, out Type type))
|
||||||
|
throw new ItemNotFoundException($"No configuration exists for the name: {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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task EditValue(string path, object value)
|
public async Task EditValue(string path, object value)
|
||||||
{
|
{
|
||||||
|
@ -4,10 +4,11 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Controllers
|
namespace Kyoo.Controllers
|
||||||
{
|
{
|
||||||
@ -24,7 +25,7 @@ namespace Kyoo.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The configuration to get the plugin's directory.
|
/// The configuration to get the plugin's directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IConfiguration _config;
|
private readonly IOptionsMonitor<BasicOptions> _options;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The logger used by this class.
|
/// The logger used by this class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -39,14 +40,14 @@ namespace Kyoo.Controllers
|
|||||||
/// Create a new <see cref="PluginManager"/> instance.
|
/// Create a new <see cref="PluginManager"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="provider">A service container to allow initialization of plugins</param>
|
/// <param name="provider">A service container to allow initialization of plugins</param>
|
||||||
/// <param name="config">The configuration instance, to get the plugin's directory path.</param>
|
/// <param name="options">The configuration instance, to get the plugin's directory path.</param>
|
||||||
/// <param name="logger">The logger used by this class.</param>
|
/// <param name="logger">The logger used by this class.</param>
|
||||||
public PluginManager(IServiceProvider provider,
|
public PluginManager(IServiceProvider provider,
|
||||||
IConfiguration config,
|
IOptionsMonitor<BasicOptions> options,
|
||||||
ILogger<PluginManager> logger)
|
ILogger<PluginManager> logger)
|
||||||
{
|
{
|
||||||
_provider = provider;
|
_provider = provider;
|
||||||
_config = config;
|
_options = options;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ namespace Kyoo.Controllers
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void LoadPlugins(ICollection<IPlugin> plugins)
|
public void LoadPlugins(ICollection<IPlugin> plugins)
|
||||||
{
|
{
|
||||||
string pluginFolder = _config.GetValue<string>("plugins");
|
string pluginFolder = _options.CurrentValue.PluginPath;
|
||||||
if (!Directory.Exists(pluginFolder))
|
if (!Directory.Exists(pluginFolder))
|
||||||
Directory.CreateDirectory(pluginFolder);
|
Directory.CreateDirectory(pluginFolder);
|
||||||
|
|
||||||
|
@ -7,10 +7,11 @@ using System.Threading.Tasks;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Kyoo.Models.Attributes;
|
using Kyoo.Models.Attributes;
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Kyoo.Models.Options;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Controllers
|
namespace Kyoo.Controllers
|
||||||
{
|
{
|
||||||
@ -27,7 +28,7 @@ namespace Kyoo.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The configuration instance used to get schedule information
|
/// The configuration instance used to get schedule information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IOptionsMonitor<TaskOptions> _options;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The logger instance.
|
/// The logger instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -56,15 +57,15 @@ namespace Kyoo.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tasks">The list of tasks to manage</param>
|
/// <param name="tasks">The list of tasks to manage</param>
|
||||||
/// <param name="provider">The service provider to request services for tasks</param>
|
/// <param name="provider">The service provider to request services for tasks</param>
|
||||||
/// <param name="configuration">The configuration to load schedule information.</param>
|
/// <param name="options">The configuration to load schedule information.</param>
|
||||||
/// <param name="logger">The logger.</param>
|
/// <param name="logger">The logger.</param>
|
||||||
public TaskManager(IEnumerable<ITask> tasks,
|
public TaskManager(IEnumerable<ITask> tasks,
|
||||||
IServiceProvider provider,
|
IServiceProvider provider,
|
||||||
IConfiguration configuration,
|
IOptionsMonitor<TaskOptions> options,
|
||||||
ILogger<TaskManager> logger)
|
ILogger<TaskManager> logger)
|
||||||
{
|
{
|
||||||
_provider = provider;
|
_provider = provider;
|
||||||
_configuration = configuration.GetSection("scheduledTasks");
|
_options = options;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_tasks = tasks.Select(x => (x, GetNextTaskDate(x.Slug))).ToList();
|
_tasks = tasks.Select(x => (x, GetNextTaskDate(x.Slug))).ToList();
|
||||||
|
|
||||||
@ -224,10 +225,9 @@ namespace Kyoo.Controllers
|
|||||||
/// <returns>The next date.</returns>
|
/// <returns>The next date.</returns>
|
||||||
private DateTime GetNextTaskDate(string taskSlug)
|
private DateTime GetNextTaskDate(string taskSlug)
|
||||||
{
|
{
|
||||||
TimeSpan delay = _configuration.GetValue<TimeSpan>(taskSlug);
|
if (_options.CurrentValue.Scheduled.TryGetValue(taskSlug, out TimeSpan delay))
|
||||||
if (delay == default)
|
return DateTime.Now + delay;
|
||||||
return DateTime.MaxValue;
|
return DateTime.MaxValue;
|
||||||
return DateTime.Now + delay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -1,26 +1,25 @@
|
|||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Controllers
|
namespace Kyoo.Controllers
|
||||||
{
|
{
|
||||||
public class ThumbnailsManager : IThumbnailsManager
|
public class ThumbnailsManager : IThumbnailsManager
|
||||||
{
|
{
|
||||||
private readonly IFileManager _files;
|
private readonly IFileManager _files;
|
||||||
private readonly string _peoplePath;
|
private readonly IOptionsMonitor<BasicOptions> _options;
|
||||||
private readonly string _providerPath;
|
|
||||||
|
|
||||||
public ThumbnailsManager(IConfiguration configuration, IFileManager files)
|
public ThumbnailsManager(IFileManager files, IOptionsMonitor<BasicOptions> options)
|
||||||
{
|
{
|
||||||
_files = files;
|
_files = files;
|
||||||
_peoplePath = Path.GetFullPath(configuration.GetValue<string>("peoplePath"));
|
_options = options;
|
||||||
_providerPath = Path.GetFullPath(configuration.GetValue<string>("providerPath"));
|
Directory.CreateDirectory(_options.CurrentValue.PeoplePath);
|
||||||
Directory.CreateDirectory(_peoplePath);
|
Directory.CreateDirectory(_options.CurrentValue.ProviderPath);
|
||||||
Directory.CreateDirectory(_providerPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task DownloadImage(string url, string localPath, string what)
|
private static async Task DownloadImage(string url, string localPath, string what)
|
||||||
@ -141,16 +140,18 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
if (people == null)
|
if (people == null)
|
||||||
throw new ArgumentNullException(nameof(people));
|
throw new ArgumentNullException(nameof(people));
|
||||||
string thumbPath = Path.GetFullPath(Path.Combine(_peoplePath, $"{people.Slug}.jpg"));
|
string peoplePath = _options.CurrentValue.PeoplePath;
|
||||||
return Task.FromResult(thumbPath.StartsWith(_peoplePath) ? thumbPath : null);
|
string thumbPath = Path.GetFullPath(Path.Combine(peoplePath, $"{people.Slug}.jpg"));
|
||||||
|
return Task.FromResult(thumbPath.StartsWith(peoplePath) ? thumbPath : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<string> GetProviderLogo(Provider provider)
|
public Task<string> GetProviderLogo(Provider provider)
|
||||||
{
|
{
|
||||||
if (provider == null)
|
if (provider == null)
|
||||||
throw new ArgumentNullException(nameof(provider));
|
throw new ArgumentNullException(nameof(provider));
|
||||||
string thumbPath = Path.GetFullPath(Path.Combine(_providerPath, $"{provider.Slug}.{provider.LogoExtension}"));
|
string providerPath = _options.CurrentValue.ProviderPath;
|
||||||
return Task.FromResult(thumbPath.StartsWith(_providerPath) ? thumbPath : null);
|
string thumbPath = Path.GetFullPath(Path.Combine(providerPath, $"{provider.Slug}.{provider.LogoExtension}"));
|
||||||
|
return Task.FromResult(thumbPath.StartsWith(providerPath) ? thumbPath : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@ using System.IO;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Kyoo.Models.Options;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using Stream = Kyoo.Models.Watch.Stream;
|
using Stream = Kyoo.Models.Watch.Stream;
|
||||||
|
|
||||||
// We use threads so tasks are not always awaited.
|
// We use threads so tasks are not always awaited.
|
||||||
@ -66,20 +67,18 @@ namespace Kyoo.Controllers
|
|||||||
tracks = Array.Empty<Track>();
|
tracks = Array.Empty<Track>();
|
||||||
|
|
||||||
if (ptr != IntPtr.Zero)
|
if (ptr != IntPtr.Zero)
|
||||||
free(ptr); // free_streams is not necesarry since the Marshal free the unmanaged pointers.
|
free(ptr); // free_streams is not necessary since the Marshal free the unmanaged pointers.
|
||||||
return tracks;
|
return tracks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IFileManager _files;
|
private readonly IFileManager _files;
|
||||||
private readonly string _transmuxPath;
|
private readonly IOptions<BasicOptions> _options;
|
||||||
private readonly string _transcodePath;
|
|
||||||
|
|
||||||
public Transcoder(IConfiguration config, IFileManager files)
|
public Transcoder(IFileManager files, IOptions<BasicOptions> options)
|
||||||
{
|
{
|
||||||
_files = files;
|
_files = files;
|
||||||
_transmuxPath = Path.GetFullPath(config.GetValue<string>("transmuxTempPath"));
|
_options = options;
|
||||||
_transcodePath = Path.GetFullPath(config.GetValue<string>("transcodeTempPath"));
|
|
||||||
|
|
||||||
if (TranscoderAPI.init() != Marshal.SizeOf<Stream>())
|
if (TranscoderAPI.init() != Marshal.SizeOf<Stream>())
|
||||||
throw new BadTranscoderException();
|
throw new BadTranscoderException();
|
||||||
@ -100,7 +99,7 @@ namespace Kyoo.Controllers
|
|||||||
if (!File.Exists(episode.Path))
|
if (!File.Exists(episode.Path))
|
||||||
throw new ArgumentException("Path does not exists. Can't transcode.");
|
throw new ArgumentException("Path does not exists. Can't transcode.");
|
||||||
|
|
||||||
string folder = Path.Combine(_transmuxPath, episode.Slug);
|
string folder = Path.Combine(_options.Value.TransmuxPath, episode.Slug);
|
||||||
string manifest = Path.Combine(folder, episode.Slug + ".m3u8");
|
string manifest = Path.Combine(folder, episode.Slug + ".m3u8");
|
||||||
float playableDuration = 0;
|
float playableDuration = 0;
|
||||||
bool transmuxFailed = false;
|
bool transmuxFailed = false;
|
||||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Kyoo.Tasks;
|
using Kyoo.Tasks;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
@ -90,8 +91,15 @@ namespace Kyoo
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Configure(IServiceCollection services, ICollection<Type> availableTypes)
|
public void Configure(IServiceCollection services, ICollection<Type> availableTypes)
|
||||||
{
|
{
|
||||||
string publicUrl = _configuration.GetValue<string>("publicUrl");
|
string publicUrl = _configuration.GetPublicUrl();
|
||||||
|
|
||||||
|
services.Configure<BasicOptions>(_configuration.GetSection(BasicOptions.Path));
|
||||||
|
services.AddConfiguration<BasicOptions>(BasicOptions.Path);
|
||||||
|
services.Configure<TaskOptions>(_configuration.GetSection(TaskOptions.Path));
|
||||||
|
services.AddConfiguration<TaskOptions>(TaskOptions.Path);
|
||||||
|
services.Configure<MediaOptions>(_configuration.GetSection(MediaOptions.Path));
|
||||||
|
services.AddConfiguration<MediaOptions>(MediaOptions.Path);
|
||||||
|
|
||||||
services.AddControllers()
|
services.AddControllers()
|
||||||
.AddNewtonsoftJson(x =>
|
.AddNewtonsoftJson(x =>
|
||||||
{
|
{
|
||||||
|
48
Kyoo/Models/Options/BasicOptions.cs
Normal file
48
Kyoo/Models/Options/BasicOptions.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
namespace Kyoo.Models.Options
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The typed list of basic/global options for Kyoo
|
||||||
|
/// </summary>
|
||||||
|
public class BasicOptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The path of this list of options
|
||||||
|
/// </summary>
|
||||||
|
public const string Path = "Basics";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The internal url where the server will listen
|
||||||
|
/// </summary>
|
||||||
|
public string Url { get; set; } = "http://*:5000";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The public url that will be used in items response and in authentication server host.
|
||||||
|
/// </summary>
|
||||||
|
public string PublicUrl { get; set; } = "http://localhost:5000/";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path of the plugin directory.
|
||||||
|
/// </summary>
|
||||||
|
public string PluginPath { get; set; } = "plugins/";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path of the people pictures.
|
||||||
|
/// </summary>
|
||||||
|
public string PeoplePath { get; set; } = "people/";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path of providers icons.
|
||||||
|
/// </summary>
|
||||||
|
public string ProviderPath { get; set; } = "providers/";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The temporary folder to cache transmuxed file.
|
||||||
|
/// </summary>
|
||||||
|
public string TransmuxPath { get; set; } = "cached/transmux";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The temporary folder to cache transcoded file.
|
||||||
|
/// </summary>
|
||||||
|
public string TranscodePath { get; set; } = "cached/transcode";
|
||||||
|
}
|
||||||
|
}
|
23
Kyoo/Models/Options/MediaOptions.cs
Normal file
23
Kyoo/Models/Options/MediaOptions.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace Kyoo.Models.Options
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Options for media registering.
|
||||||
|
/// </summary>
|
||||||
|
public class MediaOptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The path of this options
|
||||||
|
/// </summary>
|
||||||
|
public const string Path = "Media";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A regex for episodes
|
||||||
|
/// </summary>
|
||||||
|
public string Regex { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A regex for subtitles
|
||||||
|
/// </summary>
|
||||||
|
public string SubtitleRegex { get; set; }
|
||||||
|
}
|
||||||
|
}
|
28
Kyoo/Models/Options/TaskOptions.cs
Normal file
28
Kyoo/Models/Options/TaskOptions.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace Kyoo.Models.Options
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Options related to tasks
|
||||||
|
/// </summary>
|
||||||
|
public class TaskOptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The path of this options
|
||||||
|
/// </summary>
|
||||||
|
public const string Path = "Tasks";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of tasks that can be run concurrently.
|
||||||
|
/// </summary>
|
||||||
|
public int Parallels { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The delay of tasks that should be automatically started at fixed times.
|
||||||
|
/// </summary>
|
||||||
|
[UsedImplicitly]
|
||||||
|
public Dictionary<string, TimeSpan> Scheduled { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -83,14 +83,16 @@ namespace Kyoo
|
|||||||
/// <returns>A new web host instance</returns>
|
/// <returns>A new web host instance</returns>
|
||||||
private static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
private static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
||||||
{
|
{
|
||||||
|
IConfiguration configuration = SetupConfig(new ConfigurationBuilder(), args).Build();
|
||||||
|
|
||||||
return new WebHostBuilder()
|
return new WebHostBuilder()
|
||||||
.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
|
.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
|
||||||
.UseConfiguration(SetupConfig(new ConfigurationBuilder(), args).Build())
|
.UseConfiguration(configuration)
|
||||||
.ConfigureAppConfiguration(x => SetupConfig(x, args))
|
.ConfigureAppConfiguration(x => SetupConfig(x, args))
|
||||||
.ConfigureLogging((context, builder) =>
|
.ConfigureLogging((context, builder) =>
|
||||||
{
|
{
|
||||||
builder.AddConfiguration(context.Configuration.GetSection("logging"))
|
builder.AddConfiguration(context.Configuration.GetSection("logging"))
|
||||||
.AddSimpleConsole(x =>
|
.AddSimpleConsole(x =>
|
||||||
{
|
{
|
||||||
x.TimestampFormat = "[hh:mm:ss] ";
|
x.TimestampFormat = "[hh:mm:ss] ";
|
||||||
})
|
})
|
||||||
@ -107,6 +109,7 @@ namespace Kyoo
|
|||||||
.UseKestrel(options => { options.AddServerHeader = false; })
|
.UseKestrel(options => { options.AddServerHeader = false; })
|
||||||
.UseIIS()
|
.UseIIS()
|
||||||
.UseIISIntegration()
|
.UseIISIntegration()
|
||||||
|
.UseUrls(configuration.GetValue<string>("basics:urls"))
|
||||||
.UseStartup<Startup>();
|
.UseStartup<Startup>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ using System.IO;
|
|||||||
using Kyoo.Authentication;
|
using Kyoo.Authentication;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Postgresql;
|
using Kyoo.Postgresql;
|
||||||
using Kyoo.Tasks;
|
using Kyoo.Tasks;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
@ -12,6 +13,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo
|
namespace Kyoo
|
||||||
{
|
{
|
||||||
@ -38,7 +40,8 @@ namespace Kyoo
|
|||||||
/// <param name="loggerFactory">A logger factory used to create a logger for the plugin manager.</param>
|
/// <param name="loggerFactory">A logger factory used to create a logger for the plugin manager.</param>
|
||||||
public Startup(IServiceProvider hostProvider, IConfiguration configuration, ILoggerFactory loggerFactory, IWebHostEnvironment host)
|
public Startup(IServiceProvider hostProvider, IConfiguration configuration, ILoggerFactory loggerFactory, IWebHostEnvironment host)
|
||||||
{
|
{
|
||||||
_plugins = new PluginManager(hostProvider, configuration, loggerFactory.CreateLogger<PluginManager>());
|
IOptionsMonitor<BasicOptions> options = hostProvider.GetService<IOptionsMonitor<BasicOptions>>();
|
||||||
|
_plugins = new PluginManager(hostProvider, options, loggerFactory.CreateLogger<PluginManager>());
|
||||||
|
|
||||||
// TODO remove postgres from here and load it like a normal plugin.
|
// TODO remove postgres from here and load it like a normal plugin.
|
||||||
_plugins.LoadPlugins(new IPlugin[] {
|
_plugins.LoadPlugins(new IPlugin[] {
|
||||||
|
@ -6,8 +6,9 @@ using Kyoo.Models;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.CommonApi;
|
using Kyoo.CommonApi;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -19,8 +20,8 @@ namespace Kyoo.Api
|
|||||||
{
|
{
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
public CollectionApi(ILibraryManager libraryManager, IConfiguration configuration)
|
public CollectionApi(ILibraryManager libraryManager, IOptions<BasicOptions> options)
|
||||||
: base(libraryManager.CollectionRepository, configuration)
|
: base(libraryManager.CollectionRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -19,28 +15,18 @@ namespace Kyoo.Api
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class ConfigurationApi : Controller
|
public class ConfigurationApi : Controller
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The configuration manager used to retrieve and edit configuration values (while being type safe).
|
||||||
|
/// </summary>
|
||||||
private readonly IConfigurationManager _manager;
|
private readonly IConfigurationManager _manager;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The configuration to retrieve and edit.
|
|
||||||
/// </summary>
|
|
||||||
private readonly IConfiguration _configuration;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The strongly typed list of options
|
|
||||||
/// </summary>
|
|
||||||
private readonly Dictionary<string, Type> _references;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new <see cref="ConfigurationApi"/> using the given configuration.
|
/// Create a new <see cref="ConfigurationApi"/> using the given configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="configuration">The configuration to use.</param>
|
/// <param name="manager">The configuration manager used to retrieve and edit configuration values</param>
|
||||||
/// <param name="references">The strongly typed option list.</param>
|
public ConfigurationApi(IConfigurationManager manager)
|
||||||
public ConfigurationApi(IConfigurationManager manager, IConfiguration configuration, IEnumerable<ConfigurationReference> references)
|
|
||||||
{
|
{
|
||||||
_manager = manager;
|
_manager = manager;
|
||||||
_configuration = configuration;
|
|
||||||
_references = references.ToDictionary(x => x.Path, x => x.Type, StringComparer.OrdinalIgnoreCase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -54,16 +40,14 @@ namespace Kyoo.Api
|
|||||||
[Permission(nameof(ConfigurationApi), Kind.Admin)]
|
[Permission(nameof(ConfigurationApi), Kind.Admin)]
|
||||||
public ActionResult<object> GetConfiguration(string slug)
|
public ActionResult<object> GetConfiguration(string slug)
|
||||||
{
|
{
|
||||||
slug = slug.Replace("__", ":");
|
try
|
||||||
// TODO handle lists and dictionaries.
|
{
|
||||||
if (!_references.TryGetValue(slug, out Type type))
|
return _manager.GetValue(slug);
|
||||||
|
}
|
||||||
|
catch (ItemNotFoundException)
|
||||||
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
object ret = _configuration.GetValue(type, slug);
|
}
|
||||||
if (ret != null)
|
|
||||||
return ret;
|
|
||||||
object option = Activator.CreateInstance(type);
|
|
||||||
_configuration.Bind(slug, option);
|
|
||||||
return option;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -7,8 +7,9 @@ using System.Threading.Tasks;
|
|||||||
using Kyoo.CommonApi;
|
using Kyoo.CommonApi;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -23,10 +24,10 @@ namespace Kyoo.Api
|
|||||||
private readonly IFileManager _files;
|
private readonly IFileManager _files;
|
||||||
|
|
||||||
public EpisodeApi(ILibraryManager libraryManager,
|
public EpisodeApi(ILibraryManager libraryManager,
|
||||||
IConfiguration configuration,
|
IOptions<BasicOptions> options,
|
||||||
IFileManager files,
|
IFileManager files,
|
||||||
IThumbnailsManager thumbnails)
|
IThumbnailsManager thumbnails)
|
||||||
: base(libraryManager.EpisodeRepository, configuration)
|
: base(libraryManager.EpisodeRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_files = files;
|
_files = files;
|
||||||
|
@ -5,9 +5,10 @@ using System.Threading.Tasks;
|
|||||||
using Kyoo.CommonApi;
|
using Kyoo.CommonApi;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -19,8 +20,8 @@ namespace Kyoo.Api
|
|||||||
{
|
{
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
public GenreApi(ILibraryManager libraryManager, IConfiguration config)
|
public GenreApi(ILibraryManager libraryManager, IOptions<BasicOptions> options)
|
||||||
: base(libraryManager.GenreRepository, config)
|
: base(libraryManager.GenreRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,9 @@ using Kyoo.Models;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.CommonApi;
|
using Kyoo.CommonApi;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -20,8 +21,8 @@ namespace Kyoo.Api
|
|||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly ITaskManager _taskManager;
|
private readonly ITaskManager _taskManager;
|
||||||
|
|
||||||
public LibraryApi(ILibraryManager libraryManager, ITaskManager taskManager, IConfiguration configuration)
|
public LibraryApi(ILibraryManager libraryManager, ITaskManager taskManager, IOptions<BasicOptions> options)
|
||||||
: base(libraryManager.LibraryRepository, configuration)
|
: base(libraryManager.LibraryRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_taskManager = taskManager;
|
_taskManager = taskManager;
|
||||||
|
@ -6,9 +6,10 @@ using Kyoo.CommonApi;
|
|||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -22,10 +23,10 @@ namespace Kyoo.Api
|
|||||||
private readonly string _baseURL;
|
private readonly string _baseURL;
|
||||||
|
|
||||||
|
|
||||||
public LibraryItemApi(ILibraryItemRepository libraryItems, IConfiguration configuration)
|
public LibraryItemApi(ILibraryItemRepository libraryItems, IOptions<BasicOptions> options)
|
||||||
{
|
{
|
||||||
_libraryItems = libraryItems;
|
_libraryItems = libraryItems;
|
||||||
_baseURL = configuration.GetValue<string>("publicUrl").TrimEnd('/');
|
_baseURL = options.Value.PublicUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
@ -5,9 +5,10 @@ using Kyoo.CommonApi;
|
|||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -21,10 +22,10 @@ namespace Kyoo.Api
|
|||||||
private readonly IThumbnailsManager _thumbs;
|
private readonly IThumbnailsManager _thumbs;
|
||||||
|
|
||||||
public PeopleApi(ILibraryManager libraryManager,
|
public PeopleApi(ILibraryManager libraryManager,
|
||||||
IConfiguration configuration,
|
IOptions<BasicOptions> options,
|
||||||
IFileManager files,
|
IFileManager files,
|
||||||
IThumbnailsManager thumbs)
|
IThumbnailsManager thumbs)
|
||||||
: base(libraryManager.PeopleRepository, configuration)
|
: base(libraryManager.PeopleRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_files = files;
|
_files = files;
|
||||||
|
@ -2,9 +2,10 @@ using System.Threading.Tasks;
|
|||||||
using Kyoo.CommonApi;
|
using Kyoo.CommonApi;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -19,10 +20,10 @@ namespace Kyoo.Api
|
|||||||
private readonly IFileManager _files;
|
private readonly IFileManager _files;
|
||||||
|
|
||||||
public ProviderApi(ILibraryManager libraryManager,
|
public ProviderApi(ILibraryManager libraryManager,
|
||||||
IConfiguration config,
|
IOptions<BasicOptions> options,
|
||||||
IFileManager files,
|
IFileManager files,
|
||||||
IThumbnailsManager thumbnails)
|
IThumbnailsManager thumbnails)
|
||||||
: base(libraryManager.ProviderRepository, config)
|
: base(libraryManager.ProviderRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_files = files;
|
_files = files;
|
||||||
|
@ -6,8 +6,9 @@ using Kyoo.Controllers;
|
|||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -22,10 +23,10 @@ namespace Kyoo.Api
|
|||||||
private readonly IFileManager _files;
|
private readonly IFileManager _files;
|
||||||
|
|
||||||
public SeasonApi(ILibraryManager libraryManager,
|
public SeasonApi(ILibraryManager libraryManager,
|
||||||
IConfiguration configuration,
|
IOptions<BasicOptions> options,
|
||||||
IThumbnailsManager thumbs,
|
IThumbnailsManager thumbs,
|
||||||
IFileManager files)
|
IFileManager files)
|
||||||
: base(libraryManager.SeasonRepository, configuration)
|
: base(libraryManager.SeasonRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_thumbs = thumbs;
|
_thumbs = thumbs;
|
||||||
|
@ -8,8 +8,9 @@ using System.Threading.Tasks;
|
|||||||
using Kyoo.CommonApi;
|
using Kyoo.CommonApi;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -26,8 +27,8 @@ namespace Kyoo.Api
|
|||||||
public ShowApi(ILibraryManager libraryManager,
|
public ShowApi(ILibraryManager libraryManager,
|
||||||
IFileManager files,
|
IFileManager files,
|
||||||
IThumbnailsManager thumbs,
|
IThumbnailsManager thumbs,
|
||||||
IConfiguration configuration)
|
IOptions<BasicOptions> options)
|
||||||
: base(libraryManager.ShowRepository, configuration)
|
: base(libraryManager.ShowRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_files = files;
|
_files = files;
|
||||||
|
@ -5,9 +5,10 @@ using System.Threading.Tasks;
|
|||||||
using Kyoo.CommonApi;
|
using Kyoo.CommonApi;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -19,8 +20,8 @@ namespace Kyoo.Api
|
|||||||
{
|
{
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
public StudioApi(ILibraryManager libraryManager, IConfiguration config)
|
public StudioApi(ILibraryManager libraryManager, IOptions<BasicOptions> options)
|
||||||
: base(libraryManager.StudioRepository, config)
|
: base(libraryManager.StudioRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,10 @@ using Kyoo.CommonApi;
|
|||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -18,8 +19,8 @@ namespace Kyoo.Api
|
|||||||
{
|
{
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
public TrackApi(ILibraryManager libraryManager, IConfiguration configuration)
|
public TrackApi(ILibraryManager libraryManager, IOptions<BasicOptions> options)
|
||||||
: base(libraryManager.TrackRepository, configuration)
|
: base(libraryManager.TrackRepository, options.Value.PublicUrl)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
|
using Kyoo.Models.Options;
|
||||||
using Kyoo.Models.Permissions;
|
using Kyoo.Models.Permissions;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.Api
|
namespace Kyoo.Api
|
||||||
{
|
{
|
||||||
@ -16,20 +17,18 @@ namespace Kyoo.Api
|
|||||||
{
|
{
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly ITranscoder _transcoder;
|
private readonly ITranscoder _transcoder;
|
||||||
|
private readonly IOptions<BasicOptions> _options;
|
||||||
private readonly IFileManager _files;
|
private readonly IFileManager _files;
|
||||||
private readonly string _transmuxPath;
|
|
||||||
private readonly string _transcodePath;
|
|
||||||
|
|
||||||
public VideoApi(ILibraryManager libraryManager,
|
public VideoApi(ILibraryManager libraryManager,
|
||||||
ITranscoder transcoder,
|
ITranscoder transcoder,
|
||||||
IConfiguration config,
|
IOptions<BasicOptions> options,
|
||||||
IFileManager files)
|
IFileManager files)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_transcoder = transcoder;
|
_transcoder = transcoder;
|
||||||
|
_options = options;
|
||||||
_files = files;
|
_files = files;
|
||||||
_transmuxPath = config.GetValue<string>("transmuxTempPath");
|
|
||||||
_transcodePath = config.GetValue<string>("transcodeTempPath");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnActionExecuted(ActionExecutedContext ctx)
|
public override void OnActionExecuted(ActionExecutedContext ctx)
|
||||||
@ -101,7 +100,7 @@ namespace Kyoo.Api
|
|||||||
[Permission("video", Kind.Read)]
|
[Permission("video", Kind.Read)]
|
||||||
public IActionResult GetTransmuxedChunk(string episodeLink, string chunk)
|
public IActionResult GetTransmuxedChunk(string episodeLink, string chunk)
|
||||||
{
|
{
|
||||||
string path = Path.GetFullPath(Path.Combine(_transmuxPath, episodeLink));
|
string path = Path.GetFullPath(Path.Combine(_options.Value.TransmuxPath, episodeLink));
|
||||||
path = Path.Combine(path, "segments", chunk);
|
path = Path.Combine(path, "segments", chunk);
|
||||||
return PhysicalFile(path, "video/MP2T");
|
return PhysicalFile(path, "video/MP2T");
|
||||||
}
|
}
|
||||||
@ -110,7 +109,7 @@ namespace Kyoo.Api
|
|||||||
[Permission("video", Kind.Read)]
|
[Permission("video", Kind.Read)]
|
||||||
public IActionResult GetTranscodedChunk(string episodeLink, string chunk)
|
public IActionResult GetTranscodedChunk(string episodeLink, string chunk)
|
||||||
{
|
{
|
||||||
string path = Path.GetFullPath(Path.Combine(_transcodePath, episodeLink));
|
string path = Path.GetFullPath(Path.Combine(_options.Value.TranscodePath, episodeLink));
|
||||||
path = Path.Combine(path, "segments", chunk);
|
path = Path.Combine(path, "segments", chunk);
|
||||||
return PhysicalFile(path, "video/MP2T");
|
return PhysicalFile(path, "video/MP2T");
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
{
|
{
|
||||||
"server.urls": "http://*:5000",
|
"basics": {
|
||||||
"publicUrl": "http://localhost:5000/",
|
"url": "http://*:5000",
|
||||||
|
"publicUrl": "http://localhost:5000/",
|
||||||
|
"pluginsPath": "plugins/",
|
||||||
|
"peoplePath": "people/",
|
||||||
|
"providerPath": "providers/",
|
||||||
|
"transmuxPath": "cached/transmux",
|
||||||
|
"transcodePath": "cached/transcode"
|
||||||
|
},
|
||||||
|
|
||||||
"database": {
|
"database": {
|
||||||
"postgres": {
|
"postgres": {
|
||||||
"server": "127.0.0.1",
|
"server": "127.0.0.1",
|
||||||
@ -24,6 +31,18 @@
|
|||||||
"Kyoo": "Trace"
|
"Kyoo": "Trace"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"tasks": {
|
||||||
|
"parallels": "1",
|
||||||
|
"scheduled": {
|
||||||
|
"scan": "24:00:00"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"media": {
|
||||||
|
"regex": "(?:\\/(?<Collection>.*?))?\\/(?<Show>.*?)(?: \\(\\d+\\))?\\/\\k<Show>(?: \\(\\d+\\))?(?:(?: S(?<Season>\\d+)E(?<Episode>\\d+))| (?<Absolute>\\d+))?.*$",
|
||||||
|
"subtitleRegex": "^(?<Episode>.*)\\.(?<Language>\\w{1,3})\\.(?<Default>default\\.)?(?<Forced>forced\\.)?.*$"
|
||||||
|
},
|
||||||
|
|
||||||
"authentication": {
|
"authentication": {
|
||||||
"certificate": {
|
"certificate": {
|
||||||
@ -37,20 +56,5 @@
|
|||||||
},
|
},
|
||||||
"profilePicturePath": "users/",
|
"profilePicturePath": "users/",
|
||||||
"clients": []
|
"clients": []
|
||||||
},
|
}
|
||||||
|
|
||||||
|
|
||||||
"parallelTasks": "1",
|
|
||||||
|
|
||||||
"scheduledTasks": {
|
|
||||||
"scan": "24:00:00"
|
|
||||||
},
|
|
||||||
|
|
||||||
"transmuxTempPath": "cached/kyoo/transmux",
|
|
||||||
"transcodeTempPath": "cached/kyoo/transcode",
|
|
||||||
"peoplePath": "people",
|
|
||||||
"providerPath": "providers",
|
|
||||||
"plugins": "plugins/",
|
|
||||||
"regex": "(?:\\/(?<Collection>.*?))?\\/(?<Show>.*?)(?: \\(\\d+\\))?\\/\\k<Show>(?: \\(\\d+\\))?(?:(?: S(?<Season>\\d+)E(?<Episode>\\d+))| (?<Absolute>\\d+))?.*$",
|
|
||||||
"subtitleRegex": "^(?<Episode>.*)\\.(?<Language>\\w{1,3})\\.(?<Default>default\\.)?(?<Forced>forced\\.)?.*$"
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user