This commit is contained in:
2026-09-12 06:57:10 +02:00
parent acf29df204
commit 03abac6bef
11 changed files with 178 additions and 30 deletions
+15 -4
View File
@@ -83,7 +83,7 @@ export default router => {
});
group.post(/\/excluded_tags/, lib.loggedin, async (req, res) => {
const tagname = req.post.tagname;
const tagname = req.post?.tagname || req.body?.tagname;
if (!tagname) return res.json({ success: false, msg: 'No tag provided' }, 400);
const tag = (await db`select id, tag, normalized from tags where normalized = slugify(${tagname})`)[0];
@@ -92,10 +92,17 @@ export default router => {
await db`
update user_options
set excluded_tags = array_append(excluded_tags, ${tag.id})
where user_id = ${+req.session.id} and not (${tag.id} = any(excluded_tags))
set excluded_tags = array_append(coalesce(excluded_tags, '{}'), ${tag.id})
where user_id = ${+req.session.id} and not (${tag.id} = any(coalesce(excluded_tags, '{}')))
`;
if (req.session) {
if (!req.session.excluded_tags) req.session.excluded_tags = [];
if (!req.session.excluded_tags.includes(tag.id)) {
req.session.excluded_tags.push(tag.id);
}
}
// Return updated list
const tags = await db`
select t.id, t.tag, t.normalized
@@ -114,10 +121,14 @@ export default router => {
await db`
update user_options
set excluded_tags = array_remove(excluded_tags, ${tag.id})
set excluded_tags = array_remove(coalesce(excluded_tags, '{}'), ${tag.id})
where user_id = ${+req.session.id}
`;
if (req.session && req.session.excluded_tags) {
req.session.excluded_tags = req.session.excluded_tags.filter(id => id !== tag.id);
}
const tags = await db`
select t.id, t.tag, t.normalized
from unnest((select excluded_tags from user_options where user_id = ${+req.session.id})) as et(id)