fix untagged behaviour in pagination

This commit is contained in:
2026-08-12 17:10:53 +02:00
parent 97604bda70
commit c92306867f
4 changed files with 70 additions and 60 deletions
+24 -2
View File
@@ -785,8 +785,17 @@ export default router => {
});
}
const effMode = req.query.mode !== undefined ? +req.query.mode : (req.mode ?? 3);
const ratingsRaw = req.cookies?.ratings || req.query.ratings;
const ratingsArr = (effMode === 3 || effMode === 2) ? null : (ratingsRaw ? (Array.isArray(ratingsRaw) ? ratingsRaw : decodeURIComponent(ratingsRaw).split(/[|,]/)).filter(r => ['sfw','nsfw','nsfl','untagged'].includes(r)) : null);
let guestTagFilter = db``;
if (!session) {
const itemTags = await db`SELECT tag_id FROM tags_assign WHERE item_id = ${+id}`;
const isTagged = itemTags.length > 0;
if (!isTagged && !cfg.websrv.public_untagged) {
return res.json({ success: false, msg: 'no items found' });
}
if (cfg.websrv.public_nsfw) {
guestTagFilter = cfg.websrv.public_untagged
? db`and (id in (select item_id from tags_assign where tag_id in (1, 2)) or not exists (select 1 from tags_assign where item_id = items.id))`
@@ -798,17 +807,30 @@ export default router => {
}
}
let modeCondition = db``;
if (effMode === 2) {
modeCondition = db`and not exists (select 1 from tags_assign where item_id = items.id)`;
} else if (effMode === 0) {
modeCondition = db`and id in (select item_id from tags_assign where tag_id = 1)`;
} else if (effMode === 1) {
modeCondition = db`and id in (select item_id from tags_assign where tag_id = 2)`;
} else if (effMode === 4) {
modeCondition = db`and id in (select item_id from tags_assign where tag_id = ${parseInt(cfg.nsfl_tag_id, 10) || 3})`;
} else if (ratingsArr && ratingsArr.length > 0) {
modeCondition = db`and ${db.unsafe(lib.getMultiRatingMode(ratingsArr))}`;
}
const next = await db`
select id
from "items"
where id > ${+id} and active = true and coalesce(visibility, 0) = 0 ${guestTagFilter}
where id > ${+id} and active = true and coalesce(visibility, 0) = 0 ${guestTagFilter} ${modeCondition}
order by id
limit 1
`;
const prev = await db`
select id
from "items"
where id < ${+id} and active = true and coalesce(visibility, 0) = 0 ${guestTagFilter}
where id < ${+id} and active = true and coalesce(visibility, 0) = 0 ${guestTagFilter} ${modeCondition}
order by id desc
limit 1
`;