mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 20:21:37 +00:00
Some checks are pending
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
83 lines
2.8 KiB
C#
83 lines
2.8 KiB
C#
using AIStudio.Tools.Services;
|
|
using AIStudio.Tools.Validation;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AIStudio.Components;
|
|
|
|
public partial class ReadFileContent : MSGComponentBase
|
|
{
|
|
[Parameter]
|
|
public string Text { get; set; } = string.Empty;
|
|
|
|
[Parameter]
|
|
public string FileContent { get; set; } = string.Empty;
|
|
|
|
[Parameter]
|
|
public EventCallback<string> FileContentChanged { get; set; }
|
|
|
|
[Parameter]
|
|
public bool Disabled { get; set; }
|
|
|
|
[Inject]
|
|
private RustService RustService { get; init; } = null!;
|
|
|
|
[Inject]
|
|
private IDialogService DialogService { get; init; } = null!;
|
|
|
|
[Inject]
|
|
private ILogger<ReadFileContent> Logger { get; init; } = null!;
|
|
|
|
[Inject]
|
|
private PandocAvailabilityService PandocAvailabilityService { get; init; } = null!;
|
|
|
|
private async Task SelectFile()
|
|
{
|
|
if (this.Disabled)
|
|
return;
|
|
|
|
// Ensure that Pandoc is installed and ready:
|
|
var pandocState = await this.PandocAvailabilityService.EnsureAvailabilityAsync(
|
|
showSuccessMessage: false,
|
|
showDialog: true);
|
|
|
|
// Check if Pandoc is available after the check / installation:
|
|
if (!pandocState.IsAvailable)
|
|
{
|
|
this.Logger.LogWarning("The user cancelled the Pandoc installation or Pandoc is not available. Aborting file selection.");
|
|
return;
|
|
}
|
|
|
|
var selectedFile = await this.RustService.SelectFile(T("Select file to read its content"));
|
|
if (selectedFile.UserCancelled)
|
|
{
|
|
this.Logger.LogInformation("User cancelled the file selection");
|
|
return;
|
|
}
|
|
|
|
if(!File.Exists(selectedFile.SelectedFilePath))
|
|
{
|
|
this.Logger.LogWarning("Selected file does not exist: '{FilePath}'", selectedFile.SelectedFilePath);
|
|
return;
|
|
}
|
|
|
|
if (!await FileExtensionValidation.IsExtensionValidWithNotifyAsync(FileExtensionValidation.UseCase.DIRECTLY_LOADING_CONTENT, selectedFile.SelectedFilePath))
|
|
{
|
|
this.Logger.LogWarning("User attempted to load unsupported file: {FilePath}", selectedFile.SelectedFilePath);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var fileContent = await UserFile.LoadFileData(selectedFile.SelectedFilePath, this.RustService, this.DialogService);
|
|
await this.FileContentChanged.InvokeAsync(fileContent);
|
|
this.Logger.LogInformation("Successfully loaded file content: {FilePath}", selectedFile.SelectedFilePath);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.Logger.LogError(ex, "Failed to load file content: {FilePath}", selectedFile.SelectedFilePath);
|
|
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Error, T("Failed to load file content")));
|
|
}
|
|
}
|
|
}
|