diff --git a/src/app.rs b/src/app.rs index f5131c23..871e6e27 100644 --- a/src/app.rs +++ b/src/app.rs @@ -101,7 +101,10 @@ pub async fn run(configuration: Configuration, api_version: &Version) -> Running authorization_service.clone(), )); let tag_service = Arc::new(tag::Service::new(tag_repository.clone(), authorization_service.clone())); - let proxy_service = Arc::new(proxy::Service::new(image_cache_service.clone(), user_repository.clone())); + let proxy_service = Arc::new(proxy::Service::new( + image_cache_service.clone(), + authorization_service.clone(), + )); let settings_service = Arc::new(settings::Service::new(configuration.clone(), authorization_service.clone())); let torrent_index = Arc::new(torrent::Index::new( configuration.clone(), diff --git a/src/services/proxy.rs b/src/services/proxy.rs index 7ac2a475..b0facbc8 100644 --- a/src/services/proxy.rs +++ b/src/services/proxy.rs @@ -10,21 +10,21 @@ use std::sync::Arc; use bytes::Bytes; +use super::authorization::{self, ACTION}; use crate::cache::image::manager::{Error, ImageCacheService}; use crate::models::user::UserId; -use crate::services::user::Repository; pub struct Service { image_cache_service: Arc, - user_repository: Arc>, + authorization_service: Arc, } impl Service { #[must_use] - pub fn new(image_cache_service: Arc, user_repository: Arc>) -> Self { + pub fn new(image_cache_service: Arc, authorization_service: Arc) -> Self { Self { image_cache_service, - user_repository, + authorization_service, } } @@ -39,8 +39,11 @@ impl Service { /// * The image is too big. /// * The user quota is met. pub async fn get_image_by_url(&self, url: &str, user_id: &UserId) -> Result { - let user = self.user_repository.get_compact(user_id).await.ok(); + self.authorization_service + .authorize(ACTION::GetImageByUrl, Some(*user_id)) + .await + .map_err(|_| Error::Unauthenticated)?; - self.image_cache_service.get_image_by_url(url, user).await + self.image_cache_service.get_image_by_url(url, *user_id).await } }