2026-01-05 14:56:10 +00:00
|
|
|
namespace AIStudio.Tools.MIME;
|
|
|
|
|
|
2026-01-05 15:38:52 +00:00
|
|
|
public class ImageBuilder : ISubtype
|
2026-01-05 14:56:10 +00:00
|
|
|
{
|
2026-01-05 16:00:57 +00:00
|
|
|
private const BaseType BASE_TYPE = BaseType.IMAGE;
|
|
|
|
|
|
|
|
|
|
private ImageBuilder()
|
2026-01-05 14:56:10 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-05 16:00:57 +00:00
|
|
|
public static ImageBuilder Create() => new();
|
2026-01-05 15:38:52 +00:00
|
|
|
|
2026-01-05 14:56:10 +00:00
|
|
|
private ImageSubtype subtype;
|
|
|
|
|
|
|
|
|
|
public ImageBuilder UseSubtype(string subType)
|
|
|
|
|
{
|
|
|
|
|
this.subtype = subType.ToLowerInvariant() switch
|
|
|
|
|
{
|
|
|
|
|
"jpeg" or "jpg" => ImageSubtype.JPEG,
|
|
|
|
|
"png" => ImageSubtype.PNG,
|
|
|
|
|
"gif" => ImageSubtype.GIF,
|
|
|
|
|
"webp" => ImageSubtype.WEBP,
|
|
|
|
|
"tiff" or "tif" => ImageSubtype.TIFF,
|
|
|
|
|
"svg+xml" or "svg" => ImageSubtype.SVG,
|
|
|
|
|
"heic" => ImageSubtype.HEIC,
|
|
|
|
|
|
|
|
|
|
_ => throw new ArgumentException("Unsupported MIME image subtype.", nameof(subType))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ImageBuilder UseSubtype(ImageSubtype subType)
|
|
|
|
|
{
|
|
|
|
|
this.subtype = subType;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Implementation of IMIMESubtype
|
|
|
|
|
|
|
|
|
|
public MIMEType Build() => new()
|
|
|
|
|
{
|
|
|
|
|
Type = this,
|
2026-01-05 16:00:57 +00:00
|
|
|
TextRepresentation = $"{BASE_TYPE}/{this.subtype}".ToLowerInvariant()
|
2026-01-05 14:56:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|