diff --git a/src/inc/routes/ranking.mjs b/src/inc/routes/ranking.mjs index f741bae..4cafc46 100644 --- a/src/inc/routes/ranking.mjs +++ b/src/inc/routes/ranking.mjs @@ -1,5 +1,7 @@ import db from "../../inc/sql.mjs"; import lib from "../lib.mjs"; +import config from "../config.mjs"; +import fetch from "flumm-fetch"; export default (router, tpl) => { router.get(/^\/ranking$/, async (req, res) => { @@ -53,5 +55,43 @@ export default (router, tpl) => { } }); + router.get(/^\/top10$/, async (req, res) => { + const d = new Date(); + d.setMonth(d.getMonth() - 1); + const month = (d.getMonth() + 1).toString().padStart(2, '0'); + const year = d.getFullYear(); + + const url = `${config.apis.stats.url1}/${year}-${month}/${config.apis.stats.url2}`; + const options = { + method: 'GET', + headers: { + Authorization: config.apis.stats.auth + } + }; + + const topres = await (await fetch(url, options)).text(); + const list = topres.match(/(f0ck.me\/b\/)(?.{8}\.\w*)/g).slice(0, 10).map(e => e.split('/')[2]); + + const f0cks = []; + for(const l of list) { + const f = await db` + select id, username + from items + where dest = ${l} + limit 1 + `; + f0cks.push(f[0]); + } + + res.reply({ + body: tpl.render('top10', { + f0cks, + year, + month, + tmp: null + }, req) + }); + }); + return router; }; diff --git a/views/top10.html b/views/top10.html new file mode 100644 index 0000000..9b06596 --- /dev/null +++ b/views/top10.html @@ -0,0 +1,14 @@ +@include(snippets/header) + +

Top10 ({{ year }}-{{ month }})

+ + @each(f0cks as f0ck) + + + + + + @endeach +
{{ f0ck.id }}{{ f0ck.username }}
+ +@include(snippets/footer)