summaryrefslogtreecommitdiffstats
path: root/src/routes/api/posts.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/api/posts.rs')
-rw-r--r--src/routes/api/posts.rs85
1 files changed, 0 insertions, 85 deletions
diff --git a/src/routes/api/posts.rs b/src/routes/api/posts.rs
index 0be75ac..0ca17da 100644
--- a/src/routes/api/posts.rs
+++ b/src/routes/api/posts.rs
@@ -459,86 +459,6 @@ async fn route_unstable_posts_delete(
}
}
-async fn route_unstable_posts_href_get(
- params: (PostLocalID,),
- ctx: Arc<crate::RouteContext>,
- req: hyper::Request<hyper::Body>,
-) -> Result<hyper::Response<hyper::Body>, crate::Error> {
- let (post_id,) = params;
-
- let lang = crate::get_lang_for_req(&req);
- let db = ctx.db_pool.get().await?;
-
- let row = db
- .query_opt("SELECT href FROM post WHERE id=$1", &[&post_id])
- .await?;
- match row {
- None => Ok(crate::simple_response(
- hyper::StatusCode::NOT_FOUND,
- lang.tr("no_such_post", 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("post_not_link", 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_posts_like(
params: (PostLocalID,),
ctx: Arc<crate::RouteContext>,
@@ -898,11 +818,6 @@ pub fn route_posts() -> crate::RouteNode<()> {
.with_handler_async("GET", route_unstable_posts_get)
.with_handler_async("DELETE", route_unstable_posts_delete)
.with_child(
- "href",
- crate::RouteNode::new()
- .with_handler_async("GET", route_unstable_posts_href_get),
- )
- .with_child(
"replies",
crate::RouteNode::new()
.with_handler_async("POST", route_unstable_posts_replies_create),