diff --git a/src/api_core/common.rs b/src/api_core/common.rs index 56668fa..3b6b3cb 100644 --- a/src/api_core/common.rs +++ b/src/api_core/common.rs @@ -54,7 +54,10 @@ pub struct FileMetadataInfo { pub is_local: bool, pub is_trashed: bool, pub known_urls: Vec, + #[deprecated] pub service_names_to_statuses_to_tags: HashMap>>, + pub service_keys_to_statuses_to_tags: HashMap>>, + #[deprecated] pub service_names_to_statuses_to_display_tags: HashMap>>, pub service_keys_to_statuses_to_display_tags: HashMap>>, } diff --git a/src/lib.rs b/src/lib.rs index 31fd877..3732cf0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,8 @@ //! let files = hydrus.search() //! .add_tag(Tag::from("character:megumin")) //! .add_tag(SystemTagBuilder::new().archive().build()) -//! .add_tag(SystemTagBuilder::new().tag_namespace_as_number("page", Comparator::Equal, 5).negate().build()) +//! .add_tag(SystemTagBuilder::new() +//! .tag_namespace_as_number("page", Comparator::Equal, 5).negate().build()) //! .add_or_chain( //! OrChainBuilder::new() //! .add_tag("summer".into()) diff --git a/src/wrapper/hydrus_file.rs b/src/wrapper/hydrus_file.rs index 1e612db..1021ab6 100644 --- a/src/wrapper/hydrus_file.rs +++ b/src/wrapper/hydrus_file.rs @@ -239,11 +239,15 @@ impl HydrusFile { self.client.disassociate_urls(urls, vec![hash]).await } - /// Returns map mapping lists of tags to services - pub async fn services_with_tags(&mut self) -> Result>> { + /// Returns map mapping lists of tags to services. + /// + /// Deprecation: Use [HydrusFile::services_with_tags] instead. + #[deprecated(note = "Deprecated in the official API. Use services_with_tags instead.")] + pub async fn service_names_with_tags(&mut self) -> Result>> { let metadata = self.metadata().await?; let mut tag_mappings = HashMap::new(); + #[allow(deprecated)] for (service, status_tags) in &metadata.service_names_to_statuses_to_tags { let mut tag_list = Vec::new(); @@ -256,6 +260,23 @@ impl HydrusFile { Ok(tag_mappings) } + /// Returns a mapping with service ids mapped to tags + pub async fn services_with_tags(&mut self) -> Result>> { + let metadata = self.metadata().await?; + let mut tag_mappings = HashMap::new(); + + for (service, status_tags) in &metadata.service_keys_to_statuses_to_tags { + let mut tag_list = Vec::new(); + + for (_, tags) in status_tags { + tag_list.append(&mut tags.into_iter().map(|t| t.into()).collect()) + } + tag_mappings.insert(ServiceIdentifier::Key(service.clone()), tag_list); + } + + Ok(tag_mappings) + } + /// Returns a list of all tags assigned to the file pub async fn tags(&mut self) -> Result> { let mut tag_list = Vec::new();