james URL configuration refactoring

This commit is contained in:
EugeneTes
2026-01-20 11:41:01 +01:00
parent 7cd2c75d14
commit f3dc04f8ae
5 changed files with 12 additions and 7 deletions

View File

@@ -61,12 +61,14 @@ public class HeartbeatBackgroundTask
{ {
try try
{ {
var url = _configuration.HeartbeatApiUrl; var url = _configuration.ApiUrl != null
var apiKey = _configuration.PrinterServerKey; ? $"{_configuration.ApiUrl.TrimEnd('/')}/api/printerServer/heartbeat"
: null;
var apiKey = _configuration.ApiKey;
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(apiKey)) if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(apiKey))
{ {
_logger.LogWarning("Heartbeat not configured (missing HeartbeatApiUrl or PrinterServerKey)"); _logger.LogWarning("Heartbeat not configured (missing ApiUrl or ApiKey)");
return; return;
} }

View File

@@ -2,5 +2,6 @@
"GroupId": "63e37295bd6f26dbd36164c0", "GroupId": "63e37295bd6f26dbd36164c0",
"RestaurantId": "63e37295bd6f26dbd36164c0", "RestaurantId": "63e37295bd6f26dbd36164c0",
"ApiKey": "Pd8X/VtXLWgl5Djy4ksjdHC3xboeoh5Jig3Qo4277GQ=", "ApiKey": "Pd8X/VtXLWgl5Djy4ksjdHC3xboeoh5Jig3Qo4277GQ=",
"ApiUrl": "https://api.dev.gastrojames.ch",
"PrinterConfigurations": {} "PrinterConfigurations": {}
} }

View File

@@ -7,8 +7,8 @@ public class EpsonPrintServiceConfiguration: IPrinterConfigurationSource, IAssig
public string GroupId { get; set; } public string GroupId { get; set; }
public string RestaurantId { get; set; } public string RestaurantId { get; set; }
public string ApiKey { get; set; } public string ApiKey { get; set; }
public string? HeartbeatApiUrl { get; set; } public string? ApiUrl { get; set; }
public string? PrinterServerKey { get; set; }
public Dictionary<string, PrinterConfiguration> PrinterConfigurations { get; set; } public Dictionary<string, PrinterConfiguration> PrinterConfigurations { get; set; }
public PrinterConfiguration GetConfiguration(string printerAddress) public PrinterConfiguration GetConfiguration(string printerAddress)

View File

@@ -31,7 +31,8 @@ public class JamesDiscoveredPrintersReceiver: IDiscoveredPrintersReceiver
}).ToList() }).ToList()
}; };
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, "https://api.dev.gastrojames.ch/api/printerServer/discovered-printers"); var url = $"{_configuration.ApiUrl?.TrimEnd('/')}/api/printerServer/discovered-printers";
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, url);
requestMessage.Headers.Add("X-Printer-Server-Key", apiKey); requestMessage.Headers.Add("X-Printer-Server-Key", apiKey);
requestMessage.Content = JsonContent.Create(request); requestMessage.Content = JsonContent.Create(request);

View File

@@ -19,8 +19,9 @@ public class SignalRPrintJobSource: IPrintJobSource
_groupConfiguration = groupConfiguration; _groupConfiguration = groupConfiguration;
_logger = logger; _logger = logger;
var hubUrl = $"{groupConfiguration.ApiUrl?.TrimEnd('/')}/hubs/printer-servers";
_connection = new HubConnectionBuilder() _connection = new HubConnectionBuilder()
.WithUrl("https://api.dev.gastrojames.ch/hubs/printer-servers") .WithUrl(hubUrl)
.WithAutomaticReconnect(new InfiniteRetryPolicy()) .WithAutomaticReconnect(new InfiniteRetryPolicy())
.Build(); .Build();