Fix some lint warning and simplify some code

This commit is contained in:
Cameron Cordes
2021-03-25 13:17:58 -04:00
parent 1539255ae0
commit 31e95dc158
2 changed files with 10 additions and 12 deletions

View File

@@ -144,9 +144,7 @@ pub mod testhelpers {
.user_map .user_map
.borrow() .borrow()
.iter() .iter()
.filter(|u| u.username == user && u.password == pass) .find(|&u| u.username == user && u.password == pass)
.collect::<Vec<&User>>()
.first()
{ {
Some(u) => { Some(u) => {
let copy = (*u).clone(); let copy = (*u).clone();
@@ -160,9 +158,7 @@ pub mod testhelpers {
self.user_map self.user_map
.borrow() .borrow()
.iter() .iter()
.filter(|u| u.username == user) .find(|&u| u.username == user)
.collect::<Vec<&User>>()
.first()
.is_some() .is_some()
} }
} }

View File

@@ -234,9 +234,12 @@ async fn favorites(claims: Claims) -> impl Responder {
async fn post_add_favorite(claims: Claims, body: web::Json<AddFavoriteRequest>) -> impl Responder { async fn post_add_favorite(claims: Claims, body: web::Json<AddFavoriteRequest>) -> impl Responder {
if let Ok(user_id) = claims.sub.parse::<i32>() { if let Ok(user_id) = claims.sub.parse::<i32>() {
let path = body.path.clone(); let path = body.path.clone();
web::block::<_, _, String>(move || Ok(add_favorite(user_id, path))) web::block::<_, _, String>(move || {
.await add_favorite(user_id, path);
.unwrap(); Ok(())
})
.await
.unwrap();
debug!("Adding favorite \"{}\" for userid: {}", user_id, body.path); debug!("Adding favorite \"{}\" for userid: {}", user_id, body.path);
HttpResponse::Ok() HttpResponse::Ok()
} else { } else {
@@ -330,9 +333,8 @@ fn main() -> std::io::Result<()> {
DebouncedEvent::Rename(orig, _) | DebouncedEvent::Write(orig) => { DebouncedEvent::Rename(orig, _) | DebouncedEvent::Write(orig) => {
let image_base_path = PathBuf::from(env::var("BASE_PATH").unwrap()); let image_base_path = PathBuf::from(env::var("BASE_PATH").unwrap());
let image_relative = orig.strip_prefix(&image_base_path).unwrap(); let image_relative = orig.strip_prefix(&image_base_path).unwrap();
if let Ok(old_thumbnail) = env::var("THUMBNAILS") if let Ok(old_thumbnail) =
.map(|base| PathBuf::from(base)) env::var("THUMBNAILS").map(PathBuf::from).map(|mut base| {
.map(|mut base| {
base.push(image_relative); base.push(image_relative);
base base
}) })