Update API definitions

develop
trivernis 11 months ago
parent 203815734a
commit 2dec625c07
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -1,6 +1,6 @@
[package]
name = "hydrus-api"
version = "0.9.3"
version = "0.10.0"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
license = "Apache-2.0"

@ -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,
}

@ -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<String, Vec<BasicServiceInfo>>);
pub struct GetServicesResponse {
pub services: HashMap<String, ServiceItem>,
pub version: u64,
pub hydrus_version: u64,
#[serde(flatten)]
pub other: HashMap<String, Vec<BasicServiceInfo>>,
}
pub struct GetServices;

@ -207,8 +207,18 @@ pub struct FileFullMetadata {
pub is_trashed: bool,
pub file_services: FileMetadataServices,
pub known_urls: Vec<String>,
pub service_keys_to_statuses_to_tags: HashMap<String, HashMap<String, Vec<String>>>,
pub service_keys_to_statuses_to_display_tags: HashMap<String, HashMap<String, Vec<String>>>,
/// map of service keys to tags
pub tags: HashMap<String, ServiceTags>,
}
#[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<String, Vec<String>>,
pub display_tags: HashMap<String, Vec<String>>,
}
pub trait FileMetadataType: Clone + Debug {

@ -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);

@ -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::<Vec<String>>().clone();

@ -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);
}

@ -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();

@ -52,7 +52,7 @@ async fn it_fetches_file_metadata() {
client
.get_file_metadata::<FullMetadata>(
vec![],
vec!["0000000000000000000000000000000000000000000000000000000000000000".to_string()],
vec!["9641a590e66d9f2e5137b6bcba07fdf6cec3ffaa54de2565c3afcc2125ad1160".to_string()],
)
.await
.unwrap();

@ -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

Loading…
Cancel
Save