From 585dd5ac36727b8d680a419f8541a36cfba84c65 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 30 Oct 2024 02:11:09 +0100 Subject: [PATCH] things --- strichliste.lua | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/strichliste.lua b/strichliste.lua index 6ad7d5f..959cc87 100755 --- a/strichliste.lua +++ b/strichliste.lua @@ -2,6 +2,7 @@ local path = os.getenv("PATH_INFO") local method = os.getenv("REQUEST_METHOD") +local query = os.getenv("QUERY_STRING") local function escape(s) return s:gsub("<", "<"):gsub("<", "<") @@ -53,10 +54,34 @@ local function read_log() end end +local function balances() + local users = {} + for _, username, amount, _ in read_log() do + users[username] = (users[username] or 0) + amount + end + return users +end + if path == "/" then - print("Status: 200 OK") - print("Content-Type: text/plain") - print("") + if query == "?log" then + return respond(200, "Log", function() + print("") + print("") + for time, username, amount, comment in read_log() do + print(string.format("", time, escape(username), + amount / 100, escape(comment))) + end + print("
TimeUsernameAmountComment
%d%s%.02f€%s
") + end) + end + return respond(200, "Users", function() + print("") + end) elseif path ~= nil then local username = path:sub(2) if username:match("^[%w_-]+$") == nil then