mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-07 10:42:19 +00:00
Adding post_link_tags route
This commit is contained in:
parent
78485838d6
commit
04f7d390f5
1 changed files with 32 additions and 0 deletions
32
crates/routes/src/post_link_tags.rs
Normal file
32
crates/routes/src/post_link_tags.rs
Normal file
|
@ -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<Params>,
|
||||
context: web::Data<LemmyContext>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
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))
|
||||
}
|
Loading…
Reference in a new issue