Compare commits
2 Commits
4aa96dca01
...
cdd296ea84
| Author | SHA1 | Date | |
|---|---|---|---|
|
cdd296ea84
|
|||
|
4d49a5c0b3
|
@@ -53,6 +53,8 @@ pub struct QuoteCreateForm {
|
||||
pub context: Option<String>,
|
||||
pub location: Option<String>,
|
||||
pub public: bool,
|
||||
#[serde(default)]
|
||||
pub discord_webhook: bool,
|
||||
}
|
||||
|
||||
pub async fn create(
|
||||
@@ -85,5 +87,12 @@ pub async fn create(
|
||||
|
||||
LogEntry::new(&mut tx, u, LogAction::CreateQuote { id: q.id }).await?;
|
||||
tx.commit().await?;
|
||||
|
||||
if form.discord_webhook {
|
||||
if let Some(ref url) = state.conf.read().await.discord_webhook {
|
||||
q.post_msg_webhook(url.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Ok((StatusCode::CREATED, Json(q)).into_response())
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ pub async fn page(
|
||||
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||
};
|
||||
let names = Name::get_all(&mut *conn).await?;
|
||||
let feature_webhooks = state.conf.read().await.discord_webhook.is_some();
|
||||
|
||||
Ok(base(
|
||||
"Add Quote | Mnemosyne",
|
||||
@@ -91,6 +92,15 @@ pub async fn page(
|
||||
class="px-2 py-1 w-full mb-2 bg-neutral-950/50 rounded border border-neutral-200/25";
|
||||
}
|
||||
}
|
||||
@if feature_webhooks {
|
||||
div class="flex flex-col justify-center mt-5" {
|
||||
label class="flex items-center gap-2 cursor-pointer" {
|
||||
input type="checkbox" name="discord_webhook" value="true" checked
|
||||
class="w-4 h-4 cursor-pointer";
|
||||
span {"Send to Discord"}
|
||||
}
|
||||
}
|
||||
}
|
||||
button type="submit" class="border mt-auto mb-2 cursor-pointer rounded h-fit px-2 py-1 bg-neutral-200/5 border-neutral-200/25 hover:border-neutral-200/45 hover:bg-neutral-200/15" {
|
||||
"Submit"
|
||||
}
|
||||
@@ -140,6 +150,7 @@ pub struct IncomingQuote {
|
||||
location: String,
|
||||
time: String,
|
||||
context: String,
|
||||
discord_webhook: Option<String>,
|
||||
}
|
||||
pub async fn form(
|
||||
State(state): State<MnemoState>,
|
||||
@@ -178,9 +189,12 @@ pub async fn form(
|
||||
LogEntry::new(&mut *tx, u, LogAction::CreateQuote { id: q.id }).await?;
|
||||
tx.commit().await?;
|
||||
|
||||
let should_send_webhook = form.discord_webhook.as_deref() == Some("true");
|
||||
if should_send_webhook {
|
||||
if let Some(ref url) = state.conf.read().await.discord_webhook {
|
||||
q.post_msg_webhook(url.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Redirect::to("/dashboard").into_response())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user