fixing random not working for user fav view
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user