diff options
author | metamuffin <metamuffin@disroot.org> | 2024-10-30 23:09:58 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-10-30 23:09:58 +0100 |
commit | 82e76462305d8c433befb341fa372a73efb8894d (patch) | |
tree | a61c6720807b974c6f8ff5d0d6f4f0708a149167 | |
parent | c3dadcc5a374fb9c17e91a1d6a57a252c67387c8 (diff) | |
download | abrechenbarkeit-82e76462305d8c433befb341fa372a73efb8894d.tar abrechenbarkeit-82e76462305d8c433befb341fa372a73efb8894d.tar.bz2 abrechenbarkeit-82e76462305d8c433befb341fa372a73efb8894d.tar.zst |
config and transaction sounds
-rwxr-xr-x | strichliste.lua | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/strichliste.lua b/strichliste.lua index 4e941b9..c0f73a2 100755 --- a/strichliste.lua +++ b/strichliste.lua @@ -29,6 +29,22 @@ local function parse_query(q) return data end +local function load_config() + local log = io.open("config", "r") + if log == nil then return {} end + local config = {} + for l in log:lines("l") do + if l ~= "" and l[0] ~= "#" then + local key, value = string.match(l, "^([^=]+)=([^=]*)") + if key ~= nil and value ~= nil then + config[key] = value + end + end + end + return config +end + +local config = load_config() local path = os.getenv("PATH_INFO") local method = os.getenv("REQUEST_METHOD") local query = parse_query(os.getenv("QUERY_STRING")) @@ -47,7 +63,6 @@ local stylesheet = [[ form h3 { margin: 5px; } ]] --- local script = io.open("main.js"):read("a") local script = [[ document.addEventListener("keypress", ev => { if (!(document.activeElement instanceof HTMLInputElement)) { @@ -70,6 +85,7 @@ local function respond(status, title, body) <meta charset="utf-8" /> <style>%s</style> <script>%s</script> + %s </head> <body> <nav> @@ -77,7 +93,7 @@ local function respond(status, title, body) <span><a href="/?log">View Log</a></span> <span><a href="https://codeberg.org/metamuffin/strichliste">Source</a></span> </nav> - ]], escape(title), stylesheet, script)) + ]], escape(title), stylesheet, script, config.head_extra or "")) body() print("</body></html>") end @@ -187,9 +203,13 @@ local function r_user_post(username) log:write(string.format("%d,%s,%d,%s\n", time, username, amount, comment)) log:flush() log:close() - return string.format( - "<div class=\"notif\"><p>Transaction successful: <strong class=\"amount-%s\">%.02f€</strong> (%s)</p></div>", - amount >= 0 and "pos" or "neg", amount / 100, escape(comment) + return string.format([[ + <div class=\"notif\"><p>Transaction successful: <strong class=\"amount-%s\">%.02f€</strong> (%s)</p></div> + <audio src="%s" autoplay></audio> + ]], + amount >= 0 and "pos" or "neg", amount / 100, + escape(comment), + config.transaction_sound or "" ) end @@ -204,18 +224,19 @@ local function r_user(username) local last_txn = last_txns()[username] local new_user = balance == nil balance = balance or 0 + if notif then print(notif) end if new_user then print([[ <div class="notif"><p><i>This user account does not exist yet. It will only be created after the first transaction.</i></p></div> ]]) + else + print(string.format([[ + <p>Current balance: <span class="amount-%s">%.02f€</p> + ]], balance >= 0 and "pos" or "neg", balance / 100)) + print(string.format([[ + <p>Last transaction added %s ago. <a href="/%s?log">View user log</a> + ]], format_duration(os.time() - last_txn), username)) end - if notif then print(notif) end - print(string.format([[ - <p>Current balance: <span class="amount-%s">%.02f€</p> - ]], balance >= 0 and "pos" or "neg", balance / 100)) - print(string.format([[ - <p>Last transaction added %s ago. <a href="/%s?log">View user log</a> - ]], format_duration(os.time() - last_txn), username)) print([[ <form class="transaction box" action="" method="POST"> <h3>Create Transaction</h3> |