From 644c287eede443c608eeab0cc6cd41da228947e3 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 6 May 2025 20:25:36 +0200 Subject: Remove "api" prefix on many routes. --- server.js | 16 ++++++++-------- views/game_stats.pug | 25 ------------------------ views/head.pug | 2 +- views/profile.pug | 27 ++++++++++++++------------ views/stats_title.pug | 25 ++++++++++++++++++++++++ views/stats_user.pug | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ views/tm_seed.pug | 6 +++--- views/user_stats.pug | 53 --------------------------------------------------- 8 files changed, 105 insertions(+), 102 deletions(-) delete mode 100644 views/game_stats.pug create mode 100644 views/stats_title.pug create mode 100644 views/stats_user.pug delete mode 100644 views/user_stats.pug diff --git a/server.js b/server.js index 8c8b52f..cfaced7 100644 --- a/server.js +++ b/server.js @@ -446,7 +446,7 @@ function must_pass_altcha(req, res, next) { return next() } -app.get("/api/altcha-challenge", function (_req, res) { +app.get("/altcha-challenge", function (_req, res) { return res.json(altcha_create_challenge()) }) @@ -3206,7 +3206,7 @@ app.get("/tm/pool/:pool_name", function (req, res) { res.render("tm_pool.pug", { seed, pool, roles, players, games, games_by_round }) }) -app.post("/api/tm/register/:seed_id/:level", must_be_logged_in, function (req, res) { +app.post("/tm/register/:seed_id/:level", must_be_logged_in, function (req, res) { let seed_id = req.params.seed_id | 0 let level = req.params.level | 0 let user_id = req.user.user_id @@ -3222,7 +3222,7 @@ app.post("/api/tm/register/:seed_id/:level", must_be_logged_in, function (req, r return res.redirect(req.headers.referer) }) -app.post("/api/tm/withdraw/:seed_id/:level", must_be_logged_in, function (req, res) { +app.post("/tm/withdraw/:seed_id/:level", must_be_logged_in, function (req, res) { let seed_id = req.params.seed_id | 0 let level = req.params.level | 0 let user_id = req.user.user_id @@ -3230,7 +3230,7 @@ app.post("/api/tm/withdraw/:seed_id/:level", must_be_logged_in, function (req, r return res.redirect(req.headers.referer) }) -app.post("/api/tm/start/:seed_id/:level", must_be_administrator, function (req, res) { +app.post("/tm/start/:seed_id/:level", must_be_administrator, function (req, res) { let seed_id = req.params.seed_id | 0 let level = req.params.level | 0 start_tournament_seed(seed_id, level) @@ -4237,23 +4237,23 @@ const SQL_GAME_RATINGS = SQL(` limit 50 `) -app.get("/user-stats/:who_name", must_be_administrator, function (req, res) { +app.get("/stats/user/:who_name", must_be_administrator, function (req, res) { let who = SQL_SELECT_USER_BY_NAME.get(req.params.who_name) if (who) { let stats = SQL_USER_STATS.all(who.user_id, who.user_id) let ratings = SQL_USER_RATINGS.all(who.user_id) - res.render("user_stats.pug", { who, stats, ratings }) + res.render("stats_user.pug", { who, stats, ratings }) } else { return res.status(404).send("Invalid user name.") } }) -app.get("/game-stats/:title_id", must_be_administrator, function (req, res) { +app.get("/stats/title/:title_id", must_be_administrator, function (req, res) { let title_id = req.params.title_id if (title_id in TITLE_TABLE) { let title_name = TITLE_NAME[title_id] let ratings = SQL_GAME_RATINGS.all(title_id) - res.render("game_stats.pug", { title_name, ratings }) + res.render("stats_title.pug", { title_name, ratings }) } else { return res.status(404).send("Invalid title.") } diff --git a/views/game_stats.pug b/views/game_stats.pug deleted file mode 100644 index 692c30b..0000000 --- a/views/game_stats.pug +++ /dev/null @@ -1,25 +0,0 @@ -//- vim:ts=4:sw=4: -doctype html -html - head - include head - title #{title_name} - Ranking - body - include header - article - h1 #{title_name} - Ranking - - table.striped - thead - tr - th Player - th.r Rating - th.r Plays - th.r Last played - tbody - each row in ratings - tr - td= row.name - td.r= row.rating - td.r= row.count - td.r= row.last diff --git a/views/head.pug b/views/head.pug index 20fb9aa..da73d4e 100644 --- a/views/head.pug +++ b/views/head.pug @@ -14,7 +14,7 @@ mixin altcha_script() mixin altcha_widget() if ALTCHA - altcha-widget(challengeurl="/api/altcha-challenge" hidelogo hidefooter auto="onsubmit" style="--altcha-border-radius:0") + altcha-widget(challengeurl="/altcha-challenge" hidelogo hidefooter auto="onsubmit" style="--altcha-border-radius:0") mixin social(title,description,game) meta(property="og:title" content=title) diff --git a/views/profile.pug b/views/profile.pug index de6e5c4..2f9218d 100644 --- a/views/profile.pug +++ b/views/profile.pug @@ -18,7 +18,7 @@ html +userstats(who, ratings) - h3 Account + h3 Notifications p Your mail address is #{user.mail} @@ -32,17 +32,6 @@ html if mail.notify p Disable mail notifications - p - | Change password - br - | Change mail address - br - | Change user name - br - | Change profile text - p - | Delete account - if ENABLE_WEBHOOKS if !webhook p Configure webhook @@ -55,6 +44,20 @@ html dt Configure webhook dd= new URL(webhook.url).hostname + h3 Account + + p + | Change password + br + | Change mail address + br + | Change user name + br + | Change profile text + + p + | Delete account + p form(action="/account/logout" method="post") button(type="submit") Logout diff --git a/views/stats_title.pug b/views/stats_title.pug new file mode 100644 index 0000000..2107b93 --- /dev/null +++ b/views/stats_title.pug @@ -0,0 +1,25 @@ +//- vim:ts=4:sw=4: +doctype html +html + head + include head + title #{title_name} - Ranking + body + include header + article + h1 #{title_name} - Ranking + + table.striped + thead + tr + th Player + th.r Rating + th.r Plays + th.r Last played + tbody + each row in ratings + tr + td #{row.name} + td.r= row.rating + td.r= row.count + td.r= row.last diff --git a/views/stats_user.pug b/views/stats_user.pug new file mode 100644 index 0000000..3b201ef --- /dev/null +++ b/views/stats_user.pug @@ -0,0 +1,53 @@ +//- vim:ts=4:sw=4: +- let all_won = 0 +- let all_total = 0 +doctype html +html + head + include head + title Statistics for #{who.name} + body + include header + article + h1 Statistics for #{who.name} + + table.striped + thead + tr + th Title + th Scenario + th Role + th.r Played + th.r Won + tbody + each row in stats + tr + - all_won += row.won + - all_total += row.total + td= row.title_name + td= row.scenario + td= row.role + td.r= row.total + td.r= Math.round(row.won*100/row.total) + "%" + tfoot + tr + td Overall + td + td + td.r= all_total + td.r= Math.round(all_won*100/all_total) + "%" + + table.striped + thead + tr + th Title + th.r Rating + th.r Plays + th.r Last played + tbody + each row in ratings + tr + td= row.title_name + td.r= row.rating + td.r= row.count + td.r= row.last diff --git a/views/tm_seed.pug b/views/tm_seed.pug index 45659c5..abf02c1 100644 --- a/views/tm_seed.pug +++ b/views/tm_seed.pug @@ -67,11 +67,11 @@ html if user if queue.find(p => p.user_id === user.user_id) - form(method="post" action="/api/tm/withdraw/" + seed.seed_id + "/" + (ix+1)) + form(method="post" action="/tm/withdraw/" + seed.seed_id + "/" + (ix+1)) button(disabled) Register button(type="submit") Withdraw else if may_register && may_join_seed_level(user.user_id, seed.seed_id, ix+1) - form(method="post" action="/api/tm/register/" + seed.seed_id + "/" + (ix+1)) + form(method="post" action="/tm/register/" + seed.seed_id + "/" + (ix+1)) button(type="submit") Register button(disabled) Withdraw else @@ -81,7 +81,7 @@ html if user.user_id === 1 if queue.length >= seed.pool_size - form(method="post" action="/api/tm/start/" + seed.seed_id + "/" + (ix+1)) + form(method="post" action="/tm/start/" + seed.seed_id + "/" + (ix+1)) button(type="submit") Start else p Login or sign up to register. diff --git a/views/user_stats.pug b/views/user_stats.pug deleted file mode 100644 index 3b201ef..0000000 --- a/views/user_stats.pug +++ /dev/null @@ -1,53 +0,0 @@ -//- vim:ts=4:sw=4: -- let all_won = 0 -- let all_total = 0 -doctype html -html - head - include head - title Statistics for #{who.name} - body - include header - article - h1 Statistics for #{who.name} - - table.striped - thead - tr - th Title - th Scenario - th Role - th.r Played - th.r Won - tbody - each row in stats - tr - - all_won += row.won - - all_total += row.total - td= row.title_name - td= row.scenario - td= row.role - td.r= row.total - td.r= Math.round(row.won*100/row.total) + "%" - tfoot - tr - td Overall - td - td - td.r= all_total - td.r= Math.round(all_won*100/all_total) + "%" - - table.striped - thead - tr - th Title - th.r Rating - th.r Plays - th.r Last played - tbody - each row in ratings - tr - td= row.title_name - td.r= row.rating - td.r= row.count - td.r= row.last -- cgit v1.2.3