34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
|
|
using FileSignatures;
|
|
using FileSignatures.Formats;
|
|
using StopShopping.FileApi.Services.Implementions;
|
|
|
|
namespace StopShopping.FileApi.Services;
|
|
|
|
public static class Extensions
|
|
{
|
|
public static IServiceCollection AddServices(this IServiceCollection services, IConfiguration appOptions)
|
|
{
|
|
services.Configure<AppOptions>(appOptions);
|
|
services.AddValidation();
|
|
|
|
var imageFormats = FileFormatLocator.GetFormats().OfType<Image>();
|
|
var imageInspector = new FileFormatInspector(imageFormats);
|
|
services.AddSingleton<IFileFormatInspector>(imageInspector);
|
|
|
|
services.AddScoped<IFileService, FileService>();
|
|
|
|
return services;
|
|
}
|
|
|
|
public static string GetTargetDirectory(this UploadScences uploadScences)
|
|
{
|
|
return uploadScences switch
|
|
{
|
|
UploadScences.Avatar => "avatar",
|
|
UploadScences.Product => "product",
|
|
UploadScences.Category => "category",
|
|
_ => throw new ArgumentOutOfRangeException(nameof(uploadScences))
|
|
};
|
|
}
|
|
} |