From d3b4093f9391a471595839950785de035db2f6f0 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 11 Jul 2021 20:54:43 +0200 Subject: [PATCH] Add retrieval of its bytes to the file struct Signed-off-by: trivernis --- src/models/hydrus_file.rs | 7 ++++++- tests/wrapper/test_files.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/models/hydrus_file.rs b/src/models/hydrus_file.rs index e128c8e..51abc5a 100644 --- a/src/models/hydrus_file.rs +++ b/src/models/hydrus_file.rs @@ -1,5 +1,5 @@ use crate::endpoints::adding_tags::{AddTagsRequestBuilder, TagAction}; -use crate::endpoints::common::{FileIdentifier, FileMetadataInfo}; +use crate::endpoints::common::{FileIdentifier, FileMetadataInfo, FileRecord}; use crate::error::Result; use crate::service::ServiceName; use crate::tag::Tag; @@ -177,4 +177,9 @@ impl HydrusFile { self.client.add_tags(reqwest.build()).await } + + /// Retrieves the file record bytes + pub async fn retrieve(&self) -> Result { + self.client.get_file(self.id.clone()).await + } } diff --git a/tests/wrapper/test_files.rs b/tests/wrapper/test_files.rs index 73291f6..1fccbc4 100644 --- a/tests/wrapper/test_files.rs +++ b/tests/wrapper/test_files.rs @@ -72,3 +72,11 @@ async fn it_modifies_tags() { .await .unwrap(); } + +#[tokio::test] +async fn it_retrieves_content() { + let file = get_file().await; + let file = file.retrieve().await.unwrap(); + + assert!(file.bytes.len() > 0) // assuming it exists +}