diff options
| author | ivar <i@oiee.no> | 2024-03-19 01:02:22 +0100 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2024-03-19 01:02:22 +0100 |
| commit | 5f604b3052dab1d51dc130df2470bf330b283ec6 (patch) | |
| tree | ae00e1fe4542850467555b4e3af41964ba8d878b /code/api/Program.cs | |
| parent | 63cf177e8cf22e349534664d59a6926f8b36863d (diff) | |
| download | storage-5f604b3052dab1d51dc130df2470bf330b283ec6.tar.xz storage-5f604b3052dab1d51dc130df2470bf330b283ec6.zip | |
Max lenghts on db schema
Use latest temporal from cdn
Implement majority of translation functionality
Major refinements/bugs
Diffstat (limited to 'code/api/Program.cs')
| -rw-r--r-- | code/api/Program.cs | 77 |
1 files changed, 45 insertions, 32 deletions
diff --git a/code/api/Program.cs b/code/api/Program.cs index f6c0fae..f093a45 100644 --- a/code/api/Program.cs +++ b/code/api/Program.cs @@ -1,51 +1,64 @@ global using Microsoft.AspNetCore.Mvc; -global using I2R.Storage.Api.Services.System; -global using IOL.Helpers; -global using I2R.Storage.Api.Services.Admin; -global using Microsoft.AspNetCore.Mvc.RazorPages; -global using Microsoft.EntityFrameworkCore; -global using I2R.Storage.Api.Database; -global using I2R.Storage.Api.Utilities; -global using I2R.Storage.Api.Database.Models; -global using I2R.Storage.Api.Resources; -global using I2R.Storage.Api.Enums; global using Microsoft.Extensions.Localization; -global using I2R.Storage.Api.Statics; global using Microsoft.AspNetCore.Authorization; +global using Microsoft.AspNetCore.Mvc.RazorPages; +global using Microsoft.EntityFrameworkCore; global using System.Security.Claims; -global using I2R.Storage.Api.Models; +global using System.Text.Json; +global using System.ComponentModel.DataAnnotations; global using MR.AspNetCore.Pagination; global using MR.EntityFrameworkCore.KeysetPagination; -global using System.Text.Json; -using I2R.Storage.Api.Services.System; +global using IOL.Helpers; +global using Quality.Storage.Api.Database; +global using Quality.Storage.Api.Database.Models; +global using Quality.Storage.Api.Enums; +global using Quality.Storage.Api.Models; +global using Quality.Storage.Api.Statics; +global using Quality.Storage.Api.Services.Admin; +global using Quality.Storage.Api.Services.System; +global using Quality.Storage.Api.Utilities; +global using Quality.Storage.Api.Resources; +using System.Globalization; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Localization; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; +using Quality.Storage.Api.Utilities; var builder = WebApplication.CreateBuilder(args); builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) - .AddCookie(o => { - o.Cookie.Name = "storage_session"; - o.Cookie.HttpOnly = true; - o.SlidingExpiration = true; - o.Events.OnRedirectToAccessDenied = - o.Events.OnRedirectToLogin = c => { - c.Response.StatusCode = StatusCodes.Status401Unauthorized; - return Task.FromResult<object>(null); - }; - }); + .AddCookie(o => { + o.Cookie.Name = "storage_session"; + o.Cookie.HttpOnly = true; + o.SlidingExpiration = true; + o.Events.OnRedirectToAccessDenied = + o.Events.OnRedirectToLogin = c => { + c.Response.StatusCode = StatusCodes.Status401Unauthorized; + return Task.FromResult<object>(null); + }; + }); builder.Services.AddLocalization(); -builder.Services.AddRequestLocalization(o => { o.DefaultRequestCulture = new RequestCulture("en"); }); +builder.Services.AddRequestLocalization(o => { + o.DefaultRequestCulture = new RequestCulture("en"); + var cultures = new CultureInfo[] { + new("en"), + new("no") + }; + o.SupportedCultures = cultures; + o.SupportedUICultures = cultures; +}); builder.Services.AddScoped<UserService>(); builder.Services.AddScoped<StorageService>(); builder.Services.AddScoped<ShareService>(); builder.Services.AddScoped<DefaultResourceService>(); builder.Services.AddDbContext<AppDatabase>(o => { - o.UseNpgsql(builder.Configuration.GetAppDbConnectionString(), b => { - b.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery); - b.EnableRetryOnFailure(3); - }); - o.UseSnakeCaseNamingConvention(); + o.UseNpgsql(builder.Configuration.GetAppDbConnectionString(), + b => { + b.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery); + b.EnableRetryOnFailure(3); + }); + o.UseSnakeCaseNamingConvention(); }); builder.Services.AddPagination(); builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); @@ -55,9 +68,9 @@ var app = builder.Build(); app.UseStaticFiles(); app.UseStatusCodePages(); -app.UseRequestLocalization(); app.UseAuthentication(); app.UseAuthorization(); app.MapRazorPages(); app.MapControllers(); -app.Run();
\ No newline at end of file +app.UseRequestLocalization(app.Services.GetService<IOptions<RequestLocalizationOptions>>().Value); +app.Run(); |
