v0.31.0
This commit is contained in:
1 parent
f213d853e2
commit
76b8bb7ee2
78 files changed
+7750
-5204
No files matched your search
+31
-14
@@ -1,21 +1,35 @@
|
||||
//! Deliberately small anonymous surface. Operational templates/assets are private.
|
||||
use crate::{auth::Session, runtime::ApiError};
|
||||
use axum::{extract::rejection::JsonRejection, response::Html, Extension};
|
||||
use http::StatusCode;
|
||||
use std::sync::OnceLock;
|
||||
use crate::{auth::Session, runtime::{ApiError, App}, settings::PanelCompression};
|
||||
use axum::{extract::{rejection::JsonRejection, State}, response::{Html, IntoResponse, Response}, Extension};
|
||||
use http::{HeaderMap, StatusCode};
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
static ADMIN_INDEX: OnceLock<String> = OnceLock::new();
|
||||
use super::panel_content::PanelContent;
|
||||
|
||||
pub(super) async fn index(session: Option<Extension<Session>>) -> Html<&'static str> {
|
||||
if session.is_some() {
|
||||
Html(ADMIN_INDEX.get_or_init(|| {
|
||||
include_str!("web/index.html")
|
||||
.replace("__RUSTPROXY_VERSION__", env!("CARGO_PKG_VERSION"))
|
||||
}).as_str())
|
||||
} else {
|
||||
Html(include_str!("web/login.html"))
|
||||
}
|
||||
static ADMIN_INDEX: OnceLock<PanelContent> = OnceLock::new();
|
||||
|
||||
fn panel_response(headers: &HeaderMap, compression: &PanelCompression) -> Response {
|
||||
let content = ADMIN_INDEX.get_or_init(|| {
|
||||
let html = include_str!("web/index.html")
|
||||
.replace("__RUSTPROXY_VERSION__", env!("CARGO_PKG_VERSION"));
|
||||
// Exactly one static panel document shared between all administrator accounts.
|
||||
PanelContent::new(Box::leak(html.into_boxed_str()))
|
||||
});
|
||||
content.response(headers, compression, "text/html; charset=utf-8")
|
||||
}
|
||||
|
||||
pub(super) async fn index(
|
||||
State(state): State<Arc<App>>,
|
||||
session: Option<Extension<Session>>,
|
||||
headers: HeaderMap,
|
||||
) -> Response {
|
||||
if session.is_none() {
|
||||
return Html(include_str!("web/login.html")).into_response();
|
||||
}
|
||||
let snapshot = state.config.load();
|
||||
panel_response(&headers, &snapshot.envelope.config.administration.panel_compression)
|
||||
}
|
||||
|
||||
pub(super) fn invalid_json(error: JsonRejection) -> ApiError {
|
||||
// Keep useful protocol statuses without returning serde's input excerpts.
|
||||
let status = match error.status() {
|
||||
@@ -25,3 +39,6 @@ pub(super) fn invalid_json(error: JsonRejection) -> ApiError {
|
||||
};
|
||||
ApiError(status, "auth.invalid_request".into())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
Reference in new issue
Block a user