From b3a885de282ace92b5c0d215d42c1ee17d5ade0a Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 8 Aug 2025 15:06:43 -0400 Subject: [PATCH] Run cargo fmt --- src/data/mod.rs | 4 ++-- src/files.rs | 50 ++++++++++++++++++++++++++++++++++----------- src/state.rs | 12 +++++------ src/tags.rs | 46 ++++++++++++++++++++++++++++++++--------- src/video/ffmpeg.rs | 4 ++-- src/video/mod.rs | 11 +++++----- 6 files changed, 89 insertions(+), 38 deletions(-) diff --git a/src/data/mod.rs b/src/data/mod.rs index 4be379d..30da4e3 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -137,9 +137,9 @@ pub enum PhotoSize { #[derive(Debug, Deserialize)] pub struct ThumbnailRequest { pub(crate) path: String, - pub(crate)size: Option, + pub(crate) size: Option, #[serde(default)] - pub(crate)format: Option, + pub(crate) format: Option, } #[derive(Debug, Deserialize, PartialEq)] diff --git a/src/files.rs b/src/files.rs index b71b0c3..8f996cd 100644 --- a/src/files.rs +++ b/src/files.rs @@ -516,9 +516,9 @@ mod tests { use crate::database::test::in_memory_db_connection; use crate::tags::SqliteTagDao; + use actix_web::test::TestRequest; use actix_web::web::Data; use std::{fs, sync::Arc}; - use actix_web::test::TestRequest; fn setup() { let _ = env_logger::builder().is_test(true).try_init(); @@ -609,12 +609,22 @@ mod tests { let mut tag_dao = SqliteTagDao::new(in_memory_db_connection()); - let tag1 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag1").unwrap(); - let _tag2 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag2").unwrap(); - let tag3 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag3").unwrap(); + let tag1 = tag_dao + .create_tag(&opentelemetry::Context::current(), "tag1") + .unwrap(); + let _tag2 = tag_dao + .create_tag(&opentelemetry::Context::current(), "tag2") + .unwrap(); + let tag3 = tag_dao + .create_tag(&opentelemetry::Context::current(), "tag3") + .unwrap(); - let _ = &tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", tag1.id).unwrap(); - let _ = &tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id).unwrap(); + let _ = &tag_dao + .tag_file(&opentelemetry::Context::current(), "test.jpg", tag1.id) + .unwrap(); + let _ = &tag_dao + .tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id) + .unwrap(); let mut files = HashMap::new(); files.insert( @@ -654,15 +664,31 @@ mod tests { let mut tag_dao = SqliteTagDao::new(in_memory_db_connection()); - let tag1 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag1").unwrap(); - let _tag2 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag2").unwrap(); - let tag3 = tag_dao.create_tag(&opentelemetry::Context::current(), "tag3").unwrap(); + let tag1 = tag_dao + .create_tag(&opentelemetry::Context::current(), "tag1") + .unwrap(); + let _tag2 = tag_dao + .create_tag(&opentelemetry::Context::current(), "tag2") + .unwrap(); + let tag3 = tag_dao + .create_tag(&opentelemetry::Context::current(), "tag3") + .unwrap(); - let _ = &tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", tag1.id).unwrap(); - let _ = &tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id).unwrap(); + let _ = &tag_dao + .tag_file(&opentelemetry::Context::current(), "test.jpg", tag1.id) + .unwrap(); + let _ = &tag_dao + .tag_file(&opentelemetry::Context::current(), "test.jpg", tag3.id) + .unwrap(); // Should get filtered since it doesn't have tag3 - tag_dao.tag_file(&opentelemetry::Context::current(), "some-other.jpg", tag1.id).unwrap(); + tag_dao + .tag_file( + &opentelemetry::Context::current(), + "some-other.jpg", + tag1.id, + ) + .unwrap(); let mut files = HashMap::new(); files.insert( diff --git a/src/state.rs b/src/state.rs index 0853787..b633a4d 100644 --- a/src/state.rs +++ b/src/state.rs @@ -32,7 +32,6 @@ impl AppState { gif_path, } } - } impl Default for AppState { @@ -64,10 +63,10 @@ impl AppState { // Create the AppState with the temporary paths AppState::new( std::sync::Arc::new(crate::video::actors::StreamActor {}.start()), - base_path.to_string_lossy().to_string(), - thumbnail_path.to_string_lossy().to_string(), - video_path.to_string_lossy().to_string(), - gif_path.to_string_lossy().to_string(), + base_path.to_string_lossy().to_string(), + thumbnail_path.to_string_lossy().to_string(), + video_path.to_string_lossy().to_string(), + gif_path.to_string_lossy().to_string(), ) } } @@ -76,7 +75,6 @@ impl AppState { #[cfg(test)] fn create_test_subdir(base_path: &std::path::Path, name: &str) -> std::path::PathBuf { let dir_path = base_path.join(name); - std::fs::create_dir_all(&dir_path) - .expect(&format!("Failed to create {} directory", name)); + std::fs::create_dir_all(&dir_path).expect(&format!("Failed to create {} directory", name)); dir_path } diff --git a/src/tags.rs b/src/tags.rs index 276ffdb..3a8cb60 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -552,8 +552,8 @@ impl TagDao for SqliteTagDao { #[cfg(test)] mod tests { - use actix_web::web::{Data, Json}; use actix_web::test::TestRequest; + use actix_web::web::{Data, Json}; use std::{cell::RefCell, collections::HashMap}; use diesel::result::Error::NotFound; @@ -724,7 +724,9 @@ mod tests { add_tag(claims, request, web::Json(body), tag_data.clone()).await; let mut tag_dao = tag_data.lock().unwrap(); - let tags = tag_dao.get_all_tags(&opentelemetry::Context::current(), None).unwrap(); + let tags = tag_dao + .get_all_tags(&opentelemetry::Context::current(), None) + .unwrap(); assert_eq!(tags.len(), 1); assert_eq!(tags.first().unwrap().1.name, "test-tag"); let tagged_photos = tag_dao.tagged_photos.borrow(); @@ -747,11 +749,19 @@ mod tests { let tag_data = Data::new(Mutex::new(tag_dao)); let request = TestRequest::default().to_http_request(); - add_tag(claims.clone(), request.clone(), web::Json(add_request), tag_data.clone()).await; + add_tag( + claims.clone(), + request.clone(), + web::Json(add_request), + tag_data.clone(), + ) + .await; remove_tagged_photo(claims, request, web::Json(remove_request), tag_data.clone()).await; let mut tag_dao = tag_data.lock().unwrap(); - let tags = tag_dao.get_all_tags(&opentelemetry::Context::current(), None).unwrap(); + let tags = tag_dao + .get_all_tags(&opentelemetry::Context::current(), None) + .unwrap(); assert!(tags.is_empty()); let tagged_photos = tag_dao.tagged_photos.borrow(); let previously_added_tagged_photo = tagged_photos.get("test.png").unwrap(); @@ -761,12 +771,22 @@ mod tests { #[actix_rt::test] async fn replace_tags_keeps_existing_tags_removes_extras_adds_missing_test() { let mut tag_dao = TestTagDao::new(); - let new_tag = tag_dao.create_tag(&opentelemetry::Context::current(), "Test").unwrap(); - let new_tag2 = tag_dao.create_tag(&opentelemetry::Context::current(), "Test2").unwrap(); - let _ = tag_dao.create_tag(&opentelemetry::Context::current(), "Test3").unwrap(); + let new_tag = tag_dao + .create_tag(&opentelemetry::Context::current(), "Test") + .unwrap(); + let new_tag2 = tag_dao + .create_tag(&opentelemetry::Context::current(), "Test2") + .unwrap(); + let _ = tag_dao + .create_tag(&opentelemetry::Context::current(), "Test3") + .unwrap(); - tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", new_tag.id).unwrap(); - tag_dao.tag_file(&opentelemetry::Context::current(), "test.jpg", new_tag2.id).unwrap(); + tag_dao + .tag_file(&opentelemetry::Context::current(), "test.jpg", new_tag.id) + .unwrap(); + tag_dao + .tag_file(&opentelemetry::Context::current(), "test.jpg", new_tag2.id) + .unwrap(); let claims = Claims::valid_user(String::from("1")); let tag_data = Data::new(Mutex::new(tag_dao)); @@ -777,7 +797,13 @@ mod tests { }; let request = TestRequest::default().to_http_request(); - update_tags(claims, tag_data.clone(), request, web::Json(add_tags_request)).await; + update_tags( + claims, + tag_data.clone(), + request, + web::Json(add_tags_request), + ) + .await; let tag_dao = tag_data.lock().unwrap(); let tags_for_test_photo = &tag_dao.tagged_photos.borrow()["test.jpg"]; diff --git a/src/video/ffmpeg.rs b/src/video/ffmpeg.rs index d678153..4722115 100644 --- a/src/video/ffmpeg.rs +++ b/src/video/ffmpeg.rs @@ -1,6 +1,6 @@ use futures::TryFutureExt; use log::{debug, error, info, warn}; -use std::io::{Result}; +use std::io::Result; use std::process::{Output, Stdio}; use std::time::Instant; use tokio::process::Command; @@ -182,4 +182,4 @@ impl Ffmpeg { Ok(output.status.code().unwrap_or(-1)) } -} \ No newline at end of file +} diff --git a/src/video/mod.rs b/src/video/mod.rs index 0d64712..9889243 100644 --- a/src/video/mod.rs +++ b/src/video/mod.rs @@ -1,10 +1,10 @@ use crate::otel::global_tracer; use crate::video::ffmpeg::{Ffmpeg, GifType}; use crate::{is_video, update_media_counts}; -use log::{info}; -use opentelemetry::trace::{Tracer}; +use log::info; +use opentelemetry::trace::Tracer; +use std::fs; use std::path::{Path, PathBuf}; -use std::{fs}; use walkdir::WalkDir; pub mod actors; @@ -43,8 +43,9 @@ pub async fn generate_video_gifs() { let gif_path = Path::new(gif_directory).join(relative_path); let gif_path = gif_path.with_extension("gif"); if let Some(parent_dir) = gif_path.parent() { - fs::create_dir_all(parent_dir).unwrap_or_else(|_| panic!("There was an issue creating gif directory {:?}", - gif_path)); + fs::create_dir_all(parent_dir).unwrap_or_else(|_| { + panic!("There was an issue creating gif directory {:?}", gif_path) + }); } info!("Generating gif for {:?}", path);