express: clear session and send a map

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2023-09-15 08:26:01 -04:00
parent 094465b9a7
commit 2710d482f6
Signed by: vbatts
GPG key ID: E30EFAA812C6E5ED
4 changed files with 22 additions and 7 deletions

View file

@ -5,7 +5,7 @@ const app = express();
const port = 3000;
// Create an SQLite database and initialize tables
const db = new sqlite3.Database('mydb.db', (err) => {
const db = new sqlite3.Database('db/results.db', (err) => {
if (err) {
console.error('Error opening SQLite database:', err.message);
} else {
@ -14,6 +14,7 @@ const db = new sqlite3.Database('mydb.db', (err) => {
CREATE TABLE IF NOT EXISTS button_clicks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT,
animal_name TEXT,
button_name TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
time_difference INTEGER -- Add this column for time difference
@ -33,8 +34,9 @@ app.get('/asset/frontend.js', (req, res) => {
});
// Route to get a random animal name
app.get('/getRandomAnimal', async (req, res) => {
app.get('/getNextAnimal', async (req, res) => {
try {
// TODO this is currently random, and should have a bit of reasoning behind the next choice
const animals = ['Dog', 'Cat', 'Elephant', 'Lion', 'Giraffe'];
const randomIndex = Math.floor(Math.random() * animals.length);
const randomAnimal = animals[randomIndex];