mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-15 17:41:36 +00:00
Refactor file attachment handling to focus on documents only
This commit is contained in:
parent
0dac956da4
commit
bd9d569aa9
@ -156,20 +156,17 @@ public sealed class ContentText : IContent
|
|||||||
|
|
||||||
if(this.FileAttachments.Count > 0)
|
if(this.FileAttachments.Count > 0)
|
||||||
{
|
{
|
||||||
// Filter out files that no longer exist:
|
// Get the list of existing documents:
|
||||||
var existingFiles = this.FileAttachments.Where(x => x.Exists).ToList();
|
var existingDocuments = this.FileAttachments.Where(x => x.Type is FileAttachmentType.DOCUMENT && x.Exists).ToList();
|
||||||
|
|
||||||
// Log warning for missing files:
|
// Log warning for missing files:
|
||||||
var missingFiles = this.FileAttachments.Except(existingFiles).ToList();
|
var missingDocuments = this.FileAttachments.Except(existingDocuments).Where(x => x.Type is FileAttachmentType.DOCUMENT).ToList();
|
||||||
if (missingFiles.Count > 0)
|
if (missingDocuments.Count > 0)
|
||||||
foreach (var missingFile in missingFiles)
|
foreach (var missingDocument in missingDocuments)
|
||||||
LOGGER.LogWarning("File attachment no longer exists and will be skipped: '{MissingFile}'.", missingFile.FilePath);
|
LOGGER.LogWarning("File attachment no longer exists and will be skipped: '{MissingDocument}'.", missingDocument.FilePath);
|
||||||
|
|
||||||
// Determine allowed attachments:
|
// Only proceed if there are existing, allowed documents:
|
||||||
var numberAllowedExistingFiles = existingFiles.Count(x => x.IsValid);
|
if (existingDocuments.Count > 0)
|
||||||
|
|
||||||
// Only proceed if there are existing, allowed files:
|
|
||||||
if (numberAllowedExistingFiles > 0)
|
|
||||||
{
|
{
|
||||||
// Check Pandoc availability once before processing file attachments
|
// Check Pandoc availability once before processing file attachments
|
||||||
var pandocState = await Pandoc.CheckAvailabilityAsync(Program.RUST_SERVICE, showMessages: true, showSuccessMessage: false);
|
var pandocState = await Pandoc.CheckAvailabilityAsync(Program.RUST_SERVICE, showMessages: true, showSuccessMessage: false);
|
||||||
@ -182,20 +179,20 @@ public sealed class ContentText : IContent
|
|||||||
{
|
{
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
sb.AppendLine("The following files are attached to this message:");
|
sb.AppendLine("The following files are attached to this message:");
|
||||||
foreach(var file in existingFiles)
|
foreach(var document in existingDocuments)
|
||||||
{
|
{
|
||||||
if (file.IsForbidden)
|
if (document.IsForbidden)
|
||||||
{
|
{
|
||||||
LOGGER.LogWarning("File attachment '{FilePath}' has a forbidden file type and will be skipped.", file.FilePath);
|
LOGGER.LogWarning("File attachment '{FilePath}' has a forbidden file type and will be skipped.", document.FilePath);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
sb.AppendLine("---------------------------------------");
|
sb.AppendLine("---------------------------------------");
|
||||||
sb.AppendLine($"File path: {file.FilePath}");
|
sb.AppendLine($"File path: {document.FilePath}");
|
||||||
sb.AppendLine("File content:");
|
sb.AppendLine("File content:");
|
||||||
sb.AppendLine("````");
|
sb.AppendLine("````");
|
||||||
sb.AppendLine(await Program.RUST_SERVICE.ReadArbitraryFileData(file.FilePath, int.MaxValue));
|
sb.AppendLine(await Program.RUST_SERVICE.ReadArbitraryFileData(document.FilePath, int.MaxValue));
|
||||||
sb.AppendLine("````");
|
sb.AppendLine("````");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user