summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-02-19 21:22:03 -0500
committerOwen Jacobson <owen@grimoire.ca>2025-02-19 21:22:03 -0500
commit74f80d5c11d0a212a545f053bfd4ca160bcedcd8 (patch)
tree764b93d3b5723ee5ecebabba7fff89ea7abf0876 /src
parent8a2b499fc7e00e841c56d23ac41f4d587b728a50 (diff)
Upgrade Axum to 0.8.1.
Diffstat (limited to 'src')
-rw-r--r--src/channel/routes/mod.rs4
-rw-r--r--src/clock.rs1
-rw-r--r--src/event/extract.rs41
-rw-r--r--src/invite/routes/mod.rs4
-rw-r--r--src/message/routes/mod.rs2
-rw-r--r--src/token/extract/cookie.rs1
-rw-r--r--src/token/extract/identity.rs18
-rw-r--r--src/ui/routes/mod.rs6
8 files changed, 59 insertions, 18 deletions
diff --git a/src/channel/routes/mod.rs b/src/channel/routes/mod.rs
index 696bd72..c1ef5cd 100644
--- a/src/channel/routes/mod.rs
+++ b/src/channel/routes/mod.rs
@@ -14,6 +14,6 @@ mod test;
pub fn router() -> Router<App> {
Router::new()
.route("/api/channels", post(post::handler))
- .route("/api/channels/:channel", post(channel::post::handler))
- .route("/api/channels/:channel", delete(channel::delete::handler))
+ .route("/api/channels/{channel}", post(channel::post::handler))
+ .route("/api/channels/{channel}", delete(channel::delete::handler))
}
diff --git a/src/clock.rs b/src/clock.rs
index 242bcdf..acd0df0 100644
--- a/src/clock.rs
+++ b/src/clock.rs
@@ -21,7 +21,6 @@ impl RequestedAt {
}
}
-#[async_trait::async_trait]
impl<S> FromRequestParts<S> for RequestedAt
where
S: Send + Sync,
diff --git a/src/event/extract.rs b/src/event/extract.rs
index e3021e2..4a35937 100644
--- a/src/event/extract.rs
+++ b/src/event/extract.rs
@@ -1,7 +1,7 @@
use std::ops::Deref;
use axum::{
- extract::FromRequestParts,
+ extract::{FromRequestParts, OptionalFromRequestParts},
http::{request::Parts, HeaderName, HeaderValue},
};
use axum_extra::typed_header::TypedHeader;
@@ -44,7 +44,6 @@ where
}
}
-#[async_trait::async_trait]
impl<S, T> FromRequestParts<S> for LastEventId<T>
where
S: Send + Sync,
@@ -53,12 +52,35 @@ where
type Rejection = <TypedHeader<Self> as FromRequestParts<S>>::Rejection;
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
- // This is purely for ergonomics: it allows `RequestedAt` to be extracted
- // without having to wrap it in `Extension<>`. Callers _can_ still do that,
+ // This is purely for ergonomics: it allows `LastEventId` to be extracted
+ // without having to wrap it in `TypedHeader<>`. Callers _can_ still do that,
// but they aren't forced to.
- let TypedHeader(requested_at) = TypedHeader::from_request_parts(parts, state).await?;
+ let header =
+ <TypedHeader<Self> as FromRequestParts<S>>::from_request_parts(parts, state).await?;
- Ok(requested_at)
+ Ok(header.into())
+ }
+}
+
+impl<S, T> OptionalFromRequestParts<S> for LastEventId<T>
+where
+ S: Send + Sync,
+ T: Serialize + DeserializeOwned,
+{
+ type Rejection = <TypedHeader<Self> as FromRequestParts<S>>::Rejection;
+
+ async fn from_request_parts(
+ parts: &mut Parts,
+ state: &S,
+ ) -> Result<Option<Self>, Self::Rejection> {
+ // This is purely for ergonomics: it allows `Option<LastEventId>` to be extracted
+ // without having to wrap it in `TypedHeader<>`. Callers _can_ still do that,
+ // but they aren't forced to.
+ let header =
+ <TypedHeader<Self> as OptionalFromRequestParts<S>>::from_request_parts(parts, state)
+ .await?;
+
+ Ok(header.map(Self::from))
}
}
@@ -71,6 +93,13 @@ impl<T> Deref for LastEventId<T> {
}
}
+impl<T> From<TypedHeader<LastEventId<T>>> for LastEventId<T> {
+ fn from(header: TypedHeader<Self>) -> Self {
+ let TypedHeader(value) = header;
+ value
+ }
+}
+
impl<T> From<T> for LastEventId<T> {
fn from(value: T) -> Self {
Self(value)
diff --git a/src/invite/routes/mod.rs b/src/invite/routes/mod.rs
index 2f7375c..a25dcd9 100644
--- a/src/invite/routes/mod.rs
+++ b/src/invite/routes/mod.rs
@@ -13,6 +13,6 @@ mod test;
pub fn router() -> Router<App> {
Router::new()
.route("/api/invite", post(post::handler))
- .route("/api/invite/:invite", get(invite::get::handler))
- .route("/api/invite/:invite", post(invite::post::handler))
+ .route("/api/invite/{invite}", get(invite::get::handler))
+ .route("/api/invite/{invite}", post(invite::post::handler))
}
diff --git a/src/message/routes/mod.rs b/src/message/routes/mod.rs
index dfe8628..85c192f 100644
--- a/src/message/routes/mod.rs
+++ b/src/message/routes/mod.rs
@@ -5,5 +5,5 @@ use crate::app::App;
mod message;
pub fn router() -> Router<App> {
- Router::new().route("/api/messages/:message", delete(message::delete::handler))
+ Router::new().route("/api/messages/{message}", delete(message::delete::handler))
}
diff --git a/src/token/extract/cookie.rs b/src/token/extract/cookie.rs
index af5787d..df03aea 100644
--- a/src/token/extract/cookie.rs
+++ b/src/token/extract/cookie.rs
@@ -71,7 +71,6 @@ impl Identity {
}
}
-#[async_trait::async_trait]
impl<S> FromRequestParts<S> for Identity
where
S: Send + Sync,
diff --git a/src/token/extract/identity.rs b/src/token/extract/identity.rs
index a69f509..acfd7ae 100644
--- a/src/token/extract/identity.rs
+++ b/src/token/extract/identity.rs
@@ -1,5 +1,5 @@
use axum::{
- extract::{FromRequestParts, State},
+ extract::{FromRequestParts, OptionalFromRequestParts, State},
http::request::Parts,
response::{IntoResponse, Response},
};
@@ -20,7 +20,6 @@ pub struct Identity {
pub login: Login,
}
-#[async_trait::async_trait]
impl FromRequestParts<App> for Identity {
type Rejection = LoginError<Internal>;
@@ -39,6 +38,21 @@ impl FromRequestParts<App> for Identity {
}
}
+impl OptionalFromRequestParts<App> for Identity {
+ type Rejection = LoginError<Internal>;
+
+ async fn from_request_parts(
+ parts: &mut Parts,
+ state: &App,
+ ) -> Result<Option<Self>, Self::Rejection> {
+ match <Self as FromRequestParts<App>>::from_request_parts(parts, state).await {
+ Ok(identity) => Ok(Some(identity)),
+ Err(LoginError::Unauthorized) => Ok(None),
+ Err(other) => Err(other),
+ }
+ }
+}
+
pub enum LoginError<E> {
Failure(E),
Unauthorized,
diff --git a/src/ui/routes/mod.rs b/src/ui/routes/mod.rs
index 48b3f90..7877dba 100644
--- a/src/ui/routes/mod.rs
+++ b/src/ui/routes/mod.rs
@@ -13,14 +13,14 @@ mod setup;
pub fn router(app: &App) -> Router<App> {
[
Router::new()
- .route("/*path", get(path::get::handler))
+ .route("/{*path}", get(path::get::handler))
.route("/setup", get(setup::get::handler)),
Router::new()
.route("/", get(get::handler))
.route("/me", get(me::get::handler))
.route("/login", get(login::get::handler))
- .route("/ch/:channel", get(ch::channel::get::handler))
- .route("/invite/:invite", get(invite::invite::get::handler))
+ .route("/ch/{channel}", get(ch::channel::get::handler))
+ .route("/invite/{invite}", get(invite::invite::get::handler))
.route_layer(middleware::from_fn_with_state(app.clone(), setup_required)),
]
.into_iter()