fdsafs
This commit is contained in:
@@ -4,6 +4,7 @@ import cfg from '../../config.mjs';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import crypto from 'crypto';
|
||||
import { canAnonDo, isAnonSession } from '../../settings.mjs';
|
||||
|
||||
// Note: Avatar upload/delete is handled by middleware in index.mjs via avatar_handler.mjs
|
||||
// These routes remain for other settings API endpoints
|
||||
@@ -74,6 +75,9 @@ export default router => {
|
||||
});
|
||||
|
||||
group.get(/\/excluded_tags/, lib.loggedin, async (req, res) => {
|
||||
if (isAnonSession(req.session) && !canAnonDo('exclude_tags')) {
|
||||
return res.json({ success: false, msg: 'Tag exclusion is disabled for anonymous users' }, 403);
|
||||
}
|
||||
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)
|
||||
@@ -83,10 +87,16 @@ export default router => {
|
||||
});
|
||||
|
||||
group.post(/\/excluded_tags/, lib.loggedin, async (req, res) => {
|
||||
if (isAnonSession(req.session) && !canAnonDo('exclude_tags')) {
|
||||
return res.json({ success: false, msg: 'Tag exclusion is disabled for anonymous users' }, 403);
|
||||
}
|
||||
const tagname = req.post?.tagname || req.body?.tagname;
|
||||
if (!tagname) return res.json({ success: false, msg: 'No tag provided' }, 400);
|
||||
const tagId = req.post?.tag_id || req.body?.tag_id;
|
||||
if (!tagname && !tagId) 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];
|
||||
const tag = tagId
|
||||
? (await db`select id, tag, normalized from tags where id = ${+tagId}`)[0]
|
||||
: (await db`select id, tag, normalized from tags where normalized = slugify(${tagname}) or tag = ${tagname}`)[0];
|
||||
|
||||
if (!tag) return res.json({ success: false, msg: 'Tag not found' }, 404);
|
||||
|
||||
@@ -110,12 +120,18 @@ export default router => {
|
||||
join tags t on t.id = et.id
|
||||
`;
|
||||
|
||||
return res.json({ success: true, tags }, 200);
|
||||
return res.json({ success: true, tags, tag }, 200);
|
||||
});
|
||||
|
||||
group.delete(/\/excluded_tags\/(?<tag>.+)/, lib.loggedin, async (req, res) => {
|
||||
const tagname = decodeURIComponent(req.params.tag);
|
||||
const tag = (await db`select id from tags where normalized = slugify(${tagname})`)[0];
|
||||
if (isAnonSession(req.session) && !canAnonDo('exclude_tags')) {
|
||||
return res.json({ success: false, msg: 'Tag exclusion is disabled for anonymous users' }, 403);
|
||||
}
|
||||
const tagParam = decodeURIComponent(req.params.tag);
|
||||
const isNum = /^\d+$/.test(tagParam);
|
||||
const tag = isNum
|
||||
? (await db`select id, tag, normalized from tags where id = ${+tagParam}`)[0]
|
||||
: (await db`select id, tag, normalized from tags where normalized = slugify(${tagParam}) or tag = ${tagParam}`)[0];
|
||||
|
||||
if (!tag) return res.json({ success: false, msg: 'Tag not found' }, 404);
|
||||
|
||||
@@ -135,7 +151,7 @@ export default router => {
|
||||
join tags t on t.id = et.id
|
||||
`;
|
||||
|
||||
return res.json({ success: true, tags }, 200);
|
||||
return res.json({ success: true, tags, tag }, 200);
|
||||
});
|
||||
|
||||
// Generic Token Generation (default type=discord if not specified, though frontend should specify)
|
||||
|
||||
Reference in New Issue
Block a user