diff --git a/src/inc/routeinc/f0cklib.mjs b/src/inc/routeinc/f0cklib.mjs index a1239db..ae9eb37 100644 --- a/src/inc/routeinc/f0cklib.mjs +++ b/src/inc/routeinc/f0cklib.mjs @@ -613,7 +613,13 @@ export default { const tmp = { user, tag: isTitleSearch ? _decodedTag : tag, hall, mime, itemid: rawIdOrSlug, strict: strict, userHall: userHallObj || userHallSlug, userHallOwner }; const effMode = Number(mode ?? 0); - const modequery = computeBaseMode(mode, ratings, session); + const nsflId = parseInt(cfg.nsfl_tag_id, 10) || 3; + const itemModeQuery = session + ? computeBaseMode(mode, ratings, session) + : (cfg.websrv.public_nsfw + ? `not exists (select 1 from tags_assign where item_id = items.id and tag_id = ${nsflId})` + : `not exists (select 1 from tags_assign where item_id = items.id and tag_id in (2, ${nsflId}))` + ); let tagFilter = db``; let titleFilter = db``; @@ -659,7 +665,7 @@ export default { : db`and coalesce(items.visibility, 0) = 0`); return db` - ${db.unsafe(modequery)} + ${db.unsafe(itemModeQuery)} and items.active = true ${visibilityFilter} and (items.expires_at IS NULL OR items.expires_at > ${Math.floor(Date.now() / 1000)}) diff --git a/src/inc/routes/apiv2/index.mjs b/src/inc/routes/apiv2/index.mjs index cb25e45..cdbb4c3 100644 --- a/src/inc/routes/apiv2/index.mjs +++ b/src/inc/routes/apiv2/index.mjs @@ -797,19 +797,10 @@ export default router => { let guestTagFilter = db``; if (!session) { const nsflId = parseInt(cfg.nsfl_tag_id, 10) || 3; - const itemRatingTags = await db`SELECT tag_id FROM tags_assign WHERE item_id = ${+id} AND tag_id IN (1, 2, ${nsflId})`; - const hasRatingTag = itemRatingTags.length > 0; - if (!hasRatingTag && !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 and tag_id in (1, 2, ${nsflId})))` - : db`and id in (select item_id from tags_assign where tag_id in (1, 2))`; + guestTagFilter = db`and not exists (select 1 from tags_assign where item_id = items.id and tag_id = ${nsflId})`; } else { - guestTagFilter = cfg.websrv.public_untagged - ? db`and (id in (select item_id from tags_assign where tag_id = 1) or not exists (select 1 from tags_assign where item_id = items.id and tag_id in (1, 2, ${nsflId})))` - : db`and id in (select item_id from tags_assign where tag_id = 1)`; + guestTagFilter = db`and not exists (select 1 from tags_assign where item_id = items.id and tag_id in (2, ${nsflId}))`; } }