strip session-added comments
This commit is contained in:
@@ -7,7 +7,6 @@ license = "MIT"
|
||||
|
||||
[features]
|
||||
default = ["federation"]
|
||||
# Enables federation-gated handlers; forwards to application/federation
|
||||
federation = ["application/federation"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -16,9 +16,6 @@ use axum::{Router, routing};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// JSON API routes (mounted under `/api/v1`), minus the webhook ingestion
|
||||
/// endpoints ([`webhook_router`], separately rate limited) and the
|
||||
/// federation-gated admin endpoints (`federation::api_routes`).
|
||||
pub fn router() -> Router<AppState> {
|
||||
let base = Router::new()
|
||||
.route("/diary", routing::get(diary::get_diary))
|
||||
@@ -150,7 +147,6 @@ pub fn router() -> Router<AppState> {
|
||||
base.merge(social_routes())
|
||||
}
|
||||
|
||||
/// Media-server webhook ingestion endpoints (mounted under `/api/v1`).
|
||||
pub fn webhook_router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route(
|
||||
|
||||
@@ -14,7 +14,6 @@ pub const CONFLICT: &str = "CONFLICT";
|
||||
pub const RATE_LIMITED: &str = "RATE_LIMITED";
|
||||
pub const INTERNAL: &str = "INTERNAL";
|
||||
|
||||
/// The only constructor of JSON error bodies in this crate.
|
||||
pub fn refuse(status: StatusCode, code: &'static str, message: impl Into<String>) -> Response {
|
||||
(
|
||||
status,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//! JSON API extractors whose rejections are refused in the one error shape.
|
||||
|
||||
use axum::{
|
||||
extract::{
|
||||
FromRequest, FromRequestParts, Multipart, Path, Query, Request,
|
||||
@@ -13,10 +11,6 @@ use serde::de::DeserializeOwned;
|
||||
|
||||
use crate::errors::{INTERNAL, INVALID_INPUT, refuse};
|
||||
|
||||
/// Malformed request (bad JSON, query or path), refused as `INVALID_INPUT`.
|
||||
/// Status follows axum: 400 syntax, 415 content type, 422 data errors, 413 size.
|
||||
/// A rejection with a 5xx status is a server-side fault (e.g. a route that
|
||||
/// declares no path parameter), refused as `INTERNAL`.
|
||||
pub struct MalformedRequest {
|
||||
status: StatusCode,
|
||||
message: String,
|
||||
@@ -69,7 +63,6 @@ impl From<MultipartRejection> for MalformedRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/// `axum::extract::Multipart` with refusals in the one error shape.
|
||||
pub struct Upload(pub Multipart);
|
||||
|
||||
impl<S> FromRequest<S> for Upload
|
||||
@@ -83,7 +76,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// `axum::Json` with refusals in the one error shape.
|
||||
pub struct Body<T>(pub T);
|
||||
|
||||
impl<S, T> FromRequest<S> for Body<T>
|
||||
@@ -99,7 +91,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// `axum::extract::Query` with refusals in the one error shape.
|
||||
pub struct Params<T>(pub T);
|
||||
|
||||
impl<S, T> FromRequestParts<S> for Params<T>
|
||||
@@ -115,7 +106,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// `axum::extract::Path` with refusals in the one error shape.
|
||||
pub struct PathId<T>(pub T);
|
||||
|
||||
impl<S, T> FromRequestParts<S> for PathId<T>
|
||||
|
||||
@@ -146,7 +146,6 @@ where
|
||||
)
|
||||
.await
|
||||
.map_err(ApiError)?
|
||||
// `None` only if the account vanished between `ensure_active` and here.
|
||||
.ok_or_else(|| ApiError(DomainError::NotFound("user not found".into())))?;
|
||||
if is_admin {
|
||||
Ok(AdminApiUser(user_id))
|
||||
@@ -175,7 +174,6 @@ where
|
||||
)
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR.into_response())?
|
||||
// `None` only if the account vanished between `ensure_active` and here.
|
||||
.ok_or_else(|| StatusCode::UNAUTHORIZED.into_response())?;
|
||||
if is_admin {
|
||||
Ok(AdminUser(user_id))
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//! Federation-only HTTP surface. This is the one module that decides, per
|
||||
//! build, whether federation routes exist: both builds expose the same
|
||||
//! functions, so `router.rs` and the api/html modules stay free of `cfg`.
|
||||
|
||||
#[cfg(feature = "federation")]
|
||||
pub(crate) mod blocklist_api;
|
||||
#[cfg(feature = "federation")]
|
||||
@@ -18,7 +14,6 @@ use axum::{Router, routing};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// Classic-UI routes that only exist with federation (AP collections, admin pages).
|
||||
#[cfg(feature = "federation")]
|
||||
pub fn html_routes() -> Router<AppState> {
|
||||
Router::new()
|
||||
@@ -53,7 +48,6 @@ pub fn html_routes() -> Router<AppState> {
|
||||
)
|
||||
}
|
||||
|
||||
/// JSON API routes that only exist with federation (blocklist administration).
|
||||
#[cfg(feature = "federation")]
|
||||
pub fn api_routes() -> Router<AppState> {
|
||||
Router::new()
|
||||
@@ -80,8 +74,6 @@ pub fn api_routes() -> Router<AppState> {
|
||||
)
|
||||
}
|
||||
|
||||
/// Without federation the follower/following collection URLs fall back to the
|
||||
/// classic list pages.
|
||||
#[cfg(not(feature = "federation"))]
|
||||
pub fn html_routes() -> Router<AppState> {
|
||||
Router::new()
|
||||
@@ -108,8 +100,6 @@ pub fn api_routes() -> Router<AppState> {
|
||||
Router::new()
|
||||
}
|
||||
|
||||
/// ActivityPub content negotiation for `GET /users/{id}`: federation builds
|
||||
/// answer AP clients with the actor document, others always render HTML.
|
||||
#[cfg(not(feature = "federation"))]
|
||||
pub async fn actor_document_response(
|
||||
_state: &AppState,
|
||||
|
||||
@@ -6,8 +6,6 @@ use uuid::Uuid;
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// Answers ActivityPub clients (`Accept: application/activity+json` or
|
||||
/// `application/ld+json`) with the actor document; `None` means "render HTML".
|
||||
pub async fn actor_document_response(
|
||||
state: &AppState,
|
||||
headers: &HeaderMap,
|
||||
|
||||
@@ -19,7 +19,6 @@ pub fn extract_from_cookie(headers: &axum::http::HeaderMap) -> Option<String> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Router state for [`csrf_middleware`]: whether cookies carry the `Secure` attribute.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct SecureCookies(pub bool);
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ use axum::{Router, routing};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// Classic server-rendered UI routes, minus the rate-limited auth forms
|
||||
/// ([`auth_router`]) and the federation-gated pages (`federation::html_routes`).
|
||||
pub fn router() -> Router<AppState> {
|
||||
let base = Router::new()
|
||||
.route("/", routing::get(diary::get_activity_feed_html))
|
||||
@@ -127,7 +125,6 @@ pub fn router() -> Router<AppState> {
|
||||
base.merge(social_routes())
|
||||
}
|
||||
|
||||
/// Login, logout and registration forms; the caller adds the auth rate limiter.
|
||||
pub fn auth_router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route(
|
||||
|
||||
@@ -233,11 +233,8 @@ pub async fn post_delete_user(
|
||||
let target_id = UserId::from_uuid(target);
|
||||
let own = actor == target_id;
|
||||
match delete_account(&state, actor, target_id, &form.password).await {
|
||||
// An admin removing their own account ends their own session too.
|
||||
Ok(()) if own => super::auth::get_logout(State(state)).await.into_response(),
|
||||
Ok(()) => axum::response::Redirect::to("/users").into_response(),
|
||||
// Same as other forbidden classic actions: a plain 403, not a redirect
|
||||
// to a page that would not show the error.
|
||||
Err(e @ DomainError::Forbidden(_)) => crate::errors::domain_error_response(e),
|
||||
Err(e) => axum::response::Redirect::to(&format!(
|
||||
"/users/{target}?error={}",
|
||||
|
||||
@@ -48,7 +48,6 @@ async fn health_handler() -> axum::Json<serde_json::Value> {
|
||||
axum::Json(serde_json::json!({ "status": "ok" }))
|
||||
}
|
||||
|
||||
/// JSON API rate-limit refusals use the one error shape.
|
||||
fn slow_down(reason: RejectionReason) -> axum::response::Response {
|
||||
match reason {
|
||||
RejectionReason::QuotaExceeded { .. } => refuse(
|
||||
@@ -64,7 +63,6 @@ fn slow_down(reason: RejectionReason) -> axum::response::Response {
|
||||
}
|
||||
}
|
||||
|
||||
/// Every `/api/v1` limiter is built here so its refusals use the one error shape.
|
||||
fn api_governor(quota: Quota) -> axum_governor::GovernorConfig<std::net::IpAddr> {
|
||||
GovernorConfigBuilder::default()
|
||||
.with_extractor(PeerIp::default())
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//! Request/response helpers shared by the JSON API and the classic HTML UI.
|
||||
|
||||
use crate::state::AppState;
|
||||
use domain::models::import::DomainField;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//! Fixtures shared by the in-crate mapper tests.
|
||||
|
||||
use domain::value_objects::{SocialActor, SocialIdentity, UserId};
|
||||
|
||||
pub(crate) fn local_actor(uid: &UserId) -> SocialActor {
|
||||
|
||||
Reference in New Issue
Block a user