mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 01:21:19 +02:00
style: fmt & clippy processed
This commit is contained in:
34
src/util.rs
34
src/util.rs
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user