From d10f2af9f73b9980c8a6dcdd444142724d7f70c2 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Mon, 2 Jun 2025 15:58:47 +0200 Subject: [PATCH] Add ETag handling in enterprise environment logic --- .../Tools/EnterpriseEnvironment.cs | 4 +++- .../PluginSystem/PluginFactory.Download.cs | 20 +++++++++++++++++++ .../Services/EnterpriseEnvironmentService.cs | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/MindWork AI Studio/Tools/EnterpriseEnvironment.cs b/app/MindWork AI Studio/Tools/EnterpriseEnvironment.cs index fd61b949..fd7e3fbe 100644 --- a/app/MindWork AI Studio/Tools/EnterpriseEnvironment.cs +++ b/app/MindWork AI Studio/Tools/EnterpriseEnvironment.cs @@ -1,6 +1,8 @@ +using System.Net.Http.Headers; + namespace AIStudio.Tools; -public readonly record struct EnterpriseEnvironment(string ConfigurationServerUrl, Guid ConfigurationId) +public readonly record struct EnterpriseEnvironment(string ConfigurationServerUrl, Guid ConfigurationId, EntityTagHeaderValue? ETag) { public bool IsActive => !string.IsNullOrEmpty(this.ConfigurationServerUrl) && this.ConfigurationId != Guid.Empty; } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.Download.cs b/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.Download.cs index b8720bc9..5f3dc4cb 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.Download.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.Download.cs @@ -1,9 +1,29 @@ using System.IO.Compression; +using System.Net.Http.Headers; namespace AIStudio.Tools.PluginSystem; public static partial class PluginFactory { + public static async Task DetermineConfigPluginETagAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default) + { + try + { + var serverUrl = configServerUrl.EndsWith('/') ? configServerUrl[..^1] : configServerUrl; + var downloadUrl = $"{serverUrl}/{configPlugId}.zip"; + + using var http = new HttpClient(); + using var request = new HttpRequestMessage(HttpMethod.Get, downloadUrl); + var response = await http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); + return response.Headers.ETag; + } + catch (Exception e) + { + LOG.LogError(e, "An error occurred while determining the ETag for the configuration plugin."); + return null; + } + } + public static async Task TryDownloadingConfigPluginAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default) { if(!IS_INITIALIZED) diff --git a/app/MindWork AI Studio/Tools/Services/EnterpriseEnvironmentService.cs b/app/MindWork AI Studio/Tools/Services/EnterpriseEnvironmentService.cs index 757ac1ff..28ec16de 100644 --- a/app/MindWork AI Studio/Tools/Services/EnterpriseEnvironmentService.cs +++ b/app/MindWork AI Studio/Tools/Services/EnterpriseEnvironmentService.cs @@ -40,7 +40,8 @@ public sealed class EnterpriseEnvironmentService(ILogger