Add support for returning file hashes on search

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/9/head
trivernis 2 years ago
parent b52c28e31e
commit 2b5599b821
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -22,8 +22,8 @@ use crate::api_core::managing_pages::{
GetPages, GetPagesResponse,
};
use crate::api_core::searching_and_fetching_files::{
FileMetadata, FileMetadataResponse, FileSearchOptions, GetFile, SearchFiles,
SearchFilesResponse, SearchQueryEntry,
FileMetadata, FileMetadataResponse, FileSearchOptions, GetFile, SearchFileHashes,
SearchFileHashesResponse, SearchFiles, SearchFilesResponse, SearchQueryEntry,
};
use crate::api_core::Endpoint;
use crate::error::{Error, Result};
@ -241,7 +241,7 @@ impl Client {
Ok(())
}
/// Searches for files in the inbox, the archive or both
/// Searches for files
#[tracing::instrument(skip(self), level = "debug")]
pub async fn search_files(
&self,
@ -254,6 +254,20 @@ impl Client {
.await
}
/// Searches for file hashes
#[tracing::instrument(skip(self), level = "debug")]
pub async fn search_file_hashes(
&self,
query: Vec<SearchQueryEntry>,
options: FileSearchOptions,
) -> Result<SearchFileHashesResponse> {
let mut args = options.into_query_args();
args.push(("tags", search_query_list_to_json_array(query)));
args.push(("return_hashes", String::from("true")));
self.get_and_parse::<SearchFileHashes, [(&str, String)]>(&args)
.await
}
/// Returns the metadata for a given list of file_ids or hashes
#[tracing::instrument(skip(self), level = "debug")]
pub async fn get_file_metadata(

@ -112,6 +112,22 @@ impl Endpoint for SearchFiles {
}
}
#[derive(Clone, Debug, Deserialize)]
pub struct SearchFileHashesResponse {
pub hashes: Vec<String>,
}
pub struct SearchFileHashes;
impl Endpoint for SearchFileHashes {
type Request = ();
type Response = SearchFileHashesResponse;
fn path() -> String {
String::from("get_files/search_files")
}
}
#[derive(Clone, Debug, Default, Deserialize)]
pub struct FileMetadataResponse {
pub metadata: Vec<FileMetadataInfo>,

@ -22,6 +22,25 @@ async fn is_searches_files() {
.unwrap();
}
#[tokio::test]
async fn is_searches_file_hashes() {
let client = common::get_client();
let options = FileSearchOptions::new()
.sort_type(SORT_FILE_PIXEL_COUNT)
.tag_service_name("my tags")
.file_service_name("all known files");
client
.search_file_hashes(
vec![
"beach".into(),
SearchQueryEntry::OrChain(vec!["summer".to_string(), "winter".to_string()]),
],
options,
)
.await
.unwrap();
}
#[tokio::test]
async fn it_fetches_file_metadata() {
let client = common::get_client();

Loading…
Cancel
Save