2025-06-30 16:56:48 +00:00
|
|
|
using AIStudio.Tools.Rust;
|
|
|
|
|
using AIStudio.Tools.Services;
|
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Components;
|
|
|
|
|
|
|
|
|
|
public partial class ReadFileContent : MSGComponentBase
|
|
|
|
|
{
|
2025-11-24 11:37:18 +00:00
|
|
|
[Parameter]
|
|
|
|
|
public string Text { get; set; } = string.Empty;
|
|
|
|
|
|
2025-06-30 16:56:48 +00:00
|
|
|
[Parameter]
|
|
|
|
|
public string FileContent { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<string> FileContentChanged { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
private RustService RustService { get; init; } = null!;
|
|
|
|
|
|
2025-11-14 12:34:30 +00:00
|
|
|
[Inject]
|
|
|
|
|
private IDialogService DialogService { get; init; } = null!;
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
private ILogger<ReadFileContent> Logger { get; init; } = null!;
|
|
|
|
|
|
2025-06-30 16:56:48 +00:00
|
|
|
private async Task SelectFile()
|
|
|
|
|
{
|
|
|
|
|
var selectedFile = await this.RustService.SelectFile(T("Select file to read its content"));
|
|
|
|
|
if (selectedFile.UserCancelled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(!File.Exists(selectedFile.SelectedFilePath))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var ext = Path.GetExtension(selectedFile.SelectedFilePath).TrimStart('.');
|
|
|
|
|
if (Array.Exists(FileTypeFilter.Executables.FilterExtensions, x => x.Equals(ext, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.AppBlocking, T("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, T("Images are not supported yet")));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-24 11:37:18 +00:00
|
|
|
if (Array.Exists(FileTypeFilter.AllVideos.FilterExtensions, x => x.Equals(ext, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
await MessageBus.INSTANCE.SendWarning(new(Icons.Material.Filled.FeaturedVideo, this.T("Videos are not supported yet")));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-05 19:48:54 +00:00
|
|
|
var fileContent = await UserFile.LoadFileData(selectedFile.SelectedFilePath, this.RustService, this.DialogService);
|
2025-06-30 16:56:48 +00:00
|
|
|
await this.FileContentChanged.InvokeAsync(fileContent);
|
|
|
|
|
}
|
|
|
|
|
}
|