fixing random not working for user fav view

This commit is contained in:
x
2026-01-23 20:28:03 +01:00
parent f5e386593d
commit e9c377dc87
2 changed files with 18 additions and 4 deletions

View File

@@ -358,7 +358,12 @@ window.requestAnimFrame = (function () {
if (wTagMatch) params.append('tag', decodeURIComponent(wTagMatch[1])); if (wTagMatch) params.append('tag', decodeURIComponent(wTagMatch[1]));
const wUserMatch = window.location.href.match(/\/user\/([^/]+)/); 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) { if ([...params].length > 0) {
randomUrl += '?' + params.toString(); randomUrl += '?' + params.toString();

View File

@@ -11,19 +11,28 @@ export default router => {
}); });
group.get(/\/random(\/user\/.+|\/image|\/video|\/audio)?$/, async (req, res) => { group.get(/\/random(\/user\/.+|\/image|\/video|\/audio)?$/, async (req, res) => {
const user = req.url.split[3] === "user" ? req.url.split[4] : "%"; const pathUser = req.url.split[3] === "user" ? req.url.split[4] : null;
const mime = (allowedMimes.filter(n => req.url.split[3]?.startsWith(n))[0] ? req.url.split[3] : "") + "%"; 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 tag = req.url.qs.tag || null;
const isFav = req.url.qs.fav === 'true';
const rows = await db` const rows = await db`
select "items".* select "items".*
from "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_assign on tags_assign.item_id = items.id
left join tags on tags.id = tags_assign.tag_id left join tags on tags.id = tags_assign.tag_id
where where
mime ilike ${mime} and mime ilike ${mime} and
username ilike ${user} and
active = 'true' active = 'true'
${isFav ? db`and fu."user" ilike ${user}` : db`and items.username ilike ${user}`}
${tag ? db`and tags.normalized ilike ${'%' + tag + '%'}` : db``} ${tag ? db`and tags.normalized ilike ${'%' + tag + '%'}` : db``}
order by random() order by random()
limit 1 limit 1