Refactor file attachment handling to improve file existence checks and logging

This commit is contained in:
Thorsten Sommer 2025-12-28 15:39:22 +01:00
parent 8c046dc3ae
commit c480444559
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -156,14 +156,14 @@ public sealed class ContentText : IContent
if(this.FileAttachments.Count > 0)
{
// Filter out files that no longer exist
var existingFiles = this.FileAttachments.Where(File.Exists).ToList();
// Filter out files that no longer exist:
var existingFiles = this.FileAttachments.Where(x => x.Exists).ToList();
// Log warning for missing files
// Log warning for missing files:
var missingFiles = this.FileAttachments.Except(existingFiles).ToList();
if (missingFiles.Count > 0)
foreach (var missingFile in missingFiles)
LOGGER.LogWarning("File attachment no longer exists and will be skipped: '{MissingFile}'", missingFile);
LOGGER.LogWarning("File attachment no longer exists and will be skipped: '{MissingFile}'.", missingFile.FilePath);
// Only proceed if there are existing files
if (existingFiles.Count > 0)
@ -183,10 +183,10 @@ public sealed class ContentText : IContent
{
sb.AppendLine();
sb.AppendLine("---------------------------------------");
sb.AppendLine($"File path: {file}");
sb.AppendLine($"File path: {file.FilePath}");
sb.AppendLine("File content:");
sb.AppendLine("````");
sb.AppendLine(await Program.RUST_SERVICE.ReadArbitraryFileData(file, int.MaxValue));
sb.AppendLine(await Program.RUST_SERVICE.ReadArbitraryFileData(file.FilePath, int.MaxValue));
sb.AppendLine("````");
}
}