Skip to content

Commit

Permalink
feat: [#615] new get canonical info hash method
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-nt committed Aug 3, 2024
1 parent 7bb6ff7 commit b3ffc9f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/services/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum ACTION {
GetPublicSettings,
GetTorrent,
AddTorrent,
GetCanonicalInfoHash,
}

pub struct Service {
Expand Down Expand Up @@ -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
",
),
}
Expand Down
20 changes: 20 additions & 0 deletions src/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserId>,
) -> Result<Option<InfoHash>, 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 {
Expand Down

0 comments on commit b3ffc9f

Please sign in to comment.