From 9fc3213603ecc9c9bfbba4b8501f14491b8734dc Mon Sep 17 00:00:00 2001 From: krut_ni Date: Mon, 23 Jun 2025 14:15:08 +0200 Subject: [PATCH] add a new component for the extraction of arbitrary file data --- .../Components/ReadFileContent.razor | 4 +++ .../Components/ReadFileContent.razor.cs | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 app/MindWork AI Studio/Components/ReadFileContent.razor create mode 100644 app/MindWork AI Studio/Components/ReadFileContent.razor.cs diff --git a/app/MindWork AI Studio/Components/ReadFileContent.razor b/app/MindWork AI Studio/Components/ReadFileContent.razor new file mode 100644 index 00000000..8be6f058 --- /dev/null +++ b/app/MindWork AI Studio/Components/ReadFileContent.razor @@ -0,0 +1,4 @@ +@inherits MSGComponentBase + + Use PDF content as input" + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/ReadFileContent.razor.cs b/app/MindWork AI Studio/Components/ReadFileContent.razor.cs new file mode 100644 index 00000000..2fe8395b --- /dev/null +++ b/app/MindWork AI Studio/Components/ReadFileContent.razor.cs @@ -0,0 +1,32 @@ +using AIStudio.Tools.Rust; +using AIStudio.Tools.Services; + +using Microsoft.AspNetCore.Components; + +namespace AIStudio.Components; + +public partial class ReadFileContent : MSGComponentBase +{ + [Parameter] + public string FileContent { get; set; } = string.Empty; + + [Parameter] + public EventCallback FileContentChanged { get; set; } + + [Inject] + private RustService RustService { get; init; } = null!; + + private async Task SelectFile() + { + var txtFile = await this.RustService.SelectFile("Select Text file"); + if (txtFile.UserCancelled) + return; + + if(!File.Exists(txtFile.SelectedFilePath)) + return; + + var txtContent = await this.RustService.ReadArbitraryFileData(txtFile.SelectedFilePath, int.MaxValue); + + await this.FileContentChanged.InvokeAsync(txtContent); + } +} \ No newline at end of file