diff --git a/backend/src/api/webmention.rs b/backend/src/api/webmention.rs index 62e7106..8824dbf 100644 --- a/backend/src/api/webmention.rs +++ b/backend/src/api/webmention.rs @@ -1,10 +1,10 @@ use super::{Error, Result}; -use crate::{models, schema, MainDatabase}; +use crate::{models, schema, web::discord_webhook::Client as DiscordWebhook, MainDatabase}; use diesel::prelude::*; use rocket::{ request::Form, response::{self, Responder}, - Request, Response, + Request, Response, State, }; use rocket_contrib::json::Json; use rusty_ulid::generate_ulid_string; @@ -71,8 +71,12 @@ impl<'a> Responder<'a> for models::WebMention { } #[post("/webmention/accept", data = "")] -#[instrument(skip(conn, mention), err)] -pub fn accept(conn: MainDatabase, mention: Form) -> Result { +#[instrument(skip(conn, mention, dw), err)] +pub fn accept( + conn: MainDatabase, + mention: Form, + dw: State, +) -> Result { use schema::webmentions; let mention = mention.into_inner(); @@ -90,6 +94,15 @@ pub fn accept(conn: MainDatabase, mention: Form) -> Result mentioned <{}> ()", + wm.source_url, wm.target_url, wm.id + )) + .map_err(|why| { + error!("webhook send failed: {}", why); + Error::Web(why) + })?; + Ok(wm) } diff --git a/backend/src/web/discord_webhook.rs b/backend/src/web/discord_webhook.rs index a6e1972..0e5249a 100644 --- a/backend/src/web/discord_webhook.rs +++ b/backend/src/web/discord_webhook.rs @@ -43,6 +43,7 @@ impl Client { }) } + #[instrument(skip(self), err)] pub fn send(&self, body: String) -> Result<()> { let resp = ureq::post(&self.webhook_url) .set("User-Agent", crate::APPLICATION_NAME)