about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs1
-rw-r--r--src/main.rs2
-rw-r--r--src/media/mod.rs46
-rw-r--r--src/micropub/mod.rs50
4 files changed, 48 insertions, 51 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 9d4335a..1800b5b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,6 +5,7 @@ pub mod metrics;
 /// Database abstraction layer for Kittybox, allowing the CMS to work with any kind of database.
 pub mod database;
 pub mod micropub;
+pub mod media;
 pub mod indieauth;
 pub mod frontend;
 
diff --git a/src/main.rs b/src/main.rs
index ec6c95f..0234abc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -171,7 +171,7 @@ async fn main() {
 
         let media = warp::path("media")
             .and(warp::path::end()
-                 .and(kittybox::micropub::media::media())
+                 .and(kittybox::media::media())
                  .or(kittybox::util::require_host()
                      .and(warp::path::param())
                      .map(|_host: Authority, path: String| format!("media file {}", path))));
diff --git a/src/media/mod.rs b/src/media/mod.rs
new file mode 100644
index 0000000..0d46e0c
--- /dev/null
+++ b/src/media/mod.rs
@@ -0,0 +1,46 @@
+use futures_util::StreamExt;
+use bytes::buf::Buf;
+use warp::{Filter, Rejection, Reply, multipart::{FormData, Part}};
+
+pub fn query() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
+    warp::get()
+        .and(crate::util::require_host())
+        .map(|host| "media endpoint query...")
+}
+
+pub fn options() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
+    warp::options()
+        .map(|| warp::reply::json::<Option<()>>(&None))
+        .with(warp::reply::with::header("Allow", "GET, POST"))
+}
+
+pub fn upload() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
+    warp::post()
+        .and(crate::util::require_host())
+        .and(warp::multipart::form().max_length(1024*1024*150/*mb*/))
+        .and_then(|host, mut form: FormData| async move {
+            // TODO get rid of the double unwrap() here
+            let file: Part = form.next().await.unwrap().unwrap();
+            log::debug!("Uploaded: {:?}, type: {:?}", file.filename(), file.content_type());
+
+            let mut data = file.stream();
+            while let Some(buf) = data.next().await {
+                // TODO save it into a file
+                log::debug!("buffer length: {:?}", buf.map(|b| b.remaining()));
+            }
+            Ok::<_, warp::Rejection>(warp::reply::with_header(
+                warp::reply::with_status(
+                    "",
+                    warp::http::StatusCode::CREATED
+                ),
+                "Location",
+                "./awoo.png"
+            ))
+        })
+}
+
+pub fn media() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
+    upload()
+        .or(query())
+        .or(options())
+}
diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs
index ac038f8..7aad51a 100644
--- a/src/micropub/mod.rs
+++ b/src/micropub/mod.rs
@@ -110,56 +110,6 @@ impl warp::reject::Reject for MicropubError {}
 mod post;
 pub(crate) use post::normalize_mf2;
 
-#[allow(unused_variables)]
-pub mod media {
-    use futures_util::StreamExt;
-    use bytes::buf::Buf;
-    use warp::{Filter, Rejection, Reply, multipart::{FormData, Part}};
-
-    pub fn query() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
-        warp::get()
-            .and(crate::util::require_host())
-            .map(|host| "media endpoint query...")
-    }
-
-    pub fn options() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
-        warp::options()
-            .map(|| warp::reply::json::<Option<()>>(&None))
-            .with(warp::reply::with::header("Allow", "GET, POST"))
-    }
-
-    pub fn upload() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
-        warp::post()
-            .and(crate::util::require_host())
-            .and(warp::multipart::form().max_length(1024*1024*150/*mb*/))
-            .and_then(|host, mut form: FormData| async move {
-                // TODO get rid of the double unwrap() here
-                let file: Part = form.next().await.unwrap().unwrap();
-                log::debug!("Uploaded: {:?}, type: {:?}", file.filename(), file.content_type());
-
-                let mut data = file.stream();
-                while let Some(buf) = data.next().await {
-                    // TODO save it into a file
-                    log::debug!("buffer length: {:?}", buf.map(|b| b.remaining()));
-                }
-                Ok::<_, warp::Rejection>(warp::reply::with_header(
-                    warp::reply::with_status(
-                        "",
-                        warp::http::StatusCode::CREATED
-                    ),
-                    "Location",
-                    "./awoo.png"
-                ))
-            })
-    }
-
-    pub fn media() -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
-        upload()
-            .or(query())
-            .or(options())
-    }
-}
-
 mod util {
     use serde_json::json;