2025-05-26 23:11:54 +00:00
|
|
|
|
using AIStudio.Tools.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2025-04-15 13:16:12 +00:00
|
|
|
|
|
|
|
|
|
namespace AIStudio.Dialogs;
|
|
|
|
|
|
|
|
|
|
public partial class PandocDialog : ComponentBase
|
|
|
|
|
{
|
2025-05-26 14:43:36 +00:00
|
|
|
|
[Inject]
|
|
|
|
|
private HttpClient HttpClient { get; set; } = null!;
|
|
|
|
|
|
2025-05-26 23:11:54 +00:00
|
|
|
|
[Inject]
|
|
|
|
|
private RustService RustService { get; init; } = null!;
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
protected IJSRuntime JsRuntime { get; init; } = null!;
|
|
|
|
|
|
2025-04-15 13:16:12 +00:00
|
|
|
|
[CascadingParameter]
|
|
|
|
|
private IMudDialogInstance MudDialog { get; set; } = null!;
|
2025-05-26 14:43:36 +00:00
|
|
|
|
|
|
|
|
|
private static readonly string LICENCE_URI = "https://raw.githubusercontent.com/jgm/pandoc/master/COPYRIGHT";
|
2025-05-26 23:11:54 +00:00
|
|
|
|
private static string PANDOC_VERSION = "1.0.0";
|
2025-04-15 13:16:12 +00:00
|
|
|
|
|
|
|
|
|
private bool isPandocAvailable;
|
|
|
|
|
private bool showSkeleton;
|
|
|
|
|
private bool showInstallPage;
|
2025-05-26 14:43:36 +00:00
|
|
|
|
private string? licenseText;
|
|
|
|
|
private bool isLoading;
|
2025-04-15 13:16:12 +00:00
|
|
|
|
|
|
|
|
|
#region Overrides of ComponentBase
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
await base.OnInitializedAsync();
|
|
|
|
|
this.showSkeleton = true;
|
|
|
|
|
await this.CheckPandocAvailabilityAsync();
|
2025-05-26 23:11:54 +00:00
|
|
|
|
PANDOC_VERSION = await Pandoc.FetchLatestVersionAsync();
|
2025-04-15 13:16:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void Cancel() => this.MudDialog.Cancel();
|
|
|
|
|
|
|
|
|
|
private async Task CheckPandocAvailabilityAsync()
|
|
|
|
|
{
|
2025-05-26 23:11:54 +00:00
|
|
|
|
this.isPandocAvailable = await Pandoc.CheckAvailabilityAsync(false);
|
2025-04-15 13:16:12 +00:00
|
|
|
|
this.showSkeleton = false;
|
|
|
|
|
await this.InvokeAsync(this.StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-26 23:11:54 +00:00
|
|
|
|
private async Task InstallPandocAsync() => await Pandoc.InstallAsync(this.RustService);
|
|
|
|
|
|
2025-04-15 13:16:12 +00:00
|
|
|
|
private void ProceedToInstallation() => this.showInstallPage = true;
|
2025-05-26 23:11:54 +00:00
|
|
|
|
|
|
|
|
|
private async Task GetInstaller()
|
|
|
|
|
{
|
|
|
|
|
var uri = await Pandoc.GenerateInstallerUriAsync();
|
|
|
|
|
var filename = this.FilenameFromUri(uri);
|
|
|
|
|
await this.JsRuntime.InvokeVoidAsync("triggerDownload", uri, filename);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task GetArchive()
|
|
|
|
|
{
|
|
|
|
|
var uri = await Pandoc.GenerateUriAsync();
|
|
|
|
|
var filename = this.FilenameFromUri(uri);
|
|
|
|
|
await this.JsRuntime.InvokeVoidAsync("triggerDownload", uri, filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string FilenameFromUri(string uri)
|
|
|
|
|
{
|
|
|
|
|
var index = uri.LastIndexOf('/');
|
|
|
|
|
return uri[(index + 1)..];
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-26 14:43:36 +00:00
|
|
|
|
private async Task OnExpandedChanged(bool newVal)
|
|
|
|
|
{
|
|
|
|
|
if (newVal)
|
|
|
|
|
{
|
|
|
|
|
this.isLoading = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(600);
|
|
|
|
|
|
|
|
|
|
this.licenseText = await this.LoadLicenseTextAsync();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2025-05-26 23:11:54 +00:00
|
|
|
|
this.licenseText = "Error loading license text, please consider following the links to the GPL.";
|
2025-05-26 14:43:36 +00:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
this.isLoading = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(350);
|
|
|
|
|
this.licenseText = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<string> LoadLicenseTextAsync()
|
|
|
|
|
{
|
|
|
|
|
var response = await this.HttpClient.GetAsync(LICENCE_URI);
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
|
|
|
return content;
|
|
|
|
|
}
|
2025-04-15 13:16:12 +00:00
|
|
|
|
}
|