Files
mixtape/zero.Core/Media/ZeroMediaModule.cs
T

51 lines
1.9 KiB
C#
Raw Normal View History

2021-11-25 15:38:36 +01:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using SixLabors.ImageSharp.Processing;
using System.IO;
2021-11-24 14:37:32 +01:00
namespace zero.Media;
2022-01-06 18:10:58 +01:00
internal class ZeroMediaModule : ZeroModule
2021-11-24 14:37:32 +01:00
{
2021-11-30 14:32:10 +01:00
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
2021-11-24 14:37:32 +01:00
{
2021-11-25 15:38:36 +01:00
services.AddSingleton<IMediaFileSystem, MediaFileSystem>(svc =>
{
IOptions<MediaOptions> options = svc.GetRequiredService<IOptions<MediaOptions>>();
IWebHostEnvironment env = svc.GetRequiredService<IWebHostEnvironment>();
2021-12-16 13:55:09 +01:00
return new(Path.Combine(env.WebRootPath, options.Value.FolderPath), options.Value.PublicPathPrefix + options.Value.FolderPath.EnsureStartsWith('/'));
2021-11-25 15:38:36 +01:00
});
services.AddScoped<IMediaStore, MediaStore>();
services.AddScoped<IMediaCreator, MediaCreator>();
services.AddScoped<IMediaManagement, MediaManagement>();
2021-11-30 14:32:10 +01:00
services.AddOptions<MediaOptions>().Bind(configuration.GetSection("Zero:Media")).Configure(opts =>
2021-11-25 15:38:36 +01:00
{
opts.FolderPath = "uploads";
opts.AllowedOtherFileExtensions = new() { ".pdf" };
opts.AllowedImageFileExtensions = new() { ".jpg", ".jpeg", ".png", ".bmp", ".webp", ".gif" };
opts.Thumbnails = new()
{
{ "thumb", new ResizeOptions() { Size = new(100, 100), Mode = ResizeMode.Max } },
{ "preview", new ResizeOptions() { Size = new(210, 210), Mode = ResizeMode.Min } }
};
});
2021-11-24 14:37:32 +01:00
services.Configure<ZeroOptions>(opts =>
{
RavenOptions raven = opts.For<RavenOptions>();
raven.Indexes.Add<Media_ByChildren>();
raven.Indexes.Add<Media_ByParent>();
2021-11-26 11:21:49 +01:00
raven.Indexes.Add<Media_ByHierarchy>();
2021-11-24 14:37:32 +01:00
});
2021-12-02 13:43:04 +01:00
//services.Configure<FlavorOptions>(opts =>
//{
// // TODO should we use MediaType here?
// opts.Provide<Media>("zero.media", "@media.name", icon: "fth-image");
//});
2021-11-24 14:37:32 +01:00
}
}