Skip to content

Commit

Permalink
Test leaderboards database and endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Jan 13, 2024
1 parent 3d5d1ef commit 433abb9
Show file tree
Hide file tree
Showing 7 changed files with 1,529 additions and 16 deletions.
26 changes: 26 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require('dotenv').config();

const sqlite3 = require('sqlite3');
const fs = require('fs');
const express = require('express');
const session = require('express-session');
Expand All @@ -18,6 +19,29 @@ const app = express();
const port = 3000;
const visitors = {};

const dbPath = process.env.DB_PATH;

// Check if the database file exists, if not, initialize it
if (!fs.existsSync(dbPath)) {
const db = new sqlite3.Database(dbPath);

// Create the players table if it doesn't exist
db.serialize(() => {
db.run(`
CREATE TABLE IF NOT EXISTS players (
id INTEGER PRIMARY KEY AUTOINCREMENT,
steam_id TEXT UNIQUE,
mmr INTEGER DEFAULT 0,
matches_won INTEGER DEFAULT 0,
matches_lost INTEGER DEFAULT 0
)
`);
});

// Close the database connection
db.close();
}

// Passport
passport.serializeUser((user, done) => {
done(null, user);
Expand Down Expand Up @@ -145,6 +169,8 @@ app.get('/credits', (req, res) => res.redirect(credits));
app.get('/steam', (req, res) => res.redirect(steam));
app.get('/discord', (req, res) => res.redirect(discord));
app.use('/upload', require('./src/upload'));
app.use('/report_match', require('./src/report_match'));
app.use('/leaderboards', require('./src/leaderboards'));
app.get('/admin', adm, (req, res) => res.redirect('/admin/system'));
app.use('/admin/system', adm, require('./src/admin/system'));
app.use('/admin/visitors', adm, require('./src/admin/visitors')(visitors));
Expand Down
Loading

0 comments on commit 433abb9

Please sign in to comment.