mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 23:01:10 +00:00
Merge pull request #34 from BinaryAlley/feature/add-media-items-location-options
Adds media items location options
This commit is contained in:
11 files changed
+94
-27
No files matched your search
@@ -42,6 +42,13 @@ public static class SharedConfiguration
|
||||
.Bind(configuration.GetRequiredSection(DatabaseSettingsModel.SECTION_NAME))
|
||||
.ValidateFluently()
|
||||
.ValidateOnStart();
|
||||
|
||||
|
||||
services.AddOptions<MediaSettingsModel>()
|
||||
.Bind(configuration.GetRequiredSection(MediaSettingsModel.SECTION_NAME))
|
||||
.ValidateFluently()
|
||||
.ValidateOnStart();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,5 +13,6 @@ public static partial class Errors
|
||||
{
|
||||
public static Error ApplicationThemeCannotBeEmpty => Error.Validation(description: nameof(ApplicationThemeCannotBeEmpty));
|
||||
public static Error DatabaseConnectionStringCannotBeEmpty => Error.Validation(description: nameof(DatabaseConnectionStringCannotBeEmpty));
|
||||
public static Error MediaRootDirectoryCannotBeEmpty => Error.Validation(description: nameof(MediaRootDirectoryCannotBeEmpty));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Common.Models.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Model for deserializing media settings.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{SECTION_NAME}")]
|
||||
public class MediaSettingsModel
|
||||
{
|
||||
public const string SECTION_NAME = "MediaSettings";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the root directory where media files are stored.
|
||||
/// </summary>
|
||||
public required string RootDirectory { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Infrastructure.Common.Models.Configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Common.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for the MediaSettings application configuration settings section.
|
||||
/// </summary>
|
||||
public class MediaSettingsModelValidator : AbstractValidator<MediaSettingsModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaSettingsModelValidator"/> class.
|
||||
/// </summary>
|
||||
public MediaSettingsModelValidator()
|
||||
{
|
||||
RuleFor(x => x.RootDirectory).NotEmpty().WithMessage(Errors.Errors.Configuration.MediaRootDirectoryCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
<None Update="appsettings.shared.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.shared.Development.json">
|
||||
<None Update="appsettings.shared.development.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<DependentUpon>appsettings.shared.json</DependentUpon>
|
||||
</None>
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
{
|
||||
"MediaSettings": {
|
||||
"RootDirectory": "wwwroot/media"
|
||||
},
|
||||
"CommonSettings": {
|
||||
"Theme": "LuminaDark"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=localhost;Database=Lumina;User Id=sa;Password=Password123;"
|
||||
"DefaultConnection": "Server=<host>;Database=<database>;User Id=<user>;Password=<password>;"
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
@@ -18,4 +21,4 @@
|
||||
"WithThreadId"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -30,4 +30,4 @@ internal static class PresentationApiLayerConfiguration
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -20,7 +20,7 @@ public static class PresentationApiLayerServices
|
||||
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
|
||||
public static IServiceCollection AddPresentationApiLayerServices(this IServiceCollection services)
|
||||
{
|
||||
|
||||
|
||||
services.Configure<JsonOptions>(jsonOptions =>
|
||||
{
|
||||
jsonOptions.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||||
|
||||
@@ -36,9 +36,9 @@
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.Development.json">
|
||||
<None Update="appsettings.development.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<DependentUpon>appsettings.shared.json</DependentUpon>
|
||||
<DependentUpon>appsettings.json</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ using Lumina.Domain.Common.DependencyInjection;
|
||||
using Lumina.Infrastructure.Common.DependencyInjection;
|
||||
using Lumina.Presentation.Api.Common.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
@@ -54,6 +58,18 @@ public class Program
|
||||
});
|
||||
app.UseSwaggerGen();
|
||||
|
||||
string mediaRootDirectoryPathSetting = app.Configuration.GetValue<string>("MediaSettings:RootDirectory") ?? string.Empty;
|
||||
string mediaRootPath = Path.Combine(AppContext.BaseDirectory, mediaRootDirectoryPathSetting);
|
||||
|
||||
if (!Directory.Exists(mediaRootPath))
|
||||
Directory.CreateDirectory(mediaRootPath);
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(mediaRootPath),
|
||||
RequestPath = "/media"
|
||||
});
|
||||
|
||||
await app.RunAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Debug"
|
||||
},
|
||||
{
|
||||
"Name": "Console"
|
||||
},
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/lumina_api_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"Serilog": {
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Debug"
|
||||
},
|
||||
{
|
||||
"Name": "Console"
|
||||
},
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/lumina_api_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in new issue
Block a user