mastodon-async/entities/src/attachment.rs

76 lines
2.1 KiB
Rust
Raw Normal View History

2022-11-27 14:44:43 +00:00
//! Module containing everything related to media attachements.
2022-12-07 20:58:28 +00:00
use serde::{Deserialize, Serialize};
2022-11-27 14:44:43 +00:00
/// A struct representing a media attachment.
2022-12-07 20:58:28 +00:00
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
2022-11-27 14:44:43 +00:00
pub struct Attachment {
/// ID of the attachment.
2023-01-09 12:45:08 +00:00
pub id: AttachmentId,
2022-11-27 14:44:43 +00:00
/// The media type of an attachment.
#[serde(rename = "type")]
pub media_type: MediaType,
/// URL of the locally hosted version of the image.
2022-12-23 15:09:33 +00:00
pub url: Option<String>,
2022-11-27 14:44:43 +00:00
/// For remote images, the remote URL of the original image.
pub remote_url: Option<String>,
/// URL of the preview image.
pub preview_url: String,
/// Shorter URL for the image, for insertion into text
/// (only present on local images)
pub text_url: Option<String>,
/// Meta information about the attachment.
pub meta: Option<Meta>,
/// Noop will be removed.
pub description: Option<String>,
}
2023-01-09 12:45:08 +00:00
/// Wrapper type for a attachment ID string
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(transparent)]
pub struct AttachmentId(String);
impl AsRef<str> for AttachmentId {
fn as_ref(&self) -> &str {
&self.0
}
}
2022-11-27 14:44:43 +00:00
/// Information about the attachment itself.
2022-12-07 20:58:28 +00:00
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
2022-11-27 14:44:43 +00:00
pub struct Meta {
/// Original version.
pub original: Option<ImageDetails>,
/// Smaller version.
pub small: Option<ImageDetails>,
}
/// Dimensions of an attachement.
2022-12-07 20:58:28 +00:00
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
2022-11-27 14:44:43 +00:00
pub struct ImageDetails {
/// width of attachment.
2023-01-02 11:22:30 +00:00
pub width: u64,
2022-11-27 14:44:43 +00:00
/// height of attachment.
2023-01-02 11:22:30 +00:00
pub height: u64,
2022-11-27 14:44:43 +00:00
/// A string of `widthxheight`.
2023-01-02 11:22:30 +00:00
pub size: Option<String>,
2022-11-27 14:44:43 +00:00
/// The aspect ratio of the attachment.
2023-01-02 11:22:30 +00:00
pub aspect: Option<f64>,
2022-11-27 14:44:43 +00:00
}
/// The type of media attachment.
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
2022-11-27 14:44:43 +00:00
pub enum MediaType {
/// An image.
#[serde(rename = "image")]
Image,
/// A video file.
#[serde(rename = "video")]
Video,
/// A gifv format file.
#[serde(rename = "gifv")]
Gifv,
/// Unknown format.
#[serde(rename = "unknown")]
Unknown,
}