Ensure Pandoc availability check before processing files

This commit is contained in:
Thorsten Sommer 2025-12-09 21:44:46 +01:00
parent 8b0f5dfbf8
commit 34dd75bb40
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -153,20 +153,27 @@ public sealed class ContentText : IContent
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.AppendLine(this.Text); sb.AppendLine(this.Text);
if(this.FileAttachments.Count > 0) if(this.FileAttachments.Count > 0)
{ {
sb.AppendLine(); // Check Pandoc availability once before processing file attachments
sb.AppendLine("The following files are attached to this message:"); var pandocState = await Pandoc.CheckAvailabilityAsync(Program.RUST_SERVICE, showMessages: true, showSuccessMessage: false);
foreach(var file in this.FileAttachments) if (!pandocState.IsAvailable || !pandocState.CheckWasSuccessful)
LOGGER.LogWarning("File attachments could not be processed because Pandoc is not available or the version check failed.");
else
{ {
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("---------------------------------------"); sb.AppendLine("The following files are attached to this message:");
sb.AppendLine($"File path: {file}"); foreach(var file in this.FileAttachments)
sb.AppendLine("File content:"); {
sb.AppendLine("````"); sb.AppendLine();
sb.AppendLine(await Program.RUST_SERVICE.ReadArbitraryFileData(file, int.MaxValue)); sb.AppendLine("---------------------------------------");
sb.AppendLine("````"); sb.AppendLine($"File path: {file}");
sb.AppendLine("File content:");
sb.AppendLine("````");
sb.AppendLine(await Program.RUST_SERVICE.ReadArbitraryFileData(file, int.MaxValue));
sb.AppendLine("````");
}
} }
} }
return sb.ToString(); return sb.ToString();