diff --git a/app/MindWork AI Studio/Components/ReadFileContent.razor.cs b/app/MindWork AI Studio/Components/ReadFileContent.razor.cs index 2fe8395b..1653fa55 100644 --- a/app/MindWork AI Studio/Components/ReadFileContent.razor.cs +++ b/app/MindWork AI Studio/Components/ReadFileContent.razor.cs @@ -18,15 +18,28 @@ public partial class ReadFileContent : MSGComponentBase private async Task SelectFile() { - var txtFile = await this.RustService.SelectFile("Select Text file"); - if (txtFile.UserCancelled) + var selectedFile = await this.RustService.SelectFile("Select Text file"); + if (selectedFile.UserCancelled) return; - if(!File.Exists(txtFile.SelectedFilePath)) + if(!File.Exists(selectedFile.SelectedFilePath)) return; - var txtContent = await this.RustService.ReadArbitraryFileData(txtFile.SelectedFilePath, int.MaxValue); + var ext = Path.GetExtension(selectedFile.SelectedFilePath).TrimStart('.'); - await this.FileContentChanged.InvokeAsync(txtContent); + if (Array.Exists(FileTypeFilter.Executables.FilterExtensions, x => x.Equals(ext, StringComparison.OrdinalIgnoreCase))) + { + await MessageBus.INSTANCE.SendError(new(@Icons.Material.Filled.AppBlocking, "Executables are not allowed")); + return; + } + + if (Array.Exists(FileTypeFilter.AllImages.FilterExtensions, x => x.Equals(ext, StringComparison.OrdinalIgnoreCase))) + { + await MessageBus.INSTANCE.SendWarning(new(@Icons.Material.Filled.ImageNotSupported, "Images are not supported yet")); + return; + } + + var fileContent = await this.RustService.ReadArbitraryFileData(selectedFile.SelectedFilePath, int.MaxValue); + await this.FileContentChanged.InvokeAsync(fileContent); } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/Rust/FileTypeFilter.cs b/app/MindWork AI Studio/Tools/Rust/FileTypeFilter.cs index e542cec6..8fa4b347 100644 --- a/app/MindWork AI Studio/Tools/Rust/FileTypeFilter.cs +++ b/app/MindWork AI Studio/Tools/Rust/FileTypeFilter.cs @@ -20,4 +20,6 @@ public readonly record struct FileTypeFilter(string FilterName, string[] FilterE public static FileTypeFilter AllOffice => new(TB("All Office Files"), ["docx", "xlsx", "pptx", "doc", "xls", "ppt", "pdf"]); public static FileTypeFilter AllImages => new(TB("All Image Files"), ["jpg", "jpeg", "png", "gif", "bmp", "tiff"]); + + public static FileTypeFilter Executables => new(TB("Executable Files"), ["exe", "app", "bin"]); } \ No newline at end of file