From 37460ba224bd10f0823ef5271183939f752aa763 Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Fri, 29 May 2026 19:05:44 +0200 Subject: [PATCH] regression for filter setting possible fix --- public/s/js/f0ckm.js | 16 +++++++++++++++- src/inc/routes/apiv2/index.mjs | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/public/s/js/f0ckm.js b/public/s/js/f0ckm.js index 0538dee..b9be14f 100644 --- a/public/s/js/f0ckm.js +++ b/public/s/js/f0ckm.js @@ -3429,13 +3429,27 @@ window.cancelAnimFrame = (function () { randomUrl += '?' + params.toString(); } + // Capture favs user context before fetch so it's accessible in .then() + // Without this, random in /user/foo/favs would navigate to /:id (losing context), + // causing mode mismatches between the AJAX pick and any subsequent full-page reload. + let wFavsUser = null; + if (!wUserHall) { + const wUserM = window.location.href.match(/\/user\/([^/]+)/); + if (wUserM && window.location.href.match(/\/favs(\/|$|\?)/)) { + wFavsUser = decodeURIComponent(wUserM[1]); + } + } + fetch(randomUrl) .then(r => r.json()) .then(data => { if (data.success && data.items && data.items.id) { - // Navigate in the same context (user hall, tag, etc.) + // Navigate in the same context (user hall, favs, tag, etc.) if (wUserHall && wUserHallOwner) { loadItemAjax(`/user/${encodeURIComponent(wUserHallOwner)}/hall/${encodeURIComponent(wUserHall)}/${data.items.id}`, true); + } else if (wFavsUser) { + // Preserve /user/:name/favs/:id context so next/prev arrows stay within favs + loadItemAjax(`/user/${encodeURIComponent(wFavsUser)}/favs/${data.items.id}`, true); } else { loadItemAjax(`/${data.items.id}`, true); } diff --git a/src/inc/routes/apiv2/index.mjs b/src/inc/routes/apiv2/index.mjs index 1a9e4ac..42036cd 100644 --- a/src/inc/routes/apiv2/index.mjs +++ b/src/inc/routes/apiv2/index.mjs @@ -496,7 +496,7 @@ export default router => { const userHallOwner = req.url.qs.userHallOwner || null; const isFav = req.url.qs.fav === 'true'; const isStrict = req.url.qs.strict === '1'; - const mode = req.session?.mode ?? 0; + const mode = req.mode ?? 0; // Use req.mode (set by middleware) for consistency with all other routes const ratingsRaw = req.cookies.ratings; const ratingsArr = ratingsRaw ? decodeURIComponent(ratingsRaw).split(/[|,]/).filter(r => ['sfw','nsfw','nsfl','untagged'].includes(r)) : null;