mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-07-28 01:02:56 +00:00
reject forbidden file typed
This commit is contained in:
parent
04543540f8
commit
53f8257a01
@ -18,15 +18,28 @@ public partial class ReadFileContent : MSGComponentBase
|
|||||||
|
|
||||||
private async Task SelectFile()
|
private async Task SelectFile()
|
||||||
{
|
{
|
||||||
var txtFile = await this.RustService.SelectFile("Select Text file");
|
var selectedFile = await this.RustService.SelectFile("Select Text file");
|
||||||
if (txtFile.UserCancelled)
|
if (selectedFile.UserCancelled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!File.Exists(txtFile.SelectedFilePath))
|
if(!File.Exists(selectedFile.SelectedFilePath))
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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 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 AllImages => new(TB("All Image Files"), ["jpg", "jpeg", "png", "gif", "bmp", "tiff"]);
|
||||||
|
|
||||||
|
public static FileTypeFilter Executables => new(TB("Executable Files"), ["exe", "app", "bin"]);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user