summaryrefslogtreecommitdiff
path: root/src/types
diff options
context:
space:
mode:
Diffstat (limited to 'src/types')
-rw-r--r--src/types/extract.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/types/extract.rs b/src/types/extract.rs
index f05215f..a76eac4 100644
--- a/src/types/extract.rs
+++ b/src/types/extract.rs
@@ -9,7 +9,7 @@ use axum::{
extract::{ConnectInfo, FromRequest, FromRequestParts},
http::{header::USER_AGENT, request::Parts, Request},
response::Response,
- BoxError, RequestExt,
+ BoxError, RequestExt, middleware::Next,
};
use bytes::Bytes;
use image::{io::Reader, DynamicImage, ImageFormat};
@@ -100,7 +100,7 @@ where
};
let Some(db) = parts.extensions.get::<DatabaseExtention>() else {
- return Err(ResponseCode::Forbidden.text("Could not connect to database"))
+ return Err(ResponseCode::InternalServerError.text("Could not connect to database"))
};
let db = db.0.lock().await;
@@ -288,6 +288,18 @@ where
}
}
+pub async fn connect<B>(mut req: Request<B>, next: Next<B>) -> Response
+where
+ B: Send,
+{
+ if let Ok(db) = database::Database::connect() {
+ let ex = DatabaseExtention(Mutex::new(db));
+ req.extensions_mut().insert(ex);
+ }
+
+ next.run(req).await
+}
+
async fn read_body<S, B>(mut req: Request<B>, state: &S) -> Result<Vec<u8>>
where
B: HttpBody + Sync + Send + 'static,