From 04f7d390f5630de4875543fdaf39348d05880c4c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 16 Aug 2021 12:44:38 -0400 Subject: [PATCH] Adding post_link_tags route --- crates/routes/src/post_link_tags.rs | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 crates/routes/src/post_link_tags.rs diff --git a/crates/routes/src/post_link_tags.rs b/crates/routes/src/post_link_tags.rs new file mode 100644 index 000000000..7c92a0c11 --- /dev/null +++ b/crates/routes/src/post_link_tags.rs @@ -0,0 +1,32 @@ +use actix_web::{error::ErrorBadRequest, web::Query, *}; +use anyhow::anyhow; +use lemmy_utils::{request::fetch_post_link_tags, LemmyError}; +use lemmy_websocket::LemmyContext; +use serde::Deserialize; +use url::Url; + +#[derive(Deserialize)] +struct Params { + url: String, +} + +pub fn config(cfg: &mut web::ServiceConfig) { + cfg.route("/post_link_tags", web::get().to(get_post_links_response)); + // .app_data(Data::new(client)); +} + +async fn get_post_links_response( + info: Query, + context: web::Data, +) -> Result { + let url = + Url::parse(&info.url).map_err(|_| ErrorBadRequest(LemmyError::from(anyhow!("not_found"))))?; + println!("url: {:?}", url); + + let json = fetch_post_link_tags(context.client(), &url) + .await + .map_err(|_| ErrorBadRequest(LemmyError::from(anyhow!("not_found"))))?; + println!("json: {:?}", json); + + Ok(HttpResponse::Ok().json(json)) +}