refacto site settings

This commit is contained in:
Paul Schneider 2026-09-17 22:22:18 +01:00
commit 3160eada93
33 changed files with 399 additions and 315 deletions

View file

@ -35,6 +35,7 @@ namespace Yavsc.ApiControllers
private readonly ILogger logger;
private readonly IBillingService billingService;
private readonly SiteSettings siteSettings;
public BillingController(
IAuthorizationService authorizationService,
@ -43,7 +44,8 @@ namespace Yavsc.ApiControllers
ApplicationDbContext context,
IOptions<GoogleAuthSettings> googleSettings,
IYavscMessageSender GCMSender,
IBillingService billingService
IBillingService billingService,
IOptions<SiteSettings> siteSettings
)
{
_googleSettings=googleSettings.Value;
@ -53,6 +55,7 @@ namespace Yavsc.ApiControllers
this._localizer = SR;
_GCMSender=GCMSender;
this.billingService=billingService;
this.siteSettings = siteSettings.Value;
}
[HttpGet("facture-{billingCode}-{id}.pdf"), Authorize]
@ -65,7 +68,7 @@ namespace Yavsc.ApiControllers
return new ChallengeResult();
}
var fi = bill.GetBillInfo(billingService);
var fi = bill.GetBillInfo(billingService, siteSettings);
if (!fi.Exists) return Ok(new { Error = "Not generated" });
return File(fi.OpenRead(), "application/x-pdf", fi.Name);
@ -229,7 +232,7 @@ namespace Yavsc.ApiControllers
}
if (Request.Form.Files.Count!=1)
return new BadRequestResult();
await User.ReceiveProSignatureAsync(billingCode,id,Request.Form.Files[0],"pro");
await User.ReceiveProSignatureAsync(billingCode,id,Request.Form.Files[0],"pro", siteSettings);
estimate.ProviderValidationDate = DateTime.UtcNow;
dbContext.SaveChanges(User.GetUserId());
// Notify the client
@ -273,7 +276,7 @@ namespace Yavsc.ApiControllers
}
var filename = AbstractFileSystemHelpers.SignFileNameFormat("pro", billingCode, id);
FileInfo fi = new FileInfo(Path.Combine(AbstractFileSystemHelpers.UserBillsDirName, filename));
FileInfo fi = new FileInfo(Path.Combine(siteSettings.Bills, filename));
if (!fi.Exists) return NotFound(new { Error = "Professional signature not found" });
return File(fi.OpenRead(), "application/x-pdf", filename); ;
}
@ -310,7 +313,7 @@ namespace Yavsc.ApiControllers
}
if (Request.Form.Files.Count!=1)
return new BadRequestResult();
await User.ReceiveProSignatureAsync(billingCode,id,Request.Form.Files[0],"cli");
await User.ReceiveProSignatureAsync(billingCode,id,Request.Form.Files[0],"cli", siteSettings);
estimate.ClientValidationDate = DateTime.UtcNow;
dbContext.SaveChanges(User.GetUserId());
return Ok (new { ClientValidationDate = estimate.ClientValidationDate });
@ -327,9 +330,9 @@ namespace Yavsc.ApiControllers
}
var filename = AbstractFileSystemHelpers.SignFileNameFormat("pro", billingCode, id);
FileInfo fi = new FileInfo(Path.Combine(AbstractFileSystemHelpers.UserBillsDirName, filename));
FileInfo fi = new FileInfo(Path.Combine(siteSettings.Bills, filename));
if (!fi.Exists) return NotFound(new { Error = "Professional signature not found" });
return File(fi.OpenRead(), "application/x-pdf", filename); ;
return File(fi.OpenRead(), "application/x-pdf", filename);
}
/// <summary>
@ -405,7 +408,8 @@ namespace Yavsc.ApiControllers
FileReceivedInfo fi;
try
{
fi = await User.ReceiveEstimateSignatureAsync(id, type, payload, token);
fi = await User.ReceiveEstimateSignatureAsync(id, type, payload,
siteSettings, token);
}
catch (Exception ex)
{

View file

@ -2,13 +2,13 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Http;
using ImageMagick;
using Yavsc.Models;
using Yavsc.Api.Helpers;
using Yavsc.Server.Helpers;
using System.Diagnostics;
using Microsoft.Extensions.Options;
namespace Yavsc.WebApi.Controllers
{
@ -28,13 +28,16 @@ namespace Yavsc.WebApi.Controllers
];
readonly ApplicationDbContext _dbContext;
private readonly SiteSettings siteSettings;
private readonly ILogger _logger;
public ApiAccountController(
ILoggerFactory loggerFactory, ApplicationDbContext dbContext)
ILoggerFactory loggerFactory, ApplicationDbContext dbContext,
IOptions<SiteSettings> siteSettings)
{
_logger = loggerFactory.CreateLogger(nameof(ApiAccountController));
_dbContext = dbContext;
this.siteSettings = siteSettings.Value;
}
[HttpGet("me")]
@ -146,7 +149,7 @@ namespace Yavsc.WebApi.Controllers
try
{
var info = user.ReceiveAvatar(avatarFile);
var info = user.ReceiveAvatar(avatarFile, siteSettings);
await _dbContext.SaveChangesAsync();
return Ok(new
{

View file

@ -21,7 +21,6 @@ internal class Program
var builder = WebApplication.CreateBuilder(args);
builder.AddConfiguration("api");
Config.SiteSetup = builder.Configuration.GetSection("Site").Get<SiteSettings>() ?? new SiteSettings();
var services = builder.Services;

View file

@ -5,7 +5,9 @@
"CorsAllowedOrigins": [
"https://yavsc.pschneider.fr",
"https://blogs.pschneider.fr"
]
],
"Bills": "bills",
"TempDir": "temp"
},
"Logging": {
"LogLevel": {