diff --git a/Cargo.toml b/Cargo.toml index 2e364e4..d246956 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ sqlx = { version = "0.8", features = ["macros", "runtim thiserror = "2.0.17" time = "0.3.44" tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread", "signal"] } -tower-http = { version = "0.6.6", features = ["fs"] } +tower-http = { version = "0.6.6", features = ["fs", "trace"] } tower-sessions = { version = "0.14.0", features = ["signed"] } tower-sessions-sqlx-store = { version = "0.15.0", features = ["sqlite"] } tracing = { version = "0.1.41", features = ["attributes"] } diff --git a/src/main.rs b/src/main.rs index f5883e5..bafba17 100644 --- a/src/main.rs +++ b/src/main.rs @@ -170,6 +170,7 @@ async fn serve(port: &u32) -> Result<(), anyhow::Error> { .merge(ics::router()) .nest_service("/static", ServeDir::new("./hashed_static")) .layer(auth_layer) + .layer(tower_http::trace::TraceLayer::new_for_http()) .with_state(state); let listener = TcpListener::bind(format!("0.0.0.0:{}", port)).await?; diff --git a/src/switchboard.rs b/src/switchboard.rs index 8610f22..ede4111 100644 --- a/src/switchboard.rs +++ b/src/switchboard.rs @@ -129,19 +129,22 @@ pub async fn insert_mentions<'a>( mentions: impl IntoIterator, pool: &SqlitePool, ) -> Result<(), AppError> { - let mut qb = QueryBuilder::::new( - "insert into mentions ( + let mut mentions = mentions.into_iter().peekable(); + if mentions.peek().is_some() { + let mut qb = QueryBuilder::::new( + "insert into mentions ( entity_id, entity_type, url, input_text, byte_range_start, byte_range_end) ", - ); - qb.push_values(mentions, |mut b, mention| { - b.push_bind(mention.entity_id) - .push_bind(mention.entity_type) - .push_bind(&mention.url) - .push_bind(&mention.input_text) - .push_bind(mention.byte_range_start) - .push_bind(mention.byte_range_end); - }); - qb.build().execute(pool).await?; + ); + qb.push_values(mentions, |mut b, mention| { + b.push_bind(mention.entity_id) + .push_bind(mention.entity_type) + .push_bind(&mention.url) + .push_bind(&mention.input_text) + .push_bind(mention.byte_range_start) + .push_bind(mention.byte_range_end); + }); + qb.build().execute(pool).await?; + } Ok(()) } diff --git a/src/web/home.rs b/src/web/home.rs index 806ef77..0ed42ba 100644 --- a/src/web/home.rs +++ b/src/web/home.rs @@ -102,12 +102,14 @@ pub async fn journal_section( are now, or leave everything blank to default to 'today'. Entries will be added to the top of the list regardless of date; refresh the page to re-sort." } - form hx-post="/journal_entry" hx-target="next .entries" hx-swap="afterbegin" hx-on::after-request="if(event.detail.successful) this.reset()" { + form hx-post="/journal_entry" hx-target="next .entries" hx-target-error="#journal-error" hx-swap="afterbegin" hx-on::after-request="if(event.detail.successful) this.reset()" { input name="date" placeholder=(Local::now().date_naive().to_string()); textarea name="value" placeholder="New entry..." autofocus {} input type="submit" value="Add Entry"; } + #journal-error {} + .entries { @for entry in entries { (entry.to_html(pool).await?) diff --git a/src/web/journal.rs b/src/web/journal.rs index c27aab7..c12f15b 100644 --- a/src/web/journal.rs +++ b/src/web/journal.rs @@ -80,6 +80,7 @@ mod post { let switchboard = sw_lock.read().unwrap(); switchboard.extract_mentions(&entry) }; + tracing::debug!("{:?}", mentions); insert_mentions(&mentions, pool).await?; Ok(entry.to_html(pool).await?) diff --git a/src/web/mod.rs b/src/web/mod.rs index bde8e13..66ab59c 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -21,6 +21,8 @@ struct ContactLink { name: String, contact_id: DbId, } + +#[derive(Debug)] pub struct Layout { contact_links: Vec, user: User,