about summary refs log tree commit diff
path: root/kittybox-rs/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'kittybox-rs/src/main.rs')
-rw-r--r--kittybox-rs/src/main.rs94
1 files changed, 16 insertions, 78 deletions
diff --git a/kittybox-rs/src/main.rs b/kittybox-rs/src/main.rs
index ece31df..6cc8c1d 100644
--- a/kittybox-rs/src/main.rs
+++ b/kittybox-rs/src/main.rs
@@ -100,84 +100,16 @@ async fn main() {
             }
         };
 
-        let endpoints = kittybox::frontend::IndiewebEndpoints {
-            authorization_endpoint: authorization_endpoint.to_string(),
-            token_endpoint: token_endpoint.to_string(),
-            webmention: None,
-            microsub: None,
+        let blobstore = {
+            let variable = std::env::var("BLOBSTORE_URI")
+                .unwrap();
+            let folder = variable
+                .strip_prefix("file://")
+                .unwrap();
+            let path = std::path::PathBuf::from(folder);
+            kittybox::media::storage::file::FileStore::new(path)
         };
 
-        /*let micropub = warp::path("micropub")
-            .and(warp::path::end()
-                 .and(kittybox::micropub::micropub(
-                     database.clone(),
-                     token_endpoint.to_string(),
-                     http.clone()
-                 ))
-                 .or(warp::get()
-                     .and(warp::path("client"))
-                     .and(warp::path::end())
-                     .map(|| warp::reply::html(kittybox::MICROPUB_CLIENT))));
-
-        let static_files = warp::path("static")
-            .and(kittybox::frontend::static_files());
-
-        let media = warp::path("media")
-            .and(warp::path::end()
-                 .and(kittybox::media::media())
-                 .or(kittybox::util::require_host()
-                     .and(warp::path::param())
-                     .map(|_host: Authority, path: String| format!("media file {}", path))));
-
-        let technical = warp::path(".kittybox")
-            .and(warp::path("onboarding")
-                 .and(warp::path::end())
-                 .and(kittybox::frontend::onboarding(
-                     database.clone(),
-                     endpoints.clone(),
-                     http.clone()
-                 ))
-                 .or(warp::path("health")
-                     .and(warp::path::end())
-                     .and(warp::get())
-                     // TODO make healthcheck report on database status too
-                     .map(|| "OK"))
-                 .or(warp::path("metrics")
-                     .and(warp::path::end())
-                     .and(warp::get())
-                     .map(kittybox::metrics::gather))
-                 .or(micropub)
-                 .or(media)
-                 .or(static_files)
-                 .or(warp::path("login")
-                     .and(warp::path("callback")
-                          .map(|| "callback!")
-                          // TODO form on GET and handler on POST
-                          .or(warp::path::end()
-                              .map(|| "login page!"))
-                     )
-                 )
-            );
-
-        // TODO prettier error response
-        let coffee = warp::path("coffee")
-            .map(|| warp::reply::with_status("I'm a teapot!", warp::http::StatusCode::IM_A_TEAPOT));
-
-        et catchall = ;
-
-        let app = homepage
-            .or(technical)
-            .or(coffee)
-            .or(catchall)
-            .with(warp::log("kittybox"))
-            .with(kittybox::metrics::metrics(vec![
-                ".kittybox".to_string()
-            ]))
-            ;
-
-        let svc = warp::service(app);
-         */
-
         let svc = axum::Router::new()
             .route(
                 "/",
@@ -231,9 +163,14 @@ async fn main() {
                 axum::Router::new()
                     .route(
                         "/",
-                        axum::routing::get(|| async { todo!() }).post(|| async { todo!() }),
+                        axum::routing::get(|| async { todo!() })
+                            .post(
+                                kittybox::media::upload::<kittybox::media::FileStore>
+                            ),
                     )
-                    .route("/:filename", axum::routing::get(|| async { todo!() })),
+                    .route("/uploads/*file", axum::routing::get(
+                        kittybox::media::serve::<kittybox::media::FileStore>
+                    )),
             )
             .route(
                 "/.kittybox/static/:path",
@@ -247,6 +184,7 @@ async fn main() {
             .layer(axum::Extension(kittybox::indieauth::TokenEndpoint(
                 token_endpoint,
             )))
+            .layer(axum::Extension(blobstore))
             .layer(
                 tower::ServiceBuilder::new()
                     .layer(tower_http::trace::TraceLayer::new_for_http())