mastodon-async/src/entities/attachment.rs

66 lines
1.8 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.
pub id: String,
/// The media type of an attachment.
#[serde(rename = "type")]
pub media_type: MediaType,
/// URL of the locally hosted version of the image.
pub url: String,
/// 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>,
}
/// 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.
width: u64,
/// height of attachment.
height: u64,
/// A string of `widthxheight`.
size: Option<String>,
/// The aspect ratio of the attachment.
aspect: Option<f64>,
}
/// The type of media attachment.
2022-12-07 20:58:28 +00:00
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq)]
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,
}