import { Router } from 'express' import wrapper from '../libs/database/wrapper.js' import tx from '../libs/routex.js' import { getStats } from '../libs/serverStats.js' const routes = Router() routes.get( '/', (req, res) => { tx(req, res)('pages/landing.njk', null, { currentSection: null }) } ) routes.get( '/search', (req, res) => { const map = req.query.qmap ?? "" const categories = req.query.categories ?? [] const stars = req.query.stars ?? [] const sort = req.query.sortBy ?? "map" const order = req.query.order === "desc" ? "desc" : "asc" const maps = wrapper.searchMap(map, categories.split(","), stars.split(","), sort, order) tx(req, res)('pages/maps.njk', { maps }, true, { currentSection: "maps" }) } ) routes.get( '/maps', (req, res) => { const maps = wrapper.allMaps() tx(req, res)('pages/maps.njk', { maps }, true, { currentSection: "maps" }) } ) routes.get( '/maps/:map', (req, res) => { const map = wrapper.map(req.params.map) const graphMap = wrapper.graphMap(req.params.map) const raceLeaderboard = wrapper.leaderboardRace(req.params.map, 1, 10) const teamLeaderboard = wrapper.leaderboardTeamrace(req.params.map, 1, 10) const [success, error] = map ? [true, "No error!"] : [false, "Map not found!"] tx(req, res)('pages/mapSingle.njk', { map, graphMap, raceLeaderboard, teamLeaderboard, error }, success, { currentSection: "maps" }) } ) routes.get( '/status', (req, res) => { const stats = getStats() tx(req, res)('pages/stats.njk', { stats }, true, { currentSection: null }) } ) export default routes