From ca76da65f223c1b82f33bbe744e4e5d33c2eaa65 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 28 Dec 2025 16:22:18 +0100 Subject: [PATCH] Refactor file attachment handling to skip forbidden file types in DocumentAnalysisAssistant, ContentText, and ChatComponent --- .../DocumentAnalysisAssistant.razor.cs | 6 ++++++ app/MindWork AI Studio/Chat/ContentText.cs | 13 +++++++++++-- .../Components/ChatComponent.razor.cs | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs index fa53b044..d7ee8987 100644 --- a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs +++ b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs @@ -332,6 +332,12 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore 0) + // Determine allowed attachments: + var numberAllowedExistingFiles = existingFiles.Count(x => x.IsValid); + + // Only proceed if there are existing, allowed files: + if (numberAllowedExistingFiles > 0) { // Check Pandoc availability once before processing file attachments var pandocState = await Pandoc.CheckAvailabilityAsync(Program.RUST_SERVICE, showMessages: true, showSuccessMessage: false); @@ -181,6 +184,12 @@ public sealed class ContentText : IContent sb.AppendLine("The following files are attached to this message:"); foreach(var file in existingFiles) { + if (file.IsForbidden) + { + LOGGER.LogWarning("File attachment '{FilePath}' has a forbidden file type and will be skipped.", file.FilePath); + continue; + } + sb.AppendLine(); sb.AppendLine("---------------------------------------"); sb.AppendLine($"File path: {file.FilePath}"); diff --git a/app/MindWork AI Studio/Components/ChatComponent.razor.cs b/app/MindWork AI Studio/Components/ChatComponent.razor.cs index 44b3dafa..347c096b 100644 --- a/app/MindWork AI Studio/Components/ChatComponent.razor.cs +++ b/app/MindWork AI Studio/Components/ChatComponent.razor.cs @@ -464,7 +464,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable lastUserPrompt = new ContentText { Text = this.userInput, - FileAttachments = [..this.chatDocumentPaths], + FileAttachments = [..this.chatDocumentPaths.Where(x => x.IsValid)], }; //