Update January definitions. (special embeds)
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
export version=0.4.1-alpha.9
|
export version=0.4.1-alpha.10
|
||||||
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
||||||
|
|||||||
@@ -3,30 +3,77 @@ use linkify::{LinkFinder, LinkKind};
|
|||||||
use crate::util::{result::{Error, Result}, variables::JANUARY_URL};
|
use crate::util::{result::{Error, Result}, variables::JANUARY_URL};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub enum MediaSize {
|
pub enum ImageSize {
|
||||||
Large,
|
Large,
|
||||||
Preview,
|
Preview,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct Media {
|
pub struct Image {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub width: isize,
|
pub width: isize,
|
||||||
pub height: isize,
|
pub height: isize,
|
||||||
pub size: MediaSize,
|
pub size: ImageSize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct Video {
|
||||||
|
pub url: String,
|
||||||
|
pub width: isize,
|
||||||
|
pub height: isize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub enum TwitchType {
|
||||||
|
Channel,
|
||||||
|
Video,
|
||||||
|
Clip,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub enum BandcampType {
|
||||||
|
Album,
|
||||||
|
Track
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
pub enum Special {
|
||||||
|
None,
|
||||||
|
YouTube {
|
||||||
|
id: String,
|
||||||
|
},
|
||||||
|
Twitch {
|
||||||
|
content_type: TwitchType,
|
||||||
|
id: String,
|
||||||
|
},
|
||||||
|
Spotify {
|
||||||
|
content_type: String,
|
||||||
|
id: String,
|
||||||
|
},
|
||||||
|
Soundcloud,
|
||||||
|
Bandcamp {
|
||||||
|
content_type: BandcampType,
|
||||||
|
id: String
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
url: Option<String>,
|
url: Option<String>,
|
||||||
|
special: Option<Special>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
image: Option<Media>,
|
image: Option<Image>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
video: Option<Video>,
|
||||||
|
|
||||||
|
// #[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
// opengraph_type: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
site_name: Option<String>,
|
site_name: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@@ -39,13 +86,30 @@ pub struct Metadata {
|
|||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum Embed {
|
pub enum Embed {
|
||||||
Website(Metadata),
|
Website(Metadata),
|
||||||
Image(Media),
|
Image(Image),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Embed {
|
impl Embed {
|
||||||
pub async fn generate(content: String) -> Result<Vec<Embed>> {
|
pub async fn generate(content: String) -> Result<Vec<Embed>> {
|
||||||
// FIXME: allow multiple links
|
let content = content
|
||||||
|
.split("\n")
|
||||||
|
.map(|v| {
|
||||||
|
// Ignore quoted lines.
|
||||||
|
if let Some(c) = v.chars().next() {
|
||||||
|
if c == '>' {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
v
|
||||||
|
})
|
||||||
|
// This will also remove newlines, but
|
||||||
|
// that isn't important here.
|
||||||
|
.collect::<String>();
|
||||||
|
|
||||||
|
// ! FIXME: allow multiple links
|
||||||
|
// ! FIXME: prevent generation if link is surrounded with < >
|
||||||
let mut finder = LinkFinder::new();
|
let mut finder = LinkFinder::new();
|
||||||
finder.kinds(&[LinkKind::Url]);
|
finder.kinds(&[LinkKind::Url]);
|
||||||
let links: Vec<_> = finder.links(&content).collect();
|
let links: Vec<_> = finder.links(&content).collect();
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
pub const VERSION: &str = "0.4.1-alpha.9";
|
pub const VERSION: &str = "0.4.1-alpha.10";
|
||||||
|
|||||||
Reference in New Issue
Block a user