2019-05-01 00:41:13 +02:00
|
|
|
//! Validate query prarams with type checking
|
2019-04-15 20:22:44 +02:00
|
|
|
use serde_derive::Deserialize;
|
2019-05-09 05:02:01 +02:00
|
|
|
use warp::filters::BoxedFilter;
|
|
|
|
use warp::Filter as WarpFilter;
|
2019-04-15 20:22:44 +02:00
|
|
|
|
2019-05-09 05:02:01 +02:00
|
|
|
#[derive(Deserialize, Debug, Default)]
|
2019-04-15 20:22:44 +02:00
|
|
|
pub struct Media {
|
|
|
|
pub only_media: String,
|
|
|
|
}
|
2019-05-09 05:02:01 +02:00
|
|
|
impl Media {
|
|
|
|
pub fn to_filter() -> BoxedFilter<(Self,)> {
|
|
|
|
warp::query()
|
2019-05-09 17:52:05 +02:00
|
|
|
.or(warp::any().map(Self::default))
|
2019-05-09 05:02:01 +02:00
|
|
|
.unify()
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
pub fn is_truthy(&self) -> bool {
|
|
|
|
self.only_media == "true" || self.only_media == "1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[derive(Deserialize, Debug, Default)]
|
2019-04-15 20:22:44 +02:00
|
|
|
pub struct Hashtag {
|
|
|
|
pub tag: String,
|
|
|
|
}
|
2019-05-09 05:02:01 +02:00
|
|
|
impl Hashtag {
|
|
|
|
pub fn to_filter() -> BoxedFilter<(Self,)> {
|
|
|
|
warp::query()
|
2019-05-09 17:52:05 +02:00
|
|
|
.or(warp::any().map(Self::default))
|
2019-05-09 05:02:01 +02:00
|
|
|
.unify()
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[derive(Deserialize, Debug, Default)]
|
2019-04-15 20:22:44 +02:00
|
|
|
pub struct List {
|
2019-04-21 15:21:44 +02:00
|
|
|
pub list: i64,
|
2019-04-15 20:22:44 +02:00
|
|
|
}
|
2019-05-09 05:02:01 +02:00
|
|
|
impl List {
|
|
|
|
pub fn to_filter() -> BoxedFilter<(Self,)> {
|
|
|
|
warp::query()
|
2019-05-09 17:52:05 +02:00
|
|
|
.or(warp::any().map(Self::default))
|
2019-05-09 05:02:01 +02:00
|
|
|
.unify()
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
}
|
2019-04-27 02:00:11 +02:00
|
|
|
#[derive(Deserialize, Debug)]
|
2019-04-19 01:02:29 +02:00
|
|
|
pub struct Auth {
|
|
|
|
pub access_token: String,
|
|
|
|
}
|
2019-05-09 05:02:01 +02:00
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
pub struct Stream {
|
|
|
|
pub stream: String,
|
|
|
|
}
|
|
|
|
impl ToString for Stream {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
format!("{:?}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn optional_media_query() -> BoxedFilter<(Media,)> {
|
|
|
|
warp::query()
|
|
|
|
.or(warp::any().map(|| Media {
|
|
|
|
only_media: "false".to_owned(),
|
|
|
|
}))
|
|
|
|
.unify()
|
|
|
|
.boxed()
|
|
|
|
}
|