From 84ad874a2bc7177283b971e83318d6b347625ddf Mon Sep 17 00:00:00 2001 From: Ashley Date: Sun, 10 Dec 2023 10:28:44 +0000 Subject: [PATCH] inital source for january :3 --- january/src/structs/embed.rs | 16 ++ january/src/structs/media.rs | 25 +++ january/src/structs/metadata.rs | 320 ++++++++++++++++++++++++++++++++ january/src/structs/mod.rs | 4 + january/src/structs/special.rs | 52 ++++++ 5 files changed, 417 insertions(+) create mode 100644 january/src/structs/embed.rs create mode 100644 january/src/structs/media.rs create mode 100644 january/src/structs/metadata.rs create mode 100644 january/src/structs/mod.rs create mode 100644 january/src/structs/special.rs 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