diff --git a/src/services/authorization.rs b/src/services/authorization.rs index 9419b216..4f85800c 100644 --- a/src/services/authorization.rs +++ b/src/services/authorization.rs @@ -47,6 +47,7 @@ pub enum ACTION { GetPublicSettings, GetTorrent, AddTorrent, + GetCanonicalInfoHash, } pub struct Service { @@ -188,18 +189,21 @@ impl CasbinConfiguration { admin, GetImageByUrl admin, GetTorrent admin, AddTorrent + admin, GetCanonicalInfoHash registered, GetCategories registered, GetImageByUrl registered, GetPublicSettings registered, GetTags registered, GetTorrent registered, AddTorrent + registered, GetCanonicalInfoHash guest, GetCategories guest, GetTags guest, GetAboutPage guest, GetLicensePage guest, GetPublicSettings guest, GetTorrent + guest, GetCanonicalInfoHash ", ), } diff --git a/src/services/torrent.rs b/src/services/torrent.rs index 5d5464b9..23695684 100644 --- a/src/services/torrent.rs +++ b/src/services/torrent.rs @@ -547,6 +547,26 @@ impl Index { Ok(torrent_response) } + + /// It returns the canonical info-hash. + /// + /// # Errors + /// + /// Returns an error if the user is not is there was a problem with the database. + pub async fn get_canonical_info_hash( + &self, + info_hash: &InfoHash, + opt_user_id: Option, + ) -> Result, ServiceError> { + self.authorization_service + .authorize(ACTION::GetCanonicalInfoHash, opt_user_id) + .await?; + + self.torrent_info_hash_repository + .find_canonical_info_hash_for(info_hash) + .await + .map_err(|_| ServiceError::DatabaseError) + } } pub struct DbTorrentRepository {