From 2dec625c07b8c42b7af318c7a4774b79d867a2e7 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 21 Dec 2023 11:02:04 +0100 Subject: [PATCH] Update API definitions --- Cargo.toml | 4 ++-- src/api_core/common.rs | 15 +++++++++++++++ src/api_core/endpoints/access_management.rs | 10 ++++++++-- .../endpoints/searching_and_fetching_files.rs | 14 ++++++++++++-- src/wrapper/hydrus_file.rs | 8 ++++---- src/wrapper/service.rs | 2 +- tests/client/test_access_management.rs | 2 +- tests/client/test_adding_tags.rs | 2 +- tests/client/test_searching_and_fetching_files.rs | 2 +- tests/wrapper/test_files.rs | 2 +- 10 files changed, 46 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2d11104..663c817 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydrus-api" -version = "0.9.3" +version = "0.10.0" authors = ["trivernis "] edition = "2018" license = "Apache-2.0" @@ -36,4 +36,4 @@ features = ["macros", "rt-multi-thread"] default = ["json"] rustls = ["reqwest/rustls"] cbor = ["ciborium", "base64"] -json = ["serde_json"] \ No newline at end of file +json = ["serde_json"] diff --git a/src/api_core/common.rs b/src/api_core/common.rs index 4a227d5..4ec6fd4 100644 --- a/src/api_core/common.rs +++ b/src/api_core/common.rs @@ -6,6 +6,17 @@ use std::collections::HashMap; pub struct BasicServiceInfo { pub name: String, pub service_key: String, + #[serde(alias = "type")] + pub service_type: u64, + pub type_pretty: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServiceItem { + pub name: String, + #[serde(alias = "type")] + pub service_type: u64, + pub type_pretty: String, } impl BasicServiceInfo { @@ -200,6 +211,10 @@ pub struct FileMetadataServices { #[derive(Clone, Debug, Deserialize)] pub struct FileMetadataServiceCurrent { + pub name: String, + #[serde(alias = "type")] + pub service_type: u64, + pub type_pretty: String, pub time_imported: u64, } diff --git a/src/api_core/endpoints/access_management.rs b/src/api_core/endpoints/access_management.rs index 1e2f275..0339c57 100644 --- a/src/api_core/endpoints/access_management.rs +++ b/src/api_core/endpoints/access_management.rs @@ -1,4 +1,4 @@ -use crate::api_core::common::BasicServiceInfo; +use crate::api_core::common::{BasicServiceInfo, ServiceItem}; use crate::api_core::endpoints::Endpoint; use std::collections::HashMap; @@ -62,7 +62,13 @@ impl Endpoint for VerifyAccessKey { } #[derive(Debug, Clone, Deserialize)] -pub struct GetServicesResponse(pub HashMap>); +pub struct GetServicesResponse { + pub services: HashMap, + pub version: u64, + pub hydrus_version: u64, + #[serde(flatten)] + pub other: HashMap>, +} pub struct GetServices; diff --git a/src/api_core/endpoints/searching_and_fetching_files.rs b/src/api_core/endpoints/searching_and_fetching_files.rs index 0faac7b..94b2d9b 100644 --- a/src/api_core/endpoints/searching_and_fetching_files.rs +++ b/src/api_core/endpoints/searching_and_fetching_files.rs @@ -207,8 +207,18 @@ pub struct FileFullMetadata { pub is_trashed: bool, pub file_services: FileMetadataServices, pub known_urls: Vec, - pub service_keys_to_statuses_to_tags: HashMap>>, - pub service_keys_to_statuses_to_display_tags: HashMap>>, + /// map of service keys to tags + pub tags: HashMap, +} + +#[derive(Clone, Debug, Default, Deserialize)] +pub struct ServiceTags { + pub name: String, + #[serde(alias = "type")] + pub service_type: u64, + pub type_pretty: String, + pub storage_tags: HashMap>, + pub display_tags: HashMap>, } pub trait FileMetadataType: Clone + Debug { diff --git a/src/wrapper/hydrus_file.rs b/src/wrapper/hydrus_file.rs index a81406f..5222c70 100644 --- a/src/wrapper/hydrus_file.rs +++ b/src/wrapper/hydrus_file.rs @@ -295,10 +295,10 @@ impl HydrusFile { let metadata = self.metadata().await?; let mut tag_mappings = HashMap::new(); - for (service, status_tags) in &metadata.service_keys_to_statuses_to_tags { + for (service, service_tags) in &metadata.tags { let mut tag_list = Vec::new(); - for (_, tags) in status_tags { + for (_, tags) in &service_tags.storage_tags { tag_list.append(&mut tags.into_iter().map(|t| t.into()).collect()) } tag_mappings.insert(ServiceIdentifier::Key(service.clone()), tag_list); @@ -312,10 +312,10 @@ impl HydrusFile { let metadata = self.metadata().await?; let mut tag_mappings = HashMap::new(); - for (service, status_tags) in &metadata.service_keys_to_statuses_to_tags { + for (service, service_tags) in &metadata.tags { let mut tag_list = Vec::new(); - for (_, tags) in status_tags { + for (_, tags) in &service_tags.storage_tags { tag_list.append(&mut tags.into_iter().map(|t| t.into()).collect()) } tag_mappings.insert(ServiceIdentifier::Key(service.clone()), tag_list); diff --git a/src/wrapper/service.rs b/src/wrapper/service.rs index 87664f7..462c4b6 100644 --- a/src/wrapper/service.rs +++ b/src/wrapper/service.rs @@ -135,7 +135,7 @@ pub struct Services { impl Services { /// Creates the services list from a given hydrus response pub fn from_response(client: Client, response: GetServicesResponse) -> Self { - let mut response = response.0; + let mut response = response.other; let mut mapped_types = HashMap::with_capacity(response.keys().len()); let keys = response.keys().cloned().collect::>().clone(); diff --git a/tests/client/test_access_management.rs b/tests/client/test_access_management.rs index 0ff5101..7f7df6a 100644 --- a/tests/client/test_access_management.rs +++ b/tests/client/test_access_management.rs @@ -27,5 +27,5 @@ async fn it_verifies_the_access_key() { async fn it_returns_a_list_of_services() { let client = common::get_client(); let services_response = client.get_services().await.unwrap(); - assert!(services_response.0.keys().len() > 0); + assert!(services_response.other.keys().len() > 0); } diff --git a/tests/client/test_adding_tags.rs b/tests/client/test_adding_tags.rs index 65e5f21..409df96 100644 --- a/tests/client/test_adding_tags.rs +++ b/tests/client/test_adding_tags.rs @@ -49,7 +49,7 @@ async fn it_searches_for_tags() { "*", TagSearchOptions::default() .display_type(TagDisplayType::Display) - .tag_service(ServiceIdentifier::name("public tag repository")), + .tag_service(ServiceIdentifier::name("all known tags")), ) .await .unwrap(); diff --git a/tests/client/test_searching_and_fetching_files.rs b/tests/client/test_searching_and_fetching_files.rs index 3090a8a..02bcf44 100644 --- a/tests/client/test_searching_and_fetching_files.rs +++ b/tests/client/test_searching_and_fetching_files.rs @@ -52,7 +52,7 @@ async fn it_fetches_file_metadata() { client .get_file_metadata::( vec![], - vec!["0000000000000000000000000000000000000000000000000000000000000000".to_string()], + vec!["9641a590e66d9f2e5137b6bcba07fdf6cec3ffaa54de2565c3afcc2125ad1160".to_string()], ) .await .unwrap(); diff --git a/tests/wrapper/test_files.rs b/tests/wrapper/test_files.rs index ee2699c..a34a354 100644 --- a/tests/wrapper/test_files.rs +++ b/tests/wrapper/test_files.rs @@ -70,7 +70,7 @@ async fn it_modifies_tags() { let mut file = get_file().await; file.modify_tags( ServiceName::my_tags().into(), - TagAction::RescindPendFromRepository, + TagAction::DeleteFromLocalService, vec!["ark mage".into()], ) .await