Introduce FileAttachmentImage for improved image handling and refactor FileAttachment creation logic

This commit is contained in:
Thorsten Sommer 2025-12-29 17:33:48 +01:00
parent 19cc1de84b
commit 8778feee30
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 25 additions and 2 deletions

View File

@ -9,7 +9,7 @@ namespace AIStudio.Chat;
/// <param name="FileName">The name of the file, including extension.</param>
/// <param name="FilePath">The full path to the file, including the filename and extension.</param>
/// <param name="FileSizeBytes">The size of the file in bytes.</param>
public readonly record struct FileAttachment(FileAttachmentType Type, string FileName, string FilePath, long FileSizeBytes)
public record FileAttachment(FileAttachmentType Type, string FileName, string FilePath, long FileSizeBytes)
{
/// <summary>
/// Gets a value indicating whether the file type is forbidden and should not be attached.
@ -55,7 +55,13 @@ public readonly record struct FileAttachment(FileAttachmentType Type, string Fil
var fileSize = File.Exists(filePath) ? new FileInfo(filePath).Length : 0;
var type = DetermineFileType(filePath);
return new FileAttachment(type, fileName, filePath, fileSize);
return type switch
{
FileAttachmentType.DOCUMENT => new FileAttachment(type, fileName, filePath, fileSize),
FileAttachmentType.IMAGE => new FileAttachmentImage(fileName, filePath, fileSize),
_ => new FileAttachment(type, fileName, filePath, fileSize),
};
}
/// <summary>

View File

@ -0,0 +1,17 @@
namespace AIStudio.Chat;
public record FileAttachmentImage(string FileName, string FilePath, long FileSizeBytes) : FileAttachment(FileAttachmentType.IMAGE, FileName, FilePath, FileSizeBytes), IImageSource
{
/// <summary>
/// The type of the image source.
/// </summary>
/// <remarks>
/// Is the image source a URL, a local file path, a base64 string, etc.?
/// </remarks>
public ContentImageSource SourceType { get; init; } = ContentImageSource.LOCAL_PATH;
/// <summary>
/// The image source.
/// </summary>
public string Source { get; set; } = FilePath;
}