From d95ae14555b421eb62f9ffaeb7c869c540961fa4 Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 10 May 2022 00:42:01 +0300 Subject: media: move to separate subtree This will ease future extraction of the media endpoint to a separate crate. This is highly desirable since it will allow Kittybox's media endpoint to be used separately in instances where a standalone media endpoint is desirable (e.g. custom solutions using my code to polyfill for desired functionality that is undesirable to implement by oneself) --- src/micropub/mod.rs | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) (limited to 'src/micropub') 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 + Clone { - warp::get() - .and(crate::util::require_host()) - .map(|host| "media endpoint query...") - } - - pub fn options() -> impl Filter + Clone { - warp::options() - .map(|| warp::reply::json::>(&None)) - .with(warp::reply::with::header("Allow", "GET, POST")) - } - - pub fn upload() -> impl Filter + 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 + Clone { - upload() - .or(query()) - .or(options()) - } -} - mod util { use serde_json::json; -- cgit 1.4.1