Add initialization check to plugin download logic

This commit is contained in:
Thorsten Sommer 2025-06-02 15:29:50 +02:00
parent 3cf3f2d817
commit 4ced06473b
No known key found for this signature in database
GPG Key ID: B0B7E2FC074BF1F5

View File

@ -6,13 +6,21 @@ public static partial class PluginFactory
{ {
public static async Task<bool> TryDownloadingConfigPluginAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default) public static async Task<bool> TryDownloadingConfigPluginAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default)
{ {
LOG.LogInformation($"Downloading configuration plugin with ID: {configPlugId} from server: {configServerUrl}"); if(!IS_INITIALIZED)
{
LOG.LogWarning("Plugin factory is not yet initialized. Cannot download configuration plugin.");
return false;
}
var serverUrl = configServerUrl.EndsWith('/') ? configServerUrl[..^1] : configServerUrl;
var downloadUrl = $"{serverUrl}/{configPlugId}.zip";
LOG.LogInformation($"Try to download configuration plugin with ID='{configPlugId}' from server='{configServerUrl}' (GET {downloadUrl})");
var tempDownloadFile = Path.GetTempFileName(); var tempDownloadFile = Path.GetTempFileName();
try try
{ {
using var httpClient = new HttpClient(); using var httpClient = new HttpClient();
var serverUrl = configServerUrl.EndsWith('/') ? configServerUrl[..^1] : configServerUrl; var response = await httpClient.GetAsync(downloadUrl, cancellationToken);
var response = await httpClient.GetAsync($"{serverUrl}/{configPlugId}.zip", cancellationToken);
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {
await using var tempFileStream = File.Create(tempDownloadFile); await using var tempFileStream = File.Create(tempDownloadFile);