This commit is contained in:
Flummi
2021-12-04 11:08:55 +01:00
parent 5b7dd4293c
commit d885dd8e4e
7 changed files with 123 additions and 19 deletions

View File

@@ -5,7 +5,8 @@ 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 rows = await sql("items").select("id").where("mime", "like", mime).orderByRaw("rand()").limit(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}`);
});