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-29 23:50:29 +00:00
|
|
|
|
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
|
|
|
|
2023-01-09 13:26:13 +00:00
|
|
|
impl AttachmentId {
|
|
|
|
pub fn new(value: impl Into<String>) -> Self {
|
|
|
|
Self(value.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
2022-12-27 18:08:24 +00:00
|
|
|
#[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,
|
|
|
|
}
|