This commit is contained in:
parent
6c6f739110
commit
d69f9b8427
@ -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\/)(?<link>.{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;
|
||||
};
|
||||
|
14
views/top10.html
Normal file
14
views/top10.html
Normal file
@ -0,0 +1,14 @@
|
||||
@include(snippets/header)
|
||||
|
||||
<h3>Top10 ({{ year }}-{{ month }})</h3>
|
||||
<table class="table">
|
||||
@each(f0cks as f0ck)
|
||||
<tr>
|
||||
<td><a href="//f0ck.me/{{ f0ck.id }}"><img src="//f0ck.me/t/{{ f0ck.id }}.webp" /></a></td>
|
||||
<td><a href="//f0ck.me/{{ f0ck.id }}">{{ f0ck.id }}</a></td>
|
||||
<td>{{ f0ck.username }}</td>
|
||||
</tr>
|
||||
@endeach
|
||||
</table>
|
||||
|
||||
@include(snippets/footer)
|
Loading…
Reference in New Issue
Block a user