2021-02-21 05:38:48 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-12-07 23:41:32 +00:00
|
|
|
|
2021-02-21 05:38:48 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
2021-02-20 23:05:04 +00:00
|
|
|
#[serde(rename_all = "lowercase")]
|
|
|
|
pub enum Rating {
|
|
|
|
General,
|
|
|
|
Mature,
|
|
|
|
Adult,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::str::FromStr for Rating {
|
|
|
|
type Err = &'static str;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
let rating = match s {
|
|
|
|
"g" | "s" | "general" => Self::General,
|
|
|
|
"m" | "q" | "mature" => Self::Mature,
|
|
|
|
"a" | "e" | "adult" => Self::Adult,
|
|
|
|
_ => return Err("unknown rating"),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(rating)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 23:41:32 +00:00
|
|
|
/// A general type for every result in a search.
|
2021-02-21 05:38:48 +00:00
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
2020-12-07 23:41:32 +00:00
|
|
|
pub struct SearchResult {
|
|
|
|
pub site_id: i64,
|
|
|
|
pub site_id_str: String,
|
|
|
|
|
|
|
|
pub url: String,
|
|
|
|
pub filename: String,
|
|
|
|
pub artists: Option<Vec<String>>,
|
2021-02-20 23:05:04 +00:00
|
|
|
pub rating: Option<Rating>,
|
2020-12-07 23:41:32 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub site_info: Option<SiteInfo>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub hash: Option<i64>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub distance: Option<u64>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub searched_hash: Option<i64>,
|
|
|
|
}
|
|
|
|
|
2021-02-21 05:38:48 +00:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2020-12-07 23:41:32 +00:00
|
|
|
#[serde(tag = "site", content = "site_info")]
|
|
|
|
pub enum SiteInfo {
|
|
|
|
FurAffinity {
|
|
|
|
file_id: i32,
|
|
|
|
},
|
|
|
|
#[serde(rename = "e621")]
|
|
|
|
E621 {
|
|
|
|
sources: Option<Vec<String>>,
|
|
|
|
},
|
|
|
|
Twitter,
|
2021-04-19 21:22:40 +00:00
|
|
|
Weasyl,
|
2020-12-07 23:41:32 +00:00
|
|
|
}
|