forked from f0ck/f0ckv2
add tag page
This commit is contained in:
29
src/inc/routes/toptags.mjs
Normal file
29
src/inc/routes/toptags.mjs
Normal file
@ -0,0 +1,29 @@
|
||||
import db from "../../inc/sql.mjs";
|
||||
import cfg from "../../inc/config.mjs";
|
||||
import f0cklib from "../routeinc/f0cklib.mjs";
|
||||
|
||||
export default (router, tpl) => {
|
||||
router.get(/^\/tags$/, async (req, res) => {
|
||||
|
||||
const phrase = cfg.websrv.phrases[~~(Math.random() * cfg.websrv.phrases.length)];
|
||||
|
||||
const toptags = await db`
|
||||
SELECT t.id, t.tag, COUNT(DISTINCT ta.item_id) AS total_items
|
||||
FROM tags t
|
||||
LEFT JOIN tags_assign ta ON t.id = ta.tag_id
|
||||
GROUP BY t.id, t.tag
|
||||
ORDER BY total_items DESC
|
||||
LIMIT 500
|
||||
;
|
||||
`;
|
||||
|
||||
res.reply({
|
||||
body: tpl.render('tags', {
|
||||
toptags,
|
||||
phrase,
|
||||
tmp: null
|
||||
}, req)
|
||||
});
|
||||
});
|
||||
return router;
|
||||
};
|
Reference in New Issue
Block a user