chore (backend-rs): use async HTTP requests
This commit is contained in:
parent
7413866885
commit
40e5bf45bd
3 changed files with 11 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{database::cache, util::http_client};
|
||||
use image::{io::Reader, ImageError, ImageFormat};
|
||||
use isahc::ReadResponseExt;
|
||||
use isahc::AsyncReadResponseExt;
|
||||
use nom_exif::{parse_jpeg_exif, EntryValue, ExifTag};
|
||||
use std::io::Cursor;
|
||||
use tokio::sync::Mutex;
|
||||
|
@ -70,7 +70,7 @@ pub async fn get_image_size_from_url(url: &str) -> Result<ImageSize, Error> {
|
|||
|
||||
tracing::info!("retrieving image from {}", url);
|
||||
|
||||
let mut response = http_client::client()?.get(url)?;
|
||||
let mut response = http_client::client()?.get_async(url).await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
tracing::info!("status: {}", response.status());
|
||||
|
@ -78,7 +78,7 @@ pub async fn get_image_size_from_url(url: &str) -> Result<ImageSize, Error> {
|
|||
return Err(Error::Http(format!("Failed to get image from {}", url)));
|
||||
}
|
||||
|
||||
let image_bytes = response.bytes()?;
|
||||
let image_bytes = response.bytes().await?;
|
||||
|
||||
let reader = Reader::new(Cursor::new(&image_bytes)).with_guessed_format()?;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Fetch latest Firefish version from the Firefish repository
|
||||
|
||||
use crate::{database::cache, util::http_client};
|
||||
use isahc::ReadResponseExt;
|
||||
use isahc::AsyncReadResponseExt;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
|
@ -29,7 +29,9 @@ async fn get_latest_version() -> Result<String, Error> {
|
|||
version: String,
|
||||
}
|
||||
|
||||
let mut response = http_client::client()?.get(UPSTREAM_PACKAGE_JSON_URL)?;
|
||||
let mut response = http_client::client()?
|
||||
.get_async(UPSTREAM_PACKAGE_JSON_URL)
|
||||
.await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
tracing::info!("status: {}", response.status());
|
||||
|
@ -39,7 +41,7 @@ async fn get_latest_version() -> Result<String, Error> {
|
|||
));
|
||||
}
|
||||
|
||||
let res_parsed: Response = serde_json::from_str(&response.text()?)?;
|
||||
let res_parsed: Response = serde_json::from_str(&response.text().await?)?;
|
||||
|
||||
Ok(res_parsed.version)
|
||||
}
|
||||
|
|
|
@ -20,13 +20,13 @@ static CLIENT: OnceCell<HttpClient> = OnceCell::new();
|
|||
/// # Example
|
||||
/// ```no_run
|
||||
/// # use backend_rs::util::http_client::client;
|
||||
/// use isahc::ReadResponseExt;
|
||||
/// use isahc::AsyncReadResponseExt;
|
||||
///
|
||||
/// # fn f() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let mut response = client()?.get("https://example.com/")?;
|
||||
/// let mut response = client()?.get_async("https://example.com/").await?;
|
||||
///
|
||||
/// if response.status().is_success() {
|
||||
/// println!("{}", response.text()?);
|
||||
/// println!("{}", response.text().await?);
|
||||
/// }
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
|
|
Loading…
Reference in a new issue