changed /submit route to relative, and fixed output_file path definition

This commit is contained in:
2025-12-01 21:15:43 +01:00
parent a80525b06d
commit 98a7df2931
5 changed files with 8 additions and 7 deletions
Generated
+1 -1
View File
@@ -351,7 +351,7 @@ checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
[[package]] [[package]]
name = "form-generator" name = "form-generator"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"askama", "askama",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "form-generator" name = "form-generator"
version = "0.1.0" version = "0.1.1"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
+1 -1
View File
@@ -20,7 +20,7 @@
{ {
packages.default = pkgs.rustPlatform.buildRustPackage { packages.default = pkgs.rustPlatform.buildRustPackage {
pname = "form-generator"; pname = "form-generator";
version = "0.1.0"; version = "0.1.1";
src = ./.; src = ./.;
cargoLock = { cargoLock = {
+4 -3
View File
@@ -45,7 +45,6 @@ struct FieldDef {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct AppConfig { struct AppConfig {
json_output: String,
submit_button: String, submit_button: String,
fields: Vec<FieldDef>, fields: Vec<FieldDef>,
} }
@@ -60,6 +59,7 @@ struct ResponseEntry {
struct AppState { struct AppState {
cfg: Arc<AppConfig>, cfg: Arc<AppConfig>,
file_lock: Arc<Mutex<()>>, file_lock: Arc<Mutex<()>>,
output_file: String,
} }
#[tokio::main] #[tokio::main]
@@ -74,7 +74,7 @@ async fn main() -> anyhow::Result<()> {
tracing::info!( tracing::info!(
"Loaded config: '{}', writing answers to '{}' with {} fields", "Loaded config: '{}', writing answers to '{}' with {} fields",
cli.config_path, cli.config_path,
cfg.json_output, cli.output_file,
cfg.fields.len() cfg.fields.len()
); );
@@ -105,6 +105,7 @@ async fn main() -> anyhow::Result<()> {
let state = AppState { let state = AppState {
cfg: Arc::new(cfg), cfg: Arc::new(cfg),
file_lock: Arc::new(Mutex::new(())), file_lock: Arc::new(Mutex::new(())),
output_file: cli.output_file.clone(),
}; };
let app = Router::new() let app = Router::new()
@@ -160,7 +161,7 @@ async fn submit(
}; };
let _guard = state.file_lock.lock().await; let _guard = state.file_lock.lock().await;
let path = &state.cfg.json_output; let path = &state.output_file;
let mut existing: Vec<ResponseEntry> = match std::fs::read_to_string(path) { let mut existing: Vec<ResponseEntry> = match std::fs::read_to_string(path) {
Ok(raw) => serde_json::from_str(&raw).unwrap_or(Vec::new()), Ok(raw) => serde_json::from_str(&raw).unwrap_or(Vec::new()),
+1 -1
View File
@@ -4,7 +4,7 @@
{% block content %} {% block content %}
<div class="form-container"> <div class="form-container">
<form action="/submit" method="POST" autocomplete="off"> <form action="submit" method="POST" autocomplete="off">
{% for f in fields %} {% for f in fields %}
{% if f.html_before.is_some() %} {% if f.html_before.is_some() %}
{{ f.html_before.as_ref().unwrap() | safe }} {{ f.html_before.as_ref().unwrap() | safe }}