diff options
Diffstat (limited to 'src/frontend')
-rw-r--r-- | src/frontend/mod.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index a05c91d..3a23ad9 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -241,6 +241,29 @@ async fn get_post_from_database<S: Storage>( } #[tracing::instrument(skip(db))] +pub async fn custom_css<D: Storage>(Host(host): Host, State(db): State<D>) -> impl IntoResponse { + // This is stupid, but there is no other way. + let hcard_url: url::Url = format!("https://{}/", host).parse().unwrap(); + match db + .get_setting::<crate::database::settings::CustomCss>(&hcard_url) + .await + { + Ok(css) => { + let css = css.into_inner(); + if css.is_empty() { + StatusCode::NOT_FOUND.into_response() + } else { + (StatusCode::OK, [("Content-Type", "text/css")], css).into_response() + } + } + Err(err) => { + tracing::warn!("Failed to get custom CSS: {}", err); + StatusCode::INTERNAL_SERVER_ERROR.into_response() + } + } +} + +#[tracing::instrument(skip(db))] pub async fn homepage<D: Storage>( Host(host): Host, Query(query): Query<QueryParams>, |