mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Implements directory structure seed service
This commit is contained in:
1 parent
6fc47b1a3c
commit
ef051d8c77
5 files changed
+97
-2
No files matched your search
@@ -1,9 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.DependencyInjection;
|
||||
using Lumina.DataAccess.Common.DependencyInjection;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.Common.DependencyInjection;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Infrastructure.Common.DependencyInjection;
|
||||
using Lumina.Presentation.Api.Common.DependencyInjection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@@ -92,7 +94,7 @@ public class Program
|
||||
|
||||
app.UseCors("AllowAll");
|
||||
|
||||
//app.UseExceptionHandler("/error"); // uses a middleware which re-executes the request to the error path
|
||||
//app.UseExceptionHandler("/error"); // uses a middleware which re-executes the request to the error path
|
||||
|
||||
//app.UseHttpsRedirection();
|
||||
|
||||
@@ -120,12 +122,23 @@ public class Program
|
||||
.WithDotNetFlag(true);
|
||||
});
|
||||
|
||||
// create a directory relative to the application's startup directory, and use it to store static files that are served at the /media route on the API
|
||||
string mediaRootDirectoryPathSetting = app.Configuration.GetValue<string>("MediaSettings:RootDirectory") ?? string.Empty;
|
||||
string mediaRootPath = Path.Combine(AppContext.BaseDirectory, mediaRootDirectoryPathSetting);
|
||||
|
||||
if (!Directory.Exists(mediaRootPath))
|
||||
Directory.CreateDirectory(mediaRootPath);
|
||||
|
||||
// ensure the default file system structure is present
|
||||
using (IServiceScope scope = app.Services.CreateScope())
|
||||
{
|
||||
IServiceProvider services = scope.ServiceProvider;
|
||||
IFileSystemStructureSeedService context = services.GetRequiredService<IFileSystemStructureSeedService>();
|
||||
ErrorOr<Created> setDefaultDirectoriesResult = context.SetDefaultDirectories(mediaRootPath);
|
||||
if (setDefaultDirectoriesResult.IsError)
|
||||
throw new InvalidOperationException("Could not create default file system directories structure: " + setDefaultDirectoriesResult.FirstError.Description);
|
||||
}
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(mediaRootPath),
|
||||
|
||||
Reference in new issue
Block a user