Remove rand from the downloader.

This commit is contained in:
Jordan Petridis 2017-11-26 03:47:43 +02:00
parent 6336f7cac1
commit 7eff93ecf1
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
6 changed files with 4 additions and 18 deletions

1
Cargo.lock generated
View File

@ -571,7 +571,6 @@ dependencies = [
"hyper 0.11.7 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.11.7 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 1.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 1.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
] ]

View File

@ -46,7 +46,7 @@ Flatpak instructions... Soon™.
### Dependancies ### Dependancies
* Rust stable 1.21 or later. * Rust stable 1.22 or later.
* Gtk+ 3.22 or later * Gtk+ 3.22 or later
* Meson * Meson

View File

@ -38,7 +38,6 @@ lazy_static! {
} }
pub fn connection() -> Pool { pub fn connection() -> Pool {
// Arc::clone(&DB)
Arc::clone(&POOL) Arc::clone(&POOL)
} }

View File

@ -9,7 +9,6 @@ error-chain = "0.11.0"
hyper = "0.11.7" hyper = "0.11.7"
log = "0.3.8" log = "0.3.8"
mime_guess = "1.8.2" mime_guess = "1.8.2"
rand = "0.3.18"
reqwest = "0.8.1" reqwest = "0.8.1"
tempdir = "0.3.5" tempdir = "0.3.5"

View File

@ -1,8 +1,6 @@
use reqwest; use reqwest;
use hyper::header::*; use hyper::header::*;
use tempdir::TempDir; use tempdir::TempDir;
use rand;
use rand::Rng;
use mime_guess; use mime_guess;
use std::fs::{rename, DirBuilder, File}; use std::fs::{rename, DirBuilder, File};
@ -62,13 +60,8 @@ fn download_into(dir: &str, file_title: &str, url: &str) -> Result<String> {
// Construct a temp file to save desired content. // Construct a temp file to save desired content.
let tempdir = TempDir::new_in(dir, "")?; let tempdir = TempDir::new_in(dir, "")?;
let mut rng = rand::thread_rng();
let out_file = format!( let out_file = format!("{}/temp.part", tempdir.path().to_str().unwrap(),);
"{}/{}.part",
tempdir.path().to_str().unwrap(),
rng.gen::<usize>()
);
// Save requested content into the file. // Save requested content into the file.
save_io(&out_file, &mut resp, ct_len)?; save_io(&out_file, &mut resp, ct_len)?;
@ -142,11 +135,7 @@ pub fn get_episode(ep: &mut Episode, download_folder: &str) -> Result<()> {
} }
pub fn cache_image(pd: &Podcast) -> Option<String> { pub fn cache_image(pd: &Podcast) -> Option<String> {
if pd.image_uri().is_none() { let url = pd.image_uri()?.to_owned();
return None;
}
let url = pd.image_uri().unwrap().to_owned();
if url == "" { if url == "" {
return None; return None;
} }
@ -159,6 +148,7 @@ pub fn cache_image(pd: &Podcast) -> Option<String> {
// Hacky way // Hacky way
// TODO: make it so it returns the first cover.* file encountered. // TODO: make it so it returns the first cover.* file encountered.
// Use glob instead
let png = format!("{}/cover.png", download_fold); let png = format!("{}/cover.png", download_fold);
let jpg = format!("{}/cover.jpg", download_fold); let jpg = format!("{}/cover.jpg", download_fold);
let jpe = format!("{}/cover.jpe", download_fold); let jpe = format!("{}/cover.jpe", download_fold);

View File

@ -8,7 +8,6 @@ extern crate hyper;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate mime_guess; extern crate mime_guess;
extern crate rand;
extern crate reqwest; extern crate reqwest;
extern crate tempdir; extern crate tempdir;