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)) +}