about summary refs log tree commit diff
path: root/splorm/src/handler
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2026-09-26 03:39:25 -0500
committergennyble <gen@nyble.dev>2026-09-26 03:39:25 -0500
commit2d53b7007f513ca99097aa95faab88e44af8cb86 (patch)
treebc603b8f868f914c7e107e90c8762651b953dc3c /splorm/src/handler
parent10cd0527b16aa3d01cb4af708917ad95db142a1b (diff)
make change message optional when editing quarks
Diffstat (limited to 'splorm/src/handler')
-rw-r--r--splorm/src/handler/quark/api.rs19
-rw-r--r--splorm/src/handler/quark/index.rs1
-rw-r--r--splorm/src/handler/quark/markup.rs5
-rw-r--r--splorm/src/handler/quark/mod.rs1
4 files changed, 20 insertions, 6 deletions
diff --git a/splorm/src/handler/quark/api.rs b/splorm/src/handler/quark/api.rs
index e1c403a..6b019c1 100644
--- a/splorm/src/handler/quark/api.rs
+++ b/splorm/src/handler/quark/api.rs
@@ -67,6 +67,15 @@ pub async fn edit(
 			}: EditForm = data.try_into()?;
 			let redirect = api_redirect(&settings, &name, format!("../{name}"));
 
+			let commit = match commit {
+				Some(commit) => commit,
+				None => {
+					let time = timeparse::format::human_with_time(&timeparse::whichever_now());
+					format!("edited '{name}' {time}")
+				}
+			};
+			tracing::trace!("editing with commit='{commit}'");
+
 			wikarden
 				.modify(&name, false, content, commit)
 				.await
@@ -144,7 +153,7 @@ struct CreateForm {
 struct EditForm {
 	name: String,
 	content: String,
-	commit: String,
+	commit: Option<String>,
 }
 
 /// what an endpoint does; mutually exclusive
@@ -184,6 +193,8 @@ impl MultipartFields {
 				Some($field.text().await.map_err(|_| {
 					RuntimeError::bad_request(format!("failed to decode field '{}'", $fieldname))
 				})?)
+				.map(|s| if s.is_empty() { None } else { Some(s) })
+				.flatten()
 			};
 		}
 
@@ -239,11 +250,11 @@ impl TryInto<EditForm> for MultipartFields {
 	type Error = RuntimeError;
 
 	fn try_into(self) -> Result<EditForm, RuntimeError> {
-		match (self.name, self.content, self.commit) {
-			(Some(name), Some(content), Some(commit)) => Ok(EditForm {
+		match (self.name, self.content) {
+			(Some(name), Some(content)) => Ok(EditForm {
 				name,
 				content,
-				commit,
+				commit: self.commit,
 			}),
 			_ => Err(RuntimeError::bad_request("edit request missing fields")),
 		}
diff --git a/splorm/src/handler/quark/index.rs b/splorm/src/handler/quark/index.rs
index 8bb0dca..0cea887 100644
--- a/splorm/src/handler/quark/index.rs
+++ b/splorm/src/handler/quark/index.rs
@@ -54,6 +54,7 @@ pub async fn index(
 	}
 
 	let page = PageSettings {
+		title: "Quark",
 		name: settings.wikarden_index(),
 		with_tools: maybe_session.is_some(),
 		can_be_deleted: false,
diff --git a/splorm/src/handler/quark/markup.rs b/splorm/src/handler/quark/markup.rs
index f19603f..72d2501 100644
--- a/splorm/src/handler/quark/markup.rs
+++ b/splorm/src/handler/quark/markup.rs
@@ -13,6 +13,7 @@ use wikarden::Wikarden;
 use crate::{RuntimeError, config::Settings};
 
 pub struct PageSettings<'s> {
+	pub title: &'s str,
 	pub name: &'s str,
 	pub with_tools: bool,
 	pub can_be_deleted: bool,
@@ -29,8 +30,8 @@ pub async fn render_page<'s>(
 ) -> Result<Response, RuntimeError> {
 	let template_path = settings.quark_template_dir().join("page.html");
 	let mut template = super::open_template_path(template_path, &settings).await?;
-	template.set("title", page.name);
-	template.set("page-title", page.name);
+	template.set("title", page.title);
+	template.set("page-title", page.title);
 
 	match wikarden.source(page.name, false).await {
 		Err(e) => template.set("main", format!("<h2>{e:?}</h2>")),
diff --git a/splorm/src/handler/quark/mod.rs b/splorm/src/handler/quark/mod.rs
index 2924dc9..0faf215 100644
--- a/splorm/src/handler/quark/mod.rs
+++ b/splorm/src/handler/quark/mod.rs
@@ -79,6 +79,7 @@ async fn page(
 	}
 
 	let page = PageSettings {
+		title: &name,
 		name: &name,
 		with_tools: maybe_session.is_some(),
 		can_be_deleted: true,