From 313bd98ae6c9c3bdf430b46d7ee3a1c952862c3b Mon Sep 17 00:00:00 2001 From: Scott Lyons Date: Sun, 11 Aug 2024 00:47:48 -0700 Subject: [PATCH] fix(client): fixing reverse image search --- szurubooru-client/src/client.rs | 11 +++++++---- szurubooru-integration-test/src/main.rs | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/szurubooru-client/src/client.rs b/szurubooru-client/src/client.rs index 4abf15f..4359654 100644 --- a/szurubooru-client/src/client.rs +++ b/szurubooru-client/src/client.rs @@ -835,10 +835,13 @@ impl<'a> SzurubooruRequest<'a> { pub async fn reverse_search_file( &self, file: &mut File, + file_path: impl AsRef, ) -> SzurubooruResult { let request = self.prep_request(Method::POST, "/posts/reverse-search", None); - let image_part = self.part_from_file(file)?; + let image_part = self + .part_from_file(file)? + .file_name(file_path.as_ref().to_string()); let form = Form::new().part("content", image_part); self.handle_request(request.multipart(form)).await @@ -849,9 +852,9 @@ impl<'a> SzurubooruRequest<'a> { &self, file_path: impl AsRef, ) -> SzurubooruResult { - let mut file = File::open(file_path).map_err(SzurubooruClientError::IOError)?; - - self.reverse_search_file(&mut file).await + let mut file = File::open(&file_path).map_err(SzurubooruClientError::IOError)?; + let filename = file_path.as_ref().file_name().unwrap().to_str().unwrap(); + self.reverse_search_file(&mut file, filename).await } /// Searches for an exact match of a file based on the SHA1 checksum diff --git a/szurubooru-integration-test/src/main.rs b/szurubooru-integration-test/src/main.rs index 57cf96a..fa337ea 100644 --- a/szurubooru-integration-test/src/main.rs +++ b/szurubooru-integration-test/src/main.rs @@ -404,6 +404,14 @@ async fn test_creating_posts(client: &SzurubooruClient) { .expect("Could not search for post by file path"); assert_eq!(matching_posts.results.first().unwrap(), &folly3_post); + info!("Reverse searching"); + let matching_posts = client + .request() + .reverse_search_file_path(&folly3_path) + .await + .expect("Could not reverse image search"); + assert!(matching_posts.exact_post.is_some()); + info!("Testing temporary upload"); let folly4_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("folly4.jpg"); let folly4_temp_upload = client