From 2318a33f9b359ae27b52cd9a19db1f6782d8dae3 Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 1 Aug 2024 22:50:28 +0300 Subject: Upgrade dependencies and fix deprecated functionality I think I managed to not lose any functionality from my dependencies. sqlparser remains unupgraded, but that's mostly because it is only used in one example and it's not worth it to upgrade right now. --- src/micropub/mod.rs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src/micropub/mod.rs') diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs index fc5dd10..63b81c5 100644 --- a/src/micropub/mod.rs +++ b/src/micropub/mod.rs @@ -5,12 +5,12 @@ use std::sync::Arc; use crate::database::{MicropubChannel, Storage, StorageError}; use crate::indieauth::backend::AuthBackend; use crate::indieauth::User; -use crate::media::storage::MediaStore; use crate::micropub::util::form_to_mf2_json; -use axum::extract::{BodyStream, FromRef, Host, Query, State}; -use axum::headers::ContentType; +use axum::extract::{FromRef, Host, Query, State}; +use axum::body::Body as BodyStream; +use axum_extra::headers::ContentType; use axum::response::{IntoResponse, Response}; -use axum::TypedHeader; +use axum_extra::TypedHeader; use axum::http::StatusCode; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -136,10 +136,10 @@ async fn background_processing( // TODO parse link headers let links = response .headers() - .get_all(hyper::http::header::LINK) + .get_all(reqwest::header::LINK) .iter() .cloned() - .collect::>(); + .collect::>(); let html = response.text().await; if html.is_err() { return None; @@ -330,9 +330,9 @@ pub(crate) async fn _post( IntoResponse::into_response((StatusCode::ACCEPTED, [("Location", uid.as_str())])); #[cfg(not(tokio_unstable))] - jobset.lock().await.spawn(background_processing(db, mf2, http)); + let _ = jobset.lock().await.spawn(background_processing(db, mf2, http)); #[cfg(tokio_unstable)] - jobset.lock().await.build_task() + let _ = jobset.lock().await.build_task() .name(format!("Kittybox background processing for post {}", uid.as_str()).as_str()) .spawn(background_processing(db, mf2, http)); @@ -459,7 +459,7 @@ enum PostBody { #[tracing::instrument] async fn dispatch_body( - mut body: BodyStream, + body: BodyStream, content_type: ContentType, ) -> Result { let body: Vec = { @@ -467,6 +467,7 @@ async fn dispatch_body( use tokio_stream::StreamExt; let mut buf = Vec::default(); + let mut body = body.into_data_stream(); while let Some(chunk) = body.next().await { buf.extend_from_slice(&chunk.unwrap()) } @@ -673,7 +674,7 @@ where { axum::routing::get(query::) .post(post::) - .layer::<_, _, std::convert::Infallible>(tower_http::cors::CorsLayer::new() + .layer::<_, _>(tower_http::cors::CorsLayer::new() .allow_methods([ axum::http::Method::GET, axum::http::Method::POST, @@ -704,7 +705,8 @@ mod tests { use std::sync::Arc; use crate::{database::Storage, micropub::MicropubError}; - use hyper::body::HttpBody; + use bytes::Bytes; + use futures::StreamExt; use serde_json::json; use tokio::sync::Mutex; @@ -861,7 +863,15 @@ mod tests { .await; assert_eq!(res.status(), 401); - let body = res.body_mut().data().await.unwrap().unwrap(); + let body = res + .into_body() + .into_data_stream() + .collect::>>() + .await + .into_iter() + .map(Result::unwrap) + .by_ref() + .fold(Vec::new(), |mut a, i| { a.extend(i); a}); let json: MicropubError = serde_json::from_slice(&body as &[u8]).unwrap(); assert_eq!(json.error, super::ErrorType::NotAuthorized); } -- cgit 1.4.1