From 19bf677e98514f16e77e18f9bbbfbcc5a0cc6ba2 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Sat, 8 Jan 2022 10:14:50 +1100 Subject: [PATCH] Store contact and feedback logs in /database.logjson rather than /_logs/*.json --- .gitignore | 1 - contact/index.html.jst | 17 +++++++++++------ feedback.html.jst | 17 +++++++++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index d9822db..cbdda53 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ .*.less .*.min .*.svg -/_logs /_zet/site.* /database.logjson /node_modules diff --git a/contact/index.html.jst b/contact/index.html.jst index f8bdb38..2125210 100644 --- a/contact/index.html.jst +++ b/contact/index.html.jst @@ -31,12 +31,17 @@ return async env => { date = new XDate() query.date = date.toUTCString() - await env.site.ensure_dir('/_logs') - env.site.modify_json( - `/_logs/contact_${date.toUTCString('yyyyMMdd')}.json`, - [], - async result => {result.value.push(query)} - ) + let transaction = env.site.database.Transaction() + ;( + await ( + await ( + await ( + await transaction.get({}) + ).get('logs', {}) + ).get(date.toUTCString('yyyyMMdd'), {}) + ).get('contact', []) + ).push(transaction.json_to_logjson(query)) + transaction.commit() // send email (asynchronously) let emailjs_contact = await env.site.get_emailjs( diff --git a/feedback.html.jst b/feedback.html.jst index 11d951f..38fe202 100644 --- a/feedback.html.jst +++ b/feedback.html.jst @@ -24,12 +24,17 @@ return async env => { date = new XDate() query.date = date.toUTCString() - await env.site.ensure_dir('/_logs') - env.site.modify_json( - `/_logs/feedback_${date.toUTCString('yyyyMMdd')}.json`, - [], - async result => {result.value.push(query)} - ) + let transaction = env.site.database.Transaction() + ;( + await ( + await ( + await ( + await transaction.get({}) + ).get('logs', {}) + ).get(date.toUTCString('yyyyMMdd'), {}) + ).get('feedback', []) + ).push(transaction.json_to_logjson(query)) + transaction.commit() // send email (asynchronously) let emailjs_feedback = await env.site.get_emailjs( -- 2.34.1