diff --git a/src/app.rs b/src/app.rs index 270d0589..18cc427f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -56,7 +56,7 @@ pub async fn run(configuration: Configuration) -> Running { auth.clone(), tracker_service.clone(), mailer_service, - image_cache_service + image_cache_service, )); // Start repeating task to import tracker torrent data and updating diff --git a/src/cache/cache.rs b/src/cache/cache.rs index 50f31a77..8573ba0d 100644 --- a/src/cache/cache.rs +++ b/src/cache/cache.rs @@ -154,8 +154,8 @@ mod tests { } #[tokio::test] - async fn given_a_bytes_cache_with_a_capacity_and_entry_size_limit_it_should_allow_adding_new_entries_if_the_limit_is_not_exceeded() { - + async fn given_a_bytes_cache_with_a_capacity_and_entry_size_limit_it_should_allow_adding_new_entries_if_the_limit_is_not_exceeded( + ) { let bytes: Bytes = Bytes::from("abcdef"); let mut bytes_cache = BytesCache::with_capacity_and_entry_size_limit(bytes.len() * 2, bytes.len()).unwrap(); @@ -171,8 +171,8 @@ mod tests { } #[tokio::test] - async fn given_a_bytes_cache_with_a_capacity_and_entry_size_limit_it_should_not_allow_adding_new_entries_if_the_capacity_is_exceeded() { - + async fn given_a_bytes_cache_with_a_capacity_and_entry_size_limit_it_should_not_allow_adding_new_entries_if_the_capacity_is_exceeded( + ) { let bytes: Bytes = Bytes::from("abcdef"); let mut bytes_cache = BytesCache::with_capacity_and_entry_size_limit(bytes.len() * 2 - 1, bytes.len()).unwrap(); diff --git a/src/cache/image/manager.rs b/src/cache/image/manager.rs index 8cc96cec..8a6960a1 100644 --- a/src/cache/image/manager.rs +++ b/src/cache/image/manager.rs @@ -133,7 +133,9 @@ impl ImageCacheService { } async fn get_image_from_url_as_bytes(&self, url: &str) -> Result { - let res = self.reqwest_client.clone() + let res = self + .reqwest_client + .clone() .get(url) .send() .await @@ -171,7 +173,14 @@ impl ImageCacheService { } async fn update_image_cache(&self, url: &str, image_bytes: &Bytes) -> Result<(), Error> { - if self.image_cache.write().await.set(url.to_string(), image_bytes.clone()).await.is_err() { + if self + .image_cache + .write() + .await + .set(url.to_string(), image_bytes.clone()) + .await + .is_err() + { return Err(Error::ImageTooBig); } @@ -181,7 +190,10 @@ impl ImageCacheService { async fn update_user_quota(&self, user: &UserCompact, amount: usize) -> Result<(), Error> { let settings = self.cfg.settings.read().await; - let mut quota = self.user_quotas.read().await + let mut quota = self + .user_quotas + .read() + .await .get(&user.user_id) .cloned() .unwrap_or(ImageCacheQuota::new( @@ -196,5 +208,4 @@ impl ImageCacheService { Ok(()) } - } diff --git a/src/config.rs b/src/config.rs index ddccea13..ad00c711 100644 --- a/src/config.rs +++ b/src/config.rs @@ -76,7 +76,7 @@ pub struct ImageCache { pub capacity: usize, pub entry_size_limit: usize, pub user_quota_period_seconds: u64, - pub user_quota_bytes: usize + pub user_quota_bytes: usize, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -87,7 +87,7 @@ pub struct TorrustConfig { pub auth: Auth, pub database: Database, pub mail: Mail, - pub image_cache: ImageCache + pub image_cache: ImageCache, } impl TorrustConfig { @@ -131,13 +131,12 @@ impl TorrustConfig { capacity: 128_000_000, entry_size_limit: 4_000_000, user_quota_period_seconds: 3600, - user_quota_bytes: 64_000_000 - } + user_quota_bytes: 64_000_000, + }, } } } - #[derive(Debug)] pub struct Configuration { pub settings: RwLock,