about summary refs log tree commit diff
path: root/src/frontend
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2025-04-20 09:16:35 +0300
committerVika <vika@fireburn.ru>2025-04-20 10:01:04 +0300
commitb02882d1d586dbc481a4c002e6e9a5892daabc9f (patch)
tree194b30281834c536493b23a09344f3ef3e98ac11 /src/frontend
parent3207c8ea57eac714417494e06ce0f82864b7ff1e (diff)
downloadkittybox-b02882d1d586dbc481a4c002e6e9a5892daabc9f.tar.zst
Expose custom CSS as a route feature/themes
The admin dashboard (that's not done yet) should include methods for
setting this field. For now, it could very well be set through editing
the database manually. #ManualUntilItHurts

Change-Id: Ibef6fca5f1d19f237e660bf3a13b4d72c8c08a0a
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/mod.rs23
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>,