fix(client): fixing reverse image search
This commit is contained in:
parent
cbb3449c9f
commit
313bd98ae6
2 changed files with 15 additions and 4 deletions
|
|
@ -835,10 +835,13 @@ impl<'a> SzurubooruRequest<'a> {
|
|||
pub async fn reverse_search_file(
|
||||
&self,
|
||||
file: &mut File,
|
||||
file_path: impl AsRef<str>,
|
||||
) -> SzurubooruResult<ImageSearchResult> {
|
||||
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<Path>,
|
||||
) -> SzurubooruResult<ImageSearchResult> {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue