style: fmt & clippy processed

This commit is contained in:
VC
2022-08-11 12:29:40 +02:00
parent dab8725f99
commit b11595bfca
10 changed files with 297 additions and 209 deletions

View File

@@ -1,9 +1,9 @@
use std::error::Error;
use crate::ScootalooError;
use reqwest::Url;
use std::error::Error;
use tokio::{
fs::{create_dir_all, File},
io::copy,
fs::{File, create_dir_all},
};
/// Gets and caches Twitter Media inside the determined temp dir
@@ -16,8 +16,21 @@ pub async fn cache_media(u: &str, t: &str) -> Result<String, Box<dyn Error>> {
// create local file
let url = Url::parse(u)?;
let dest_filename = url.path_segments().ok_or_else(|| ScootalooError::new(&format!("Cannot determine the destination filename for {}", u)))?
.last().ok_or_else(|| ScootalooError::new(&format!("Cannot determine the destination filename for {}", u)))?;
let dest_filename = url
.path_segments()
.ok_or_else(|| {
ScootalooError::new(&format!(
"Cannot determine the destination filename for {}",
u
))
})?
.last()
.ok_or_else(|| {
ScootalooError::new(&format!(
"Cannot determine the destination filename for {}",
u
))
})?;
let dest_filepath = format!("{}/{}", t, dest_filename);
@@ -34,20 +47,21 @@ pub async fn cache_media(u: &str, t: &str) -> Result<String, Box<dyn Error>> {
mod tests {
use super::*;
use std::{
path::Path,
fs::remove_dir_all,
};
use std::{fs::remove_dir_all, path::Path};
const TMP_DIR: &'static str = "/tmp/scootaloo_test";
#[tokio::test]
async fn test_cache_media() {
let dest = cache_media("https://forum.nintendojo.fr/styles/prosilver/theme/images/ndfr_casual.png", TMP_DIR).await.unwrap();
let dest = cache_media(
"https://forum.nintendojo.fr/styles/prosilver/theme/images/ndfr_casual.png",
TMP_DIR,
)
.await
.unwrap();
assert!(Path::new(&dest).exists());
remove_dir_all(TMP_DIR).unwrap();
}
}