Trying to fix boardcast to upstream

This commit is contained in:
Creeper Lv
2026-06-01 18:58:36 +10:00
parent 9decde570f
commit 2920a67a61
3 changed files with 46 additions and 26 deletions
+10 -6
View File
@@ -18,7 +18,7 @@ public static class AuthEndpoints
{
var group = routes.MapGroup("/api/auth");
group.MapPost("/register", async (RegisterRequest req, HttpContext context, ServerDbContext db, PeerCache peerCache, RsaKeyManager rsaKeyManager, IConfiguration configuration, HttpClient httpClient) =>
group.MapPost("/register", async (RegisterRequest req, HttpContext context, ServerDbContext db, PeerCache peerCache, RsaKeyManager rsaKeyManager, IConfiguration configuration, HttpClient httpClient, IServiceProvider serviceProvider) =>
{
if (string.IsNullOrWhiteSpace(req.Username) || string.IsNullOrWhiteSpace(req.Password) || string.IsNullOrWhiteSpace(req.EncryptedKey))
{
@@ -45,9 +45,11 @@ public static class AuthEndpoints
{
try
{
using var scope = context.RequestServices.CreateScope();
using var scope = serviceProvider.CreateScope();
var scopeDb = scope.ServiceProvider.GetRequiredService<ServerDbContext>();
await SyncEndpoints.BroadcastUserChangeAsync(user.Username, scopeDb, peerCache, rsaKeyManager, configuration, httpClient);
var scopeRsa = scope.ServiceProvider.GetRequiredService<RsaKeyManager>();
var scopeConfig = scope.ServiceProvider.GetRequiredService<IConfiguration>();
await SyncEndpoints.BroadcastUserChangeAsync(user.Username, scopeDb, peerCache, scopeRsa, scopeConfig, httpClient);
}
catch (Exception ex)
{
@@ -58,7 +60,7 @@ public static class AuthEndpoints
return Results.Ok(new { message = "Registration successful." });
});
group.MapPost("/change-password", async (ChangePasswordRequest req, HttpContext context, ServerDbContext db, CertificateManager certManager, PeerCache peerCache, RsaKeyManager rsaKeyManager, IConfiguration configuration, HttpClient httpClient) =>
group.MapPost("/change-password", async (ChangePasswordRequest req, HttpContext context, ServerDbContext db, CertificateManager certManager, PeerCache peerCache, RsaKeyManager rsaKeyManager, IConfiguration configuration, HttpClient httpClient, IServiceProvider serviceProvider) =>
{
var username = AuthHelper.GetAuthenticatedUser(context, certManager);
if (string.IsNullOrEmpty(username)) return Results.Unauthorized();
@@ -88,9 +90,11 @@ public static class AuthEndpoints
{
try
{
using var scope = context.RequestServices.CreateScope();
using var scope = serviceProvider.CreateScope();
var scopeDb = scope.ServiceProvider.GetRequiredService<ServerDbContext>();
await SyncEndpoints.BroadcastUserChangeAsync(user.Username, scopeDb, peerCache, rsaKeyManager, configuration, httpClient);
var scopeRsa = scope.ServiceProvider.GetRequiredService<RsaKeyManager>();
var scopeConfig = scope.ServiceProvider.GetRequiredService<IConfiguration>();
await SyncEndpoints.BroadcastUserChangeAsync(user.Username, scopeDb, peerCache, scopeRsa, scopeConfig, httpClient);
}
catch (Exception ex)
{