using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using SixLabors.ImageSharp.Processing; using System.IO; namespace zero.Media; internal class ZeroMediaModule : ZeroModule { public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddSingleton(svc => { IOptions options = svc.GetRequiredService>(); IWebHostEnvironment env = svc.GetRequiredService(); return new(Path.Combine(env.WebRootPath, options.Value.FolderPath), options.Value.PublicPathPrefix + options.Value.FolderPath.EnsureStartsWith('/')); }); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddOptions().Bind(configuration.GetSection("Zero:Media")).Configure(opts => { 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 } } }; }); services.Configure(opts => { RavenOptions raven = opts.For(); raven.Indexes.Add(); raven.Indexes.Add(); raven.Indexes.Add(); }); //services.Configure(opts => //{ // // TODO should we use MediaType here? // opts.Provide("zero.media", "@media.name", icon: "fth-image"); //}); } }