diff options
Diffstat (limited to 'src/routes/api/comments.rs')
-rw-r--r-- | src/routes/api/comments.rs | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/src/routes/api/comments.rs b/src/routes/api/comments.rs index 545771c..0c91b97 100644 --- a/src/routes/api/comments.rs +++ b/src/routes/api/comments.rs @@ -219,89 +219,6 @@ async fn route_unstable_comments_delete( } } -async fn route_unstable_comments_attachments_0_href_get( - params: (CommentLocalID,), - ctx: Arc<crate::RouteContext>, - req: hyper::Request<hyper::Body>, -) -> Result<hyper::Response<hyper::Body>, crate::Error> { - let (comment_id,) = params; - - let lang = crate::get_lang_for_req(&req); - let db = ctx.db_pool.get().await?; - - let row = db - .query_opt( - "SELECT attachment_href FROM reply WHERE id=$1", - &[&comment_id], - ) - .await?; - match row { - None => Ok(crate::simple_response( - hyper::StatusCode::NOT_FOUND, - lang.tr("no_such_comment", None).into_owned(), - )), - Some(row) => { - let href: Option<String> = row.get(0); - match href { - None => Ok(crate::simple_response( - hyper::StatusCode::NOT_FOUND, - lang.tr("no_such_attachment", None).into_owned(), - )), - Some(href) => { - if href.starts_with("local-media://") { - // local media, serve file content - - let media_id: crate::Pineapple = (&href[14..]).parse()?; - - let media_row = db - .query_opt( - "SELECT path, mime FROM media WHERE id=$1", - &[&media_id.as_int()], - ) - .await?; - match media_row { - None => Ok(crate::simple_response( - hyper::StatusCode::NOT_FOUND, - lang.tr("media_upload_missing", None).into_owned(), - )), - Some(media_row) => { - let path: &str = media_row.get(0); - let mime: &str = media_row.get(1); - - if let Some(media_location) = &ctx.media_location { - let path = media_location.join(path); - - let file = tokio::fs::File::open(path).await?; - let body = hyper::Body::wrap_stream( - tokio_util::codec::FramedRead::new( - file, - tokio_util::codec::BytesCodec::new(), - ), - ); - - Ok(crate::common_response_builder() - .header(hyper::header::CONTENT_TYPE, mime) - .body(body)?) - } else { - Ok(crate::simple_response( - hyper::StatusCode::NOT_FOUND, - lang.tr("media_upload_missing", None).into_owned(), - )) - } - } - } - } else { - Ok(crate::common_response_builder() - .status(hyper::StatusCode::FOUND) - .header(hyper::header::LOCATION, &href) - .body(href.into())?) - } - } - } - } - } -} - async fn route_unstable_comments_like( params: (CommentLocalID,), ctx: Arc<crate::RouteContext>, @@ -670,11 +587,6 @@ pub fn route_comments() -> crate::RouteNode<()> { .with_handler_async("GET", route_unstable_comments_get) .with_handler_async("DELETE", route_unstable_comments_delete) .with_child( - "attachments/0/href", - crate::RouteNode::new() - .with_handler_async("GET", route_unstable_comments_attachments_0_href_get), - ) - .with_child( "replies", crate::RouteNode::new() .with_handler_async("POST", route_unstable_comments_replies_create), |