111 lines
No EOL
3.1 KiB
C#
111 lines
No EOL
3.1 KiB
C#
namespace Uwaa.Pleroma;
|
|
|
|
public class Attachment
|
|
{
|
|
/// <summary>
|
|
/// The ID of the attachment in the database.
|
|
/// </summary>
|
|
[JsonPropertyName("id")]
|
|
public string ID { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Alternate text that describes what is in the media attachment, to be used for the visually impaired or when media attachments do not load
|
|
/// </summary>
|
|
[JsonPropertyName("description")]
|
|
public string? Description { get; set; }
|
|
|
|
/// <summary>
|
|
/// Additional pleroma-specific data.
|
|
/// </summary>
|
|
[JsonPropertyName("pleroma")]
|
|
public PleromaAttachmentData Pleroma { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// The location of a scaled-down preview of the attachment
|
|
/// </summary>
|
|
[JsonPropertyName("preview_url")]
|
|
public string PreviewURL { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// The location of the full-size original attachment on the remote website. String (URL), or null if the attachment is local
|
|
/// </summary>
|
|
[JsonPropertyName("remote_url")]
|
|
public string? RemoteURL { get; set; }
|
|
|
|
/// <summary>
|
|
/// A shorter URL for the attachment
|
|
/// </summary>
|
|
[JsonPropertyName("text_url")]
|
|
public string? TextURL { get; set; }
|
|
|
|
/// <summary>
|
|
/// The type of the attachment
|
|
/// </summary>
|
|
[JsonPropertyName("type")]
|
|
public AttachmentType Type { get; set; }
|
|
|
|
/// <summary>
|
|
/// The location of the original full-size attachment
|
|
/// </summary>
|
|
[JsonPropertyName("url")]
|
|
public string URL { get; set; } = null!;
|
|
|
|
[JsonConstructor()]
|
|
internal Attachment()
|
|
{
|
|
}
|
|
}
|
|
|
|
[JsonConverter(typeof(EnumLowerCaseConverter<AttachmentType>))]
|
|
public enum AttachmentType
|
|
{
|
|
Unknown,
|
|
Image,
|
|
Video,
|
|
Audio,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Additional pleroma-specific data for an <see cref="Attachment"/>.
|
|
/// </summary>
|
|
public class PleromaAttachmentData
|
|
{
|
|
/// <summary>
|
|
/// MIME type of the attachment
|
|
/// </summary>
|
|
[JsonPropertyName("mime_type")]
|
|
public string MIMEType { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Name of the attachment, typically the filename
|
|
/// </summary>
|
|
[JsonPropertyName("name")]
|
|
public string Name { get; set; } = null!;
|
|
}
|
|
|
|
[JsonConverter(typeof(MediaIDConverter))]
|
|
public readonly struct MediaID(string id)
|
|
{
|
|
public static implicit operator MediaID(string id) => new MediaID(id);
|
|
|
|
public static implicit operator MediaID(Attachment attachment) => new MediaID(attachment.ID);
|
|
|
|
public readonly string ID = id;
|
|
|
|
public override string ToString() => ID;
|
|
}
|
|
|
|
class MediaIDConverter : JsonConverter<MediaID>
|
|
{
|
|
public override bool CanConvert(Type type) => type.IsAssignableTo(typeof(MediaID));
|
|
|
|
public override MediaID Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
return new MediaID(reader.GetString() ?? throw new NullReferenceException("Expected a string, got null"));
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, MediaID value, JsonSerializerOptions options)
|
|
{
|
|
writer.WriteStringValue(value.ID);
|
|
}
|
|
} |