diff --git a/january/src/structs/embed.rs b/january/src/structs/embed.rs new file mode 100644 index 00000000..d0be001f --- /dev/null +++ b/january/src/structs/embed.rs @@ -0,0 +1,16 @@ +use serde::Serialize; + +use super::{ + media::{Image, Video}, + metadata::Metadata, +}; + +#[derive(Clone, Debug, Serialize)] +#[serde(tag = "type")] +#[allow(clippy::large_enum_variant)] +pub enum Embed { + Website(Metadata), + Image(Image), + Video(Video), + None, +} diff --git a/january/src/structs/media.rs b/january/src/structs/media.rs new file mode 100644 index 00000000..0ce68ab4 --- /dev/null +++ b/january/src/structs/media.rs @@ -0,0 +1,25 @@ +use serde::Serialize; +use validator::Validate; + +#[derive(Clone, Debug, Serialize)] +pub enum ImageSize { + Large, + Preview, +} + +#[derive(Clone, Validate, Debug, Serialize)] +pub struct Image { + #[validate(length(min = 1, max = 512))] + pub url: String, + pub width: isize, + pub height: isize, + pub size: ImageSize, +} + +#[derive(Clone, Validate, Debug, Serialize)] +pub struct Video { + #[validate(length(min = 1, max = 512))] + pub url: String, + pub width: isize, + pub height: isize, +} diff --git a/january/src/structs/metadata.rs b/january/src/structs/metadata.rs new file mode 100644 index 00000000..dd3083e9 --- /dev/null +++ b/january/src/structs/metadata.rs @@ -0,0 +1,320 @@ +use regex::Regex; +use reqwest::Response; +use scraper::Selector; +use serde::Serialize; +use std::collections::HashMap; +use validator::Validate; + +use crate::{ + structs::special::{BandcampType, LightspeedType, TwitchType}, + util::{ + request::{consume_fragment, consume_size, fetch}, + result::Error, + }, +}; + +use super::{ + media::{Image, ImageSize, Video}, + special::Special, +}; + +#[derive(Clone, Validate, Debug, Serialize)] +pub struct Metadata { + #[validate(length(min = 1, max = 256))] + url: String, + original_url: String, + special: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[validate(length(min = 1, max = 100))] + title: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[validate(length(min = 0, max = 2000))] + description: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[validate] + image: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[validate] + video: Option