This commit is contained in:
Flummi
2021-06-24 05:10:55 +02:00
parent f3e357d8a4
commit 5b7dd4293c
9 changed files with 53 additions and 12 deletions

View File

@ -46,7 +46,8 @@ router.post(/^\/login(\/)?$/, async (req, res) => {
session: lib.md5(session),
browser: req.headers["user-agent"],
created_at: stamp,
last_used: stamp
last_used: stamp,
last_action: "/login"
});
return res.writeHead(301, {
@ -87,8 +88,15 @@ router.get(/^\/login\/test$/, async (req, res) => {
});
router.get(/^\/admin(\/)?$/, auth, async (req, res) => { // frontpage
const totals = await sql("items")
.select(
sql.raw("(select count(*) from items) total"),
sql.raw("sum(if(ifnull(tags_assign.item_id, 0) = 0, 1, 0)) untagged"),
sql.raw("sum(if(ifnull(tags_assign.item_id, 1) = 1, 0, 1)) tagged"))
.leftJoin("tags_assign", "tags_assign.item_id", "items.id");
res.reply({
body: tpl.render("views/admin", {}, req)
body: tpl.render("views/admin", { totals: totals[0] }, req)
});
});
@ -98,15 +106,30 @@ router.get(/^\/admin\/sessions(\/)?$/, auth, async (req, res) => {
.select("user_sessions.*", "user.user")
.orderBy("user.id");
const totals = await sql("items")
.select(
sql.raw("(select count(*) from items) total"),
sql.raw("sum(if(ifnull(tags_assign.item_id, 0) = 0, 1, 0)) untagged"),
sql.raw("sum(if(ifnull(tags_assign.item_id, 1) = 1, 0, 1)) tagged"))
.leftJoin("tags_assign", "tags_assign.item_id", "items.id");
res.reply({
body: tpl.render("views/admin_sessions", {
sessions: rows
sessions: rows,
totals: totals[0]
}, req)
});
});
router.get(/^\/admin\/test(\/)?$/, auth, async (req, res) => {
let ret;
const totals = await sql("items")
.select(
sql.raw("(select count(*) from items) total"),
sql.raw("sum(if(ifnull(tags_assign.item_id, 0) = 0, 1, 0)) untagged"),
sql.raw("sum(if(ifnull(tags_assign.item_id, 1) = 1, 0, 1)) tagged"))
.leftJoin("tags_assign", "tags_assign.item_id", "items.id");
if(Object.keys(req.url.qs).length > 0) {
const tag = req.url.qs.tag;
@ -121,7 +144,8 @@ router.get(/^\/admin\/test(\/)?$/, auth, async (req, res) => {
res.reply({
body: tpl.render("views/admin_search", {
result: ret
result: ret,
totals: totals[0]
}, req)
});
});

View File

@ -172,7 +172,7 @@ router.post(/^\/api\/v2\/admin\/tags\/delete$/, auth, async (req, res) => {
q = q.andWhere("prefix", `${req.session.user}@webinterface`);
const reply = !!(await q);
await cleanTags();
//await cleanTags();
return res.reply({ body: JSON.stringify({
success: reply,

View File

@ -13,7 +13,12 @@ const allowedMimes = [ "audio", "image", "video", "%" ];
router.get(/^\/(audio\/?|image\/?|video\/?)?(p\/\d+)?$/, async (req, res) => {
const tmpmime = (allowedMimes.filter(n => req.url.split[0].startsWith(n))[0] ? req.url.split[0] : "");
const mime = tmpmime + "%";
const total = (await sql("items").where("mime", "like", mime).count("* as total"))[0].total;
const total = (
await sql("items")
.where("mime", "like", mime)
.count("* as total")
)[0].total;
const pages = +Math.ceil(total / cfg.websrv.eps);
const page = Math.min(pages, +req.url.split[tmpmime.length > 0 ? 2 : 1] || 1);

View File

@ -65,7 +65,12 @@ import router from "./inc/router.mjs";
if(user.length > 0) {
req.session = user[0];
await sql("user_sessions").update("last_used", (Date.now() / 1e3)).where("id", user[0].sess_id);
let q = sql("user_sessions")
.update("last_used", (Date.now() / 1e3))
.where("id", user[0].sess_id);
if(!req.url.pathname.match(/^\/(s|b|t|ca)/))
q = q.update("last_action", req.url.pathname)
await q;
}
else { // delete session
return res.writeHead(301, {
@ -85,7 +90,7 @@ import router from "./inc/router.mjs";
if(r = router.routes.getRoute(req.url.pathname, req.method)) {
if(r.meddlware) {
const tmp = r.meddlware(req, req);
const tmp = r.meddlware(req, res);
if(tmp.redirect)
return res.redirect(tmp.redirect);
if(!tmp.success)