build(deps): update to axum 0.8, rusqlite 0.33, tokio-tungstenite 0.26, thiserror 2

This commit is contained in:
oxalica 2025-02-11 00:13:56 -05:00
parent b56f8897ff
commit 740e540b4b
9 changed files with 294 additions and 323 deletions

View file

@ -96,7 +96,7 @@ impl WsSenderWrapper<'_, '_> {
let data = serde_json::to_string(&msg).expect("serialization cannot fail");
let fut = tokio::time::timeout(
self.config.send_timeout_sec,
self.inner.send(Message::Text(data)),
self.inner.send(Message::Text(data.into())),
);
match fut.await {
Ok(Ok(())) => Ok(()),

View file

@ -7,7 +7,7 @@ use anyhow::Result;
use axum::body::Bytes;
use axum::extract::{Path, Query, State};
use axum::http::{header, HeaderName, HeaderValue, StatusCode};
use axum::response::{IntoResponse, Response};
use axum::response::{IntoResponse, NoContent, Response};
use axum::routing::MethodRouter;
use axum::{Json, Router};
use axum_extra::extract::WithRejection as R;
@ -24,7 +24,7 @@ use blah_types::{get_timestamp, Id, PubKey, Signed, UserKey};
use data_encoding::BASE64_NOPAD;
use database::{Transaction, TransactionOps};
use id::IdExt;
use middleware::{Auth, ETag, MaybeAuth, NoContent, ResultExt as _, SignedJson};
use middleware::{Auth, ETag, MaybeAuth, ResultExt as _, SignedJson};
use parking_lot::Mutex;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Deserializer, Serialize};
@ -151,7 +151,7 @@ impl AppState {
type ArcState = State<Arc<AppState>>;
pub fn router(st: Arc<AppState>) -> Router {
let r = || MethodRouter::new().fallback(fallback_method_route);
let r = MethodRouter::new;
// NB. Use consistent handler naming: `<method>_<path>[_<details>]`.
// Use prefix `list` for GET with pagination.
@ -165,16 +165,17 @@ pub fn router(st: Arc<AppState>) -> Router {
.route("/room", r().get(list_room).post(post_room))
// TODO!: remove this.
.route("/room/create", r().post(post_room))
.route("/room/:rid", r().get(get_room).delete(delete_room))
.route("/room/:rid/feed.json", r().get(feed::get_room_feed::<feed::JsonFeed>))
.route("/room/:rid/feed.atom", r().get(feed::get_room_feed::<feed::AtomFeed>))
.route("/room/:rid/msg", r().get(list_room_msg).post(post_room_msg))
.route("/room/:rid/msg/:cid/seen", r().post(post_room_msg_seen))
.route("/room/{rid}", r().get(get_room).delete(delete_room))
.route("/room/{rid}/feed.json", r().get(feed::get_room_feed::<feed::JsonFeed>))
.route("/room/{rid}/feed.atom", r().get(feed::get_room_feed::<feed::AtomFeed>))
.route("/room/{rid}/msg", r().get(list_room_msg).post(post_room_msg))
.route("/room/{rid}/msg/{cid}/seen", r().post(post_room_msg_seen))
// TODO!: remove this.
.route("/room/:rid/admin", r().post(post_room_admin))
.route("/room/:rid/member", r().get(list_room_member).post(post_room_member))
.route("/room/:rid/member/:idkey", r().get(get_room_member).delete(delete_room_member).patch(patch_room_member))
.route("/room/:rid/member/:idkey/identity", r().get(get_room_member_identity))
.route("/room/{rid}/admin", r().post(post_room_admin))
.route("/room/{rid}/member", r().get(list_room_member).post(post_room_member))
.route("/room/{rid}/member/{idkey}", r().get(get_room_member).delete(delete_room_member).patch(patch_room_member))
.route("/room/{rid}/member/{idkey}/identity", r().get(get_room_member_identity))
.method_not_allowed_fallback(fallback_method_route)
.fallback(fallback_route)
;

View file

@ -8,7 +8,7 @@ use axum::extract::rejection::{JsonRejection, PathRejection, QueryRejection};
use axum::extract::{FromRef, FromRequest, FromRequestParts, Request};
use axum::http::{header, request, HeaderValue, StatusCode};
use axum::response::{IntoResponse, IntoResponseParts, Response, ResponseParts};
use axum::{async_trait, Json};
use axum::Json;
use blah_types::msg::AuthPayload;
use blah_types::server::ErrorObject;
use blah_types::{Signed, UserKey};
@ -158,7 +158,6 @@ impl From<rusqlite::Error> for ApiError {
#[derive(Debug)]
pub struct SignedJson<T>(pub Signed<T>);
#[async_trait]
impl<S, T> FromRequest<S> for SignedJson<T>
where
S: Send + Sync,
@ -216,7 +215,6 @@ pub type MaybeAuth = Result<Auth, AuthRejection>;
#[derive(Debug)]
pub struct Auth(pub UserKey);
#[async_trait]
impl<S> FromRequestParts<S> for Auth
where
S: Send + Sync,
@ -249,7 +247,6 @@ where
#[derive(Debug, Clone)]
pub struct ETag<T>(pub Option<T>);
#[async_trait]
impl<S, T: FromStr> FromRequestParts<S> for ETag<T>
where
S: Send + Sync,
@ -284,13 +281,3 @@ impl<T: fmt::Display> IntoResponseParts for ETag<T> {
Ok(res)
}
}
// WAIT: https://github.com/tokio-rs/axum/pull/2978
#[derive(Debug, Clone, Copy)]
pub struct NoContent;
impl IntoResponse for NoContent {
fn into_response(self) -> Response {
StatusCode::NO_CONTENT.into_response()
}
}

View file

@ -2,6 +2,7 @@ use std::num::NonZero;
use std::time::Duration;
use anyhow::{anyhow, ensure};
use axum::response::NoContent;
use blah_types::get_timestamp;
use blah_types::identity::{IdUrl, UserIdentityDesc};
use blah_types::msg::{UserRegisterChallengeResponse, UserRegisterPayload};
@ -14,7 +15,7 @@ use serde::Deserialize;
use sha2::{Digest, Sha256};
use crate::database::TransactionOps;
use crate::middleware::{NoContent, SignedJson};
use crate::middleware::SignedJson;
use crate::utils::Instant;
use crate::{ApiError, ArcState, SERVER_AND_VERSION};