new backend

This commit is contained in:
Flummi
2021-12-04 12:19:47 +01:00
parent d885dd8e4e
commit 43665884f6
42 changed files with 946 additions and 1226 deletions

View File

@@ -1,12 +1,15 @@
import router from "../router.mjs";
import sql from "../sql.mjs";
import lib from "../lib.mjs";
const allowedMimes = [ "audio", "image", "video", "%" ];
router.get(/^\/random(\/image|\/video|\/audio)?$/, async (req, res) => {
const mime = (allowedMimes.filter(n => req.url.split[1]?.startsWith(n))[0] ? req.url.split[1] : "") + "%";
const tmp = req.cookies.session ? "" : "id in (select item_id from tags_assign where tag_id = 1 group by item_id)";
const rows = await sql("items").select("id").whereRaw(tmp).andWhere("mime", "like", mime).orderByRaw("rand()").limit(1);
res.redirect(`/${req.url.split[1] ? req.url.split[1] + "/" : ""}${rows[0].id}`);
});
export default (router, tpl) => {
router.get(/^\/random(\/image|\/video|\/audio)?$/, async (req, res) => {
const tmp = lib.getMode(req.session.mode ?? 0);
const mime = (allowedMimes.filter(n => req.url.split[1]?.startsWith(n))[0] ? req.url.split[1] : "") + "%";
const rows = await sql("items").select("id").whereRaw(tmp).andWhere("mime", "like", mime).orderByRaw("rand()").limit(1);
res.redirect(`/${req.url.split[1] ? req.url.split[1] + "/" : ""}${rows[0].id}`);
});
return router;
};