From 6cf14a57c7e8a6209fdd4ae033094aed9cf6e1c7 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 30 Dec 2025 14:15:13 +0100 Subject: [PATCH] Allow image previews --- app/MindWork AI Studio/Chat/FileAttachment.cs | 5 ++ .../Components/AttachDocuments.razor.cs | 2 +- .../Dialogs/DocumentCheckDialog.razor | 74 ++++++++++--------- .../Dialogs/DocumentCheckDialog.razor.cs | 20 +++-- 4 files changed, 59 insertions(+), 42 deletions(-) diff --git a/app/MindWork AI Studio/Chat/FileAttachment.cs b/app/MindWork AI Studio/Chat/FileAttachment.cs index 4d49b225..eaf9d399 100644 --- a/app/MindWork AI Studio/Chat/FileAttachment.cs +++ b/app/MindWork AI Studio/Chat/FileAttachment.cs @@ -35,6 +35,11 @@ public record FileAttachment(FileAttachmentType Type, string FileName, string Fi /// public bool IsImage { get; } = Type == FileAttachmentType.IMAGE; + /// + /// Gets the file path formatted as a file URL (file:///). + /// + public string FilePathAsUrl { get; } = $"file:///{FilePath.Replace('\\', '/')}"; + /// /// Gets a value indicating whether the file still exists on the file system. /// diff --git a/app/MindWork AI Studio/Components/AttachDocuments.razor.cs b/app/MindWork AI Studio/Components/AttachDocuments.razor.cs index bddcbe43..9bc48747 100644 --- a/app/MindWork AI Studio/Components/AttachDocuments.razor.cs +++ b/app/MindWork AI Studio/Components/AttachDocuments.razor.cs @@ -219,7 +219,7 @@ public partial class AttachDocuments : MSGComponentBase { var dialogParameters = new DialogParameters { - { x => x.FilePath, fileAttachment.FilePath }, + { x => x.Document, fileAttachment }, }; await this.DialogService.ShowAsync(T("Document Preview"), dialogParameters, DialogOptions.FULLSCREEN); diff --git a/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor b/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor index 88e5353f..2d1f9b09 100644 --- a/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor +++ b/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor @@ -6,7 +6,7 @@ @T("See how we load your file. Review the content before we process it further.") - @if (string.IsNullOrWhiteSpace(this.FilePath)) + @if (this.Document is null) { } @@ -14,7 +14,7 @@ { - - -
- -
-
-
- - - + @if (this.Document?.IsImage ?? false) + { + + + + } + else + { + + +
+ +
+
+
+ + + + } diff --git a/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor.cs b/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor.cs index 241e0393..799db7d1 100644 --- a/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/DocumentCheckDialog.razor.cs @@ -1,4 +1,5 @@ -using AIStudio.Components; +using AIStudio.Chat; +using AIStudio.Components; using AIStudio.Tools.Services; using Microsoft.AspNetCore.Components; @@ -13,7 +14,7 @@ public partial class DocumentCheckDialog : MSGComponentBase private IMudDialogInstance MudDialog { get; set; } = null!; [Parameter] - public string FilePath { get; set; } = string.Empty; + public FileAttachment? Document { get; set; } private void Close() => this.MudDialog.Cancel(); @@ -31,23 +32,26 @@ public partial class DocumentCheckDialog : MSGComponentBase protected override async Task OnAfterRenderAsync(bool firstRender) { - if (firstRender && !string.IsNullOrWhiteSpace(this.FilePath)) + if (firstRender && this.Document is not null) { try { - var fileContent = await UserFile.LoadFileData(this.FilePath, this.RustService, this.DialogService); - this.FileContent = fileContent; - this.StateHasChanged(); + if (!this.Document.IsImage) + { + var fileContent = await UserFile.LoadFileData(this.Document.FilePath, this.RustService, this.DialogService); + this.FileContent = fileContent; + this.StateHasChanged(); + } } catch (Exception ex) { - this.Logger.LogError(ex, "Failed to load file content from '{FilePath}'", this.FilePath); + this.Logger.LogError(ex, "Failed to load file content from '{FilePath}'", this.Document); this.FileContent = string.Empty; this.StateHasChanged(); } } else if (firstRender) - this.Logger.LogWarning("Document check dialog opened without a valid file path"); + this.Logger.LogWarning("Document check dialog opened without a valid file path."); } private CodeBlockTheme CodeColorPalette => this.SettingsManager.IsDarkMode ? CodeBlockTheme.Dark : CodeBlockTheme.Default;