import { Router } from 'express' import { sqlite } from '../libs/database/init.js' import wrapper, { map } from '../libs/database/wrapper.js' const mapApi = Router() mapApi.get( '/count', (req, res) => { const totalMaps = sqlite.prepare(`SELECT COUNT(*) as count FROM maps`).get() return res.json({ success: true, response: totalMaps.count, }) } ) mapApi.get( '/get/:map', (req, res) => { /* Check if map exists */ if(!wrapper.mapExists(req.params.map)) { return res.json({ success: false, response: "No such map!" }) } return res.json({ success: true, response: map(req.params.map) }) } ) mapApi.get( '/getAll', (req, res) => { return res.json({ success: true, response: wrapper.allMaps() }) } ) mapApi.get( '/category/:category', (req, res) => { /* Check if category exists */ if (!wrapper.categoryExists(req.params.category)) { return res.json({ success: false, response: "Invalid category name!", }) } return res.json({ success: true, response: wrapper.mapCategory(req.params.category) }) } ) mapApi.get( '/leaderboard/race/:map', (req, res) => { /* Check if map exists */ if (!wrapper.mapExists(req.params.map)) { return res.json({ success: false, response: "No such map!", }) } return res.json({ success: true, response: wrapper.leaderboardRace(req.params.map, 1, 20) }) } ) mapApi.get( '/leaderboard/teamrace/:map', (req, res) => { /* Check if map exists */ if (!wrapper.mapExists(req.params.map)) { return res.json({ success: false, response: "No such map!", }) } return res.json({ success: true, response: wrapper.leaderboardTeamrace(req.params.map, 1, 20) }) } ) mapApi.get( '/search', async (req, res) => { /* Check if a query was provided */ if (!req.query.q) { return res.json({ success: false, response: "No query ('host/path?q=query') provided!" }) } /* TODO: Use the searcher function */ } ) export default mapApi