2021-10-30 21:39:21 +02:00
|
|
|
import { Router } from 'express'
|
2021-11-04 22:50:57 +01:00
|
|
|
import wrapper from '../libs/database/wrapper.js'
|
|
|
|
import tx from '../libs/routex.js'
|
2021-11-05 21:04:53 +01:00
|
|
|
import { getStats } from '../libs/serverStats.js'
|
2021-10-30 21:39:21 +02:00
|
|
|
|
|
|
|
const routes = Router()
|
|
|
|
|
|
|
|
routes.get(
|
|
|
|
'/',
|
2021-11-04 21:33:42 +01:00
|
|
|
(req, res) => {
|
2021-11-04 22:50:57 +01:00
|
|
|
tx(req, res)('pages/landing.njk', null, { currentSection: null })
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-11-06 15:42:11 +01:00
|
|
|
routes.get(
|
2021-11-13 20:12:01 +01:00
|
|
|
'/maps',
|
2021-11-06 15:42:11 +01:00
|
|
|
(req, res) => {
|
2021-11-06 16:55:37 +01:00
|
|
|
const map = req.query.map ?? ""
|
|
|
|
const categories = req.query.categories ? req.query.categories : "Novice,Moderate,Brutal,Insane,Dummy,DDmaX,Oldschool,Solo,Race,Fun"
|
2021-11-13 02:34:52 +01:00
|
|
|
const stars = req.query.stars ? req.query.stars : "0,1,2,3,4,5"
|
2021-11-06 16:55:37 +01:00
|
|
|
const sort = req.query.sortBy ? req.query.sortBy : "map"
|
2021-11-06 15:42:11 +01:00
|
|
|
const order = req.query.order === "desc" ? "desc" : "asc"
|
2021-11-13 20:12:01 +01:00
|
|
|
const page = req.query.page ? parseInt(req.query.page) : 1
|
2021-11-06 15:42:11 +01:00
|
|
|
|
2021-11-13 02:28:43 +01:00
|
|
|
const maps = wrapper.searchMap(map, categories.split(","), stars.split(","), sort, order, page)
|
2021-11-06 15:42:11 +01:00
|
|
|
|
2021-11-13 21:28:28 +01:00
|
|
|
tx(req, res)('pages/maps.njk', { maps }, true, { currentSection: "maps", query: req.query })
|
2021-11-06 15:42:11 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-11-04 22:50:57 +01:00
|
|
|
routes.get(
|
|
|
|
'/maps/:map',
|
|
|
|
(req, res) => {
|
|
|
|
const map = wrapper.map(req.params.map)
|
2021-11-05 09:36:43 +01:00
|
|
|
const graphMap = wrapper.graphMap(req.params.map)
|
2021-11-04 23:20:41 +01:00
|
|
|
const raceLeaderboard = wrapper.leaderboardRace(req.params.map, 1, 10)
|
|
|
|
const teamLeaderboard = wrapper.leaderboardTeamrace(req.params.map, 1, 10)
|
2021-11-05 09:36:43 +01:00
|
|
|
|
2021-11-05 11:57:17 +01:00
|
|
|
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" })
|
2021-11-04 21:33:42 +01:00
|
|
|
}
|
2021-10-30 21:39:21 +02:00
|
|
|
)
|
|
|
|
|
2021-11-07 12:18:13 +01:00
|
|
|
routes.get(
|
|
|
|
'/leaderboards',
|
|
|
|
(req, res) => {
|
2021-11-07 22:15:15 +01:00
|
|
|
const region = "Global"
|
2021-11-07 12:18:13 +01:00
|
|
|
const leaderboards = {
|
2021-11-07 22:15:15 +01:00
|
|
|
points: wrapper.leaderboardPoints("points", region, 1, 10),
|
|
|
|
pointsRank: wrapper.leaderboardPoints("pointsRank", region, 1, 10),
|
|
|
|
pointsTeam: wrapper.leaderboardPoints("pointsTeam", region, 1, 10),
|
|
|
|
pointsThisWeek: wrapper.leaderboardPoints("pointsThisWeek", region, 1, 10),
|
|
|
|
pointsThisMonth: wrapper.leaderboardPoints("pointsThisMonth", region, 1, 10)
|
2021-11-07 12:18:13 +01:00
|
|
|
}
|
|
|
|
|
2021-11-07 12:43:05 +01:00
|
|
|
tx(req, res)('pages/leaderboards.njk', { leaderboards }, true, { currentSection: "leaderboards" })
|
2021-11-07 12:18:13 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-11-07 22:15:15 +01:00
|
|
|
routes.get(
|
|
|
|
'/leaderboards/:region',
|
|
|
|
(req, res) => {
|
|
|
|
const region = req.params.region.match(/^(Global|Europe|Asia|SA|NA|Africa|ME|OLD|Other)$/) ? req.params.region : "Global"
|
|
|
|
const leaderboards = {
|
|
|
|
points: wrapper.leaderboardPoints("points", region, 1, 10),
|
|
|
|
pointsRank: wrapper.leaderboardPoints("pointsRank", region, 1, 10),
|
|
|
|
pointsTeam: wrapper.leaderboardPoints("pointsTeam", region, 1, 10),
|
|
|
|
pointsThisWeek: wrapper.leaderboardPoints("pointsThisWeek", region, 1, 10),
|
|
|
|
pointsThisMonth: wrapper.leaderboardPoints("pointsThisMonth", region, 1, 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
tx(req, res)('pages/leaderboards.njk', { leaderboards, region }, true, { currentSection: "leaderboards" })
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-11-22 18:45:34 +01:00
|
|
|
routes.get(
|
|
|
|
'/players/:player',
|
|
|
|
(req, res) => {
|
|
|
|
const player = wrapper.player(req.params.player)
|
2021-11-22 18:52:09 +01:00
|
|
|
const finishedMaps = wrapper.finishedMaps(req.params.player)
|
|
|
|
const unfinishedMaps = wrapper.unfinishedMaps(req.params.player)
|
2021-11-22 18:45:34 +01:00
|
|
|
const [success, error] = player ? [true, null] : [false, `Player ${req.params.player} does not exist!`]
|
|
|
|
|
2021-11-22 18:52:09 +01:00
|
|
|
tx(req, res)('pages/playerProfile.njk', { player, finishedMaps, unfinishedMaps, error }, success, { currentSection: "players" })
|
2021-11-22 18:45:34 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-11-05 21:04:53 +01:00
|
|
|
routes.get(
|
|
|
|
'/status',
|
|
|
|
(req, res) => {
|
|
|
|
const stats = getStats()
|
|
|
|
|
|
|
|
tx(req, res)('pages/stats.njk', { stats }, true, { currentSection: null })
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-11-13 20:58:00 +01:00
|
|
|
routes.get(
|
|
|
|
'/credits',
|
|
|
|
(req, res) => {
|
|
|
|
tx(req, res)('pages/credits.njk', {}, true, { currentSection: null })
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
routes.get(
|
|
|
|
'/api-reference',
|
|
|
|
(req, res) => {
|
|
|
|
tx(req, res)('pages/reference.njk', {}, true, { currentSection: null })
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
routes.get(
|
|
|
|
'/changelog',
|
|
|
|
(req, res) => {
|
|
|
|
tx(req, res)('pages/changelogs.njk', {}, true, { currentSection: null })
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-10-30 21:39:21 +02:00
|
|
|
export default routes
|