cargo fmt

This commit is contained in:
Jordan Petridis
2018-10-23 13:23:01 +03:00
parent c6aa90db3e
commit 990d830f24
16 changed files with 75 additions and 72 deletions
+2 -1
View File
@@ -110,7 +110,8 @@ pub fn get_episode_widget_from_rowid(ep_id: i32) -> Result<EpisodeWidgetModel, D
episodes
.select((
rowid, title, uri, local_uri, epoch, length, duration, played, show_id,
)).filter(rowid.eq(ep_id))
))
.filter(rowid.eq(ep_id))
.get_result::<EpisodeWidgetModel>(&con)
.map_err(From::from)
}
+2 -7
View File
@@ -14,9 +14,7 @@ use models::Source;
#[fail(
display = "Request to {} returned {}. Context: {}",
url,
status_code,
context
url, status_code, context
)]
#[derive(Fail, Debug)]
pub struct HttpStatusError {
@@ -67,10 +65,7 @@ pub enum DataError {
FeedRedirect(Source),
#[fail(display = "Feed is up to date")]
FeedNotModified(Source),
#[fail(
display = "Error occured while Parsing an Episode. Reason: {}",
reason
)]
#[fail(display = "Error occured while Parsing an Episode. Reason: {}", reason)]
ParseEpisodeError { reason: String, parent_id: i32 },
#[fail(display = "Episode was not changed and thus skipped.")]
EpisodeNotChanged,
+4 -2
View File
@@ -108,7 +108,8 @@ fn batch_insert_episodes(episodes: &[NewEpisode]) {
.map_err(|err| {
error!("Failed batch indexng: {}", err);
info!("Fallign back to individual indexing.");
}).unwrap_or_else(|_| {
})
.unwrap_or_else(|_| {
episodes.iter().for_each(|ep| {
ep.index()
.map_err(|err| error!("Error: {}.", err))
@@ -174,7 +175,8 @@ mod tests {
// Create and insert a Source into db
let s = Source::from_url(url).unwrap();
get_feed(path, s.id())
}).collect();
})
.collect();
// Index the channes
let stream_ = stream::iter_ok(feeds).for_each(|x| x.index());
+18 -9
View File
@@ -332,7 +332,8 @@ mod tests {
.title("The Super Bowl of Racism")
.uri(Some(String::from(
"http://traffic.megaphone.fm/PPY6458293736.mp3",
))).guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24")))
)))
.guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24")))
.epoch(1505296800)
.length(Some(66738886))
.duration(Some(4171))
@@ -345,7 +346,8 @@ mod tests {
.title("Atlas Golfed — U.S.-Backed Think Tanks Target Latin America")
.uri(Some(String::from(
"http://traffic.megaphone.fm/FL5331443769.mp3",
))).guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d")))
)))
.guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d")))
.epoch(1502272800)
.length(Some(67527575))
.duration(Some(4415))
@@ -364,7 +366,8 @@ mod tests {
.title("The Super Bowl of Racism")
.uri(Some(String::from(
"http://traffic.megaphone.fm/PPY6458293736.mp3",
))).description(Some(String::from(descr)))
)))
.description(Some(String::from(descr)))
.guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24")))
.length(Some(66738886))
.epoch(1505296800)
@@ -387,7 +390,8 @@ mod tests {
.title("Atlas Golfed — U.S.-Backed Think Tanks Target Latin America")
.uri(Some(String::from(
"http://traffic.megaphone.fm/FL5331443769.mp3",
))).description(Some(String::from(descr)))
)))
.description(Some(String::from(descr)))
.guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d")))
.length(Some(67527575))
.epoch(1502272800)
@@ -401,7 +405,8 @@ mod tests {
.title("The Super Bowl of Racism")
.uri(Some(String::from(
"http://traffic.megaphone.fm/PPY6458293736.mp3",
))).description(Some(String::from("New description")))
)))
.description(Some(String::from("New description")))
.guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24")))
.length(Some(66738886))
.epoch(1505296800)
@@ -415,7 +420,8 @@ mod tests {
.title("Hacking Devices with Kali Linux | LUP 214")
.uri(Some(String::from(
"http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3",
))).guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D")))
)))
.guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D")))
.length(Some(46479789))
.epoch(1505280282)
.duration(Some(5733))
@@ -428,7 +434,8 @@ mod tests {
.title("Gnome Does it Again | LUP 213")
.uri(Some(String::from(
"http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3",
))).guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B")))
)))
.guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B")))
.epoch(1504670247)
.length(Some(36544272))
.duration(Some(4491))
@@ -446,7 +453,8 @@ mod tests {
.title("Hacking Devices with Kali Linux | LUP 214")
.uri(Some(String::from(
"http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3",
))).description(Some(String::from(descr)))
)))
.description(Some(String::from(descr)))
.guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D")))
.length(Some(46479789))
.epoch(1505280282)
@@ -467,7 +475,8 @@ mod tests {
.title("Gnome Does it Again | LUP 213")
.uri(Some(String::from(
"http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3",
))).description(Some(String::from(descr)))
)))
.description(Some(String::from(descr)))
.guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B")))
.length(Some(36544272))
.epoch(1504670247)
+4 -2
View File
@@ -200,7 +200,8 @@ mod tests {
.description(descr)
.image_uri(Some(String::from(
"http://www.jupiterbroadcasting.com/images/LASUN-Badge1400.jpg",
))).source_id(42)
)))
.source_id(42)
.build()
.unwrap()
};
@@ -256,7 +257,8 @@ mod tests {
.description(descr)
.image_uri(Some(String::from(
"http://www.greaterthancode.com/wp-content/uploads/2016/10/code1400-4.jpg",
))).source_id(42)
)))
.source_id(42)
.build()
.unwrap()
};
+22 -13
View File
@@ -4,14 +4,14 @@ use rss::Channel;
use url::Url;
use hyper::client::HttpConnector;
use hyper::{Client, Body};
use hyper::{Body, Client};
use hyper_tls::HttpsConnector;
use http::{Request, Response, StatusCode, Uri};
use http::header::{
ETAG, IF_MODIFIED_SINCE, IF_NONE_MATCH, LAST_MODIFIED, LOCATION, USER_AGENT as USER_AGENT_HEADER,
HeaderValue,
HeaderValue, ETAG, IF_MODIFIED_SINCE, IF_NONE_MATCH, LAST_MODIFIED, LOCATION,
USER_AGENT as USER_AGENT_HEADER,
};
use http::{Request, Response, StatusCode, Uri};
// use futures::future::ok;
use futures::future::{loop_fn, Future, Loop};
use futures::prelude::*;
@@ -96,8 +96,14 @@ impl Source {
fn update_etag(mut self, res: &Response<Body>) -> Result<Self, DataError> {
let headers = res.headers();
let etag = headers.get(ETAG).and_then(|h| h.to_str().ok()).map(From::from);
let lmod = headers.get(LAST_MODIFIED).and_then(|h| h.to_str().ok()).map(From::from);
let etag = headers
.get(ETAG)
.and_then(|h| h.to_str().ok())
.map(From::from);
let lmod = headers
.get(LAST_MODIFIED)
.and_then(|h| h.to_str().ok())
.map(From::from);
if (self.http_etag() != etag) || (self.last_modified != lmod) {
self.set_http_etag(etag);
@@ -249,19 +255,20 @@ impl Source {
) -> impl Future<Item = Response<Body>, Error = DataError> {
// FIXME: remove unwrap somehow
let uri = Uri::from_str(self.uri()).unwrap();
let mut req = Request::get(uri)
.body(Body::empty())
.unwrap();
let mut req = Request::get(uri).body(Body::empty()).unwrap();
// Set the UserAgent cause ppl still seem to check it for some reason...
req.headers_mut().insert(USER_AGENT_HEADER, HeaderValue::from_static(USER_AGENT));
req.headers_mut()
.insert(USER_AGENT_HEADER, HeaderValue::from_static(USER_AGENT));
if let Some(etag) = self.http_etag() {
req.headers_mut().insert(IF_NONE_MATCH, HeaderValue::from_str(etag).unwrap());
req.headers_mut()
.insert(IF_NONE_MATCH, HeaderValue::from_str(etag).unwrap());
}
if let Some(lmod) = self.last_modified() {
req.headers_mut().insert(IF_MODIFIED_SINCE, HeaderValue::from_str(lmod).unwrap());
req.headers_mut()
.insert(IF_MODIFIED_SINCE, HeaderValue::from_str(lmod).unwrap());
}
client
@@ -271,7 +278,9 @@ impl Source {
}
}
fn response_to_channel(res: Response<Body>) -> impl Future<Item = Channel, Error = DataError> + Send {
fn response_to_channel(
res: Response<Body>,
) -> impl Future<Item = Channel, Error = DataError> + Send {
res.into_body()
.concat2()
.map(|x| x.into_iter())
+4 -2
View File
@@ -42,7 +42,8 @@ pub fn import_to_db<R: Read>(reader: R) -> Result<Vec<Source>, reader::Error> {
}
s.ok()
}).collect();
})
.collect();
Ok(feeds)
}
@@ -91,7 +92,8 @@ pub fn extract_sources<R: Read>(reader: R) -> Result<HashSet<Opml>, reader::Erro
}
Err(err) => Err(err),
_ => Ok(()),
}).collect::<Result<Vec<_>, reader::Error>>()?;
})
.collect::<Result<Vec<_>, reader::Error>>()?;
Ok(list)
}
+3 -6
View File
@@ -1,11 +1,11 @@
// FIXME:
//! Docs.
use futures::{lazy, prelude::*, future::ok, stream::FuturesUnordered};
use futures::{future::ok, lazy, prelude::*, stream::FuturesUnordered};
use tokio;
use hyper::client::HttpConnector;
use hyper::{Client, Body};
use hyper::{Body, Client};
use hyper_tls::HttpsConnector;
use num_cpus;
@@ -23,10 +23,7 @@ type HttpsClient = Client<HttpsConnector<HttpConnector>>;
/// Messy temp diagram:
/// Source -> GET Request -> Update Etags -> Check Status -> Parse `xml/Rss` ->
/// Convert `rss::Channel` into `Feed` -> Index Podcast -> Index Episodes.
pub fn pipeline<'a, S>(
sources: S,
client: HttpsClient,
) -> impl Future<Item = (), Error = ()> + 'a
pub fn pipeline<'a, S>(sources: S, client: HttpsClient) -> impl Future<Item = (), Error = ()> + 'a
where
S: Stream<Item = Source, Error = DataError> + Send + 'a,
{
+2 -1
View File
@@ -25,7 +25,8 @@ fn download_checker() -> Result<(), DataError> {
return Some(ep);
}
None
}).for_each(|ep| {
})
.for_each(|ep| {
ep.set_local_uri(None);
ep.save()
.map_err(|err| error!("{}", err))