Merge branch 'master' into gractwo
All checks were successful
mnemo-build-and-publish / gractwo-mnemo-build (push) Successful in 1m11s

This commit is contained in:
2026-05-01 16:33:03 +02:00
2 changed files with 25 additions and 2 deletions

View File

@@ -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())
}

View File

@@ -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,8 +189,11 @@ pub async fn form(
LogEntry::new(&mut *tx, u, LogAction::CreateQuote { id: q.id }).await?;
tx.commit().await?;
if let Some(ref url) = state.conf.read().await.discord_webhook {
q.post_msg_webhook(url.clone());
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())