From e9c377dc87a5bf9a1a756a4150cb89b5473ee248 Mon Sep 17 00:00:00 2001 From: x Date: Fri, 23 Jan 2026 20:28:03 +0100 Subject: [PATCH] fixing random not working for user fav view --- public/s/js/f0ck.js | 7 ++++++- src/inc/routes/apiv2/index.mjs | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/public/s/js/f0ck.js b/public/s/js/f0ck.js index 76ae416..87dd28e 100644 --- a/public/s/js/f0ck.js +++ b/public/s/js/f0ck.js @@ -358,7 +358,12 @@ window.requestAnimFrame = (function () { if (wTagMatch) params.append('tag', decodeURIComponent(wTagMatch[1])); const wUserMatch = window.location.href.match(/\/user\/([^/]+)/); - if (wUserMatch) params.append('user', decodeURIComponent(wUserMatch[1])); + if (wUserMatch) { + params.append('user', decodeURIComponent(wUserMatch[1])); + if (window.location.href.includes('/favs/')) { + params.append('fav', 'true'); + } + } if ([...params].length > 0) { randomUrl += '?' + params.toString(); diff --git a/src/inc/routes/apiv2/index.mjs b/src/inc/routes/apiv2/index.mjs index 539357b..ff10be6 100644 --- a/src/inc/routes/apiv2/index.mjs +++ b/src/inc/routes/apiv2/index.mjs @@ -11,19 +11,28 @@ export default router => { }); group.get(/\/random(\/user\/.+|\/image|\/video|\/audio)?$/, async (req, res) => { - const user = req.url.split[3] === "user" ? req.url.split[4] : "%"; - const mime = (allowedMimes.filter(n => req.url.split[3]?.startsWith(n))[0] ? req.url.split[3] : "") + "%"; + const pathUser = req.url.split[3] === "user" ? req.url.split[4] : null; + const user = req.url.qs.user || pathUser || "%"; + + const pathMime = allowedMimes.filter(n => req.url.split[3]?.startsWith(n))[0] ? req.url.split[3] : ""; + const mime = (req.url.qs.mime || pathMime) + "%"; + const tag = req.url.qs.tag || null; + const isFav = req.url.qs.fav === 'true'; const rows = await db` select "items".* from "items" + ${isFav + ? db`join "favorites" on "favorites".item_id = "items".id join "user" as fu on fu.id = "favorites".user_id` + : db`` + } left join tags_assign on tags_assign.item_id = items.id left join tags on tags.id = tags_assign.tag_id where mime ilike ${mime} and - username ilike ${user} and active = 'true' + ${isFav ? db`and fu."user" ilike ${user}` : db`and items.username ilike ${user}`} ${tag ? db`and tags.normalized ilike ${'%' + tag + '%'}` : db``} order by random() limit 1