about summary refs log tree commit diff
path: root/src/micropub
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-01 22:50:28 +0300
committerVika <vika@fireburn.ru>2024-08-02 16:13:39 +0300
commit2318a33f9b359ae27b52cd9a19db1f6782d8dae3 (patch)
tree5f4dc1ad73d5c4104679a1976781861ec23cb20e /src/micropub
parent61a6bf6b80aea18d8b7af159d504004a29e50576 (diff)
downloadkittybox-2318a33f9b359ae27b52cd9a19db1f6782d8dae3.tar.zst
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.
Diffstat (limited to 'src/micropub')
-rw-r--r--src/micropub/mod.rs34
1 files changed, 22 insertions, 12 deletions
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<D: 'static + Storage>(
                 // TODO parse link headers
                 let links = response
                     .headers()
-                    .get_all(hyper::http::header::LINK)
+                    .get_all(reqwest::header::LINK)
                     .iter()
                     .cloned()
-                    .collect::<Vec<hyper::http::HeaderValue>>();
+                    .collect::<Vec<reqwest::header::HeaderValue>>();
                 let html = response.text().await;
                 if html.is_err() {
                     return None;
@@ -330,9 +330,9 @@ pub(crate) async fn _post<D: 'static + Storage>(
         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<PostBody, MicropubError> {
     let body: Vec<u8> = {
@@ -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::<S, A>)
         .post(post::<S, A>)
-        .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::<Vec<Result<Bytes, axum::Error>>>()
+            .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);
     }