|
|
|
@ -17,6 +17,7 @@ use std::fs::File;
|
|
|
|
|
use std::sync::Mutex;
|
|
|
|
|
use std::{collections::HashMap, sync::MutexGuard};
|
|
|
|
|
use validator::Validate;
|
|
|
|
|
use webhook::client::WebhookClient;
|
|
|
|
|
|
|
|
|
|
struct AppState {
|
|
|
|
|
databases: HashMap<String, Mutex<Database>>,
|
|
|
|
@ -120,14 +121,39 @@ async fn _post_comment(
|
|
|
|
|
}
|
|
|
|
|
return Err(Error::InvalidUrl);
|
|
|
|
|
}
|
|
|
|
|
match get_page_data(&url).await? {
|
|
|
|
|
let page_data = match get_page_data(&url).await? {
|
|
|
|
|
Some(page_data) => {
|
|
|
|
|
if page_data.content_id != comment.content_id {
|
|
|
|
|
return Err(Error::InvalidContentId);
|
|
|
|
|
}
|
|
|
|
|
page_data
|
|
|
|
|
}
|
|
|
|
|
None => return Err(Error::InvalidUrl), // e.g. 404
|
|
|
|
|
};
|
|
|
|
|
// TODO: Clean up webhook integration
|
|
|
|
|
{
|
|
|
|
|
let database = data.get_db(&origin)?;
|
|
|
|
|
if let Some(webhook) = &database.settings.webhook {
|
|
|
|
|
let client = WebhookClient::new(&webhook);
|
|
|
|
|
client.send(|message| {
|
|
|
|
|
let author = match &comment.author {
|
|
|
|
|
Some(author) => &author,
|
|
|
|
|
None => "Annonymous",
|
|
|
|
|
};
|
|
|
|
|
message
|
|
|
|
|
.username(&author)
|
|
|
|
|
.avatar_url(&format!(
|
|
|
|
|
"https://www.gravatar.com/avatar/{}?d=mp",
|
|
|
|
|
get_gravatar(&comment.email)
|
|
|
|
|
))
|
|
|
|
|
.embed(|embed| embed
|
|
|
|
|
.title(&format!("New comment on {}", page_data.content_id))
|
|
|
|
|
.description(&comment.text)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
).await.unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
web::block(move || {
|
|
|
|
|
let database = data.get_db(&origin)?;
|
|
|
|
|
if comment.author.is_none() && database.settings.name_required {
|
|
|
|
@ -152,8 +178,8 @@ async fn _post_comment(
|
|
|
|
|
}
|
|
|
|
|
database.create_comment(&comment)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
})
|
|
|
|
|
.await?
|
|
|
|
|
}).await?.unwrap();
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[post("/")]
|
|
|
|
|