Allow file shards to signal main server directly
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
using MareSynchronos.API.Routes;
|
||||||
|
using MareSynchronos.API.SignalR;
|
||||||
|
using MareSynchronosServer.Hubs;
|
||||||
|
using MareSynchronosServer.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
|
namespace MareSynchronosServer.Controllers;
|
||||||
|
|
||||||
|
[Route(MareFiles.Main)]
|
||||||
|
public class MainController : Controller
|
||||||
|
{
|
||||||
|
private IHubContext<MareHub, IMareHub> _hubContext;
|
||||||
|
|
||||||
|
public MainController(ILogger<MainController> logger, IHubContext<MareHub, IMareHub> hubContext)
|
||||||
|
{
|
||||||
|
_hubContext = hubContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet(MareFiles.Main_SendReady)]
|
||||||
|
[Authorize(Policy = "Internal")]
|
||||||
|
public IActionResult SendReadyToClients(string uid, Guid requestId)
|
||||||
|
{
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await _hubContext.Clients.User(uid).Client_DownloadReady(requestId);
|
||||||
|
});
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ namespace MareSynchronosStaticFilesServer;
|
|||||||
public class StaticFilesServerConfiguration : MareConfigurationBase
|
public class StaticFilesServerConfiguration : MareConfigurationBase
|
||||||
{
|
{
|
||||||
public bool IsDistributionNode { get; set; } = false;
|
public bool IsDistributionNode { get; set; } = false;
|
||||||
|
public bool NotifyMainServerDirectly { get; set; } = false;
|
||||||
public Uri? MainFileServerAddress { get; set; } = null;
|
public Uri? MainFileServerAddress { get; set; } = null;
|
||||||
public Uri? DistributionFileServerAddress { get; set; } = null;
|
public Uri? DistributionFileServerAddress { get; set; } = null;
|
||||||
public bool DistributionFileServerForceHTTP2 { get; set; } = false;
|
public bool DistributionFileServerForceHTTP2 { get; set; } = false;
|
||||||
@@ -30,6 +31,8 @@ public class StaticFilesServerConfiguration : MareConfigurationBase
|
|||||||
{
|
{
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
sb.AppendLine(base.ToString());
|
sb.AppendLine(base.ToString());
|
||||||
|
sb.AppendLine($"{nameof(IsDistributionNode)} => {IsDistributionNode}");
|
||||||
|
sb.AppendLine($"{nameof(NotifyMainServerDirectly)} => {NotifyMainServerDirectly}");
|
||||||
sb.AppendLine($"{nameof(MainFileServerAddress)} => {MainFileServerAddress}");
|
sb.AppendLine($"{nameof(MainFileServerAddress)} => {MainFileServerAddress}");
|
||||||
sb.AppendLine($"{nameof(DistributionFileServerAddress)} => {DistributionFileServerAddress}");
|
sb.AppendLine($"{nameof(DistributionFileServerAddress)} => {DistributionFileServerAddress}");
|
||||||
sb.AppendLine($"{nameof(DistributionFileServerForceHTTP2)} => {DistributionFileServerForceHTTP2}");
|
sb.AppendLine($"{nameof(DistributionFileServerForceHTTP2)} => {DistributionFileServerForceHTTP2}");
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ public class ShardClientReadyMessageService : IClientReadyMessageService
|
|||||||
{
|
{
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var mainUrl = _configurationService.GetValue<Uri>(nameof(StaticFilesServerConfiguration.MainFileServerAddress));
|
var mainUrlConfigKey = _configurationService.GetValue<bool>(nameof(StaticFilesServerConfiguration.NotifyMainServerDirectly))
|
||||||
|
? nameof(StaticFilesServerConfiguration.MainServerAddress)
|
||||||
|
: nameof(StaticFilesServerConfiguration.MainFileServerAddress);
|
||||||
|
var mainUrl = _configurationService.GetValue<Uri>(mainUrlConfigKey);
|
||||||
var path = MareFiles.MainSendReadyFullPath(mainUrl, uid, requestId);
|
var path = MareFiles.MainSendReadyFullPath(mainUrl, uid, requestId);
|
||||||
using HttpRequestMessage msg = new()
|
using HttpRequestMessage msg = new()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user