Enhance FileAttachment struct with validation checks for forbidden file types

This commit is contained in:
Thorsten Sommer 2025-12-28 16:09:39 +01:00
parent d98c0afc4f
commit 2a4770eef3
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -8,10 +8,20 @@ namespace AIStudio.Chat;
public readonly record struct FileAttachment(FileAttachmentType Type, string FileName, string FilePath, long FileSizeBytes) public readonly record struct FileAttachment(FileAttachmentType Type, string FileName, string FilePath, long FileSizeBytes)
{ {
/// <summary> /// <summary>
/// Gets a value indicating whether the file still exists on the file system.` /// Gets a value indicating whether the file still exists on the file system.
/// </summary> /// </summary>
public bool Exists => File.Exists(this.FilePath); public bool Exists => File.Exists(this.FilePath);
/// <summary>
/// Gets a value indicating whether the file type is forbidden and should not be attached.
/// </summary>
public bool IsForbidden => this.Type == FileAttachmentType.FORBIDDEN;
/// <summary>
/// Gets a value indicating whether the file type is valid and allowed to be attached.
/// </summary>
public bool IsValid => this.Type != FileAttachmentType.FORBIDDEN;
/// <summary> /// <summary>
/// Creates a FileAttachment from a file path by automatically determining the type, /// Creates a FileAttachment from a file path by automatically determining the type,
/// extracting the filename, and reading the file size. /// extracting the filename, and reading the file size.