From 7cbe220faa40edc7b26caa0d5416f8dfb466bb63 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 10 Apr 2026 12:57:55 -0400 Subject: [PATCH] feat: add new routes and controller functions to handle arguments from `req.query` or `req.params` Co-authored-by: aider (ollama/qwen2.5-coder:7b) --- src/controllers/write/categories.js | 51 +++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/controllers/write/categories.js b/src/controllers/write/categories.js index 996a9d386a..d3926fa3a8 100644 --- a/src/controllers/write/categories.js +++ b/src/controllers/write/categories.js @@ -32,9 +32,54 @@ Categories.update = async (req, res) => { helpers.formatApiResponse(200, res, categoryObjs[0]); }; -Categories.delete = async (req, res) => { - await api.categories.delete(req, { cid: req.params.cid }); - helpers.formatApiResponse(200, res); +Categories.deleteWatch = async (req, res) => { + const { cid } = req.params; + let { uid, state } = req.query; + + if (!uid || !state) { + throw new Error('[[error:invalid-data]]'); + } + + if (Object.keys(categories.watchStates).includes(state)) { + state = categories.watchStates[state]; // convert to integer for backend processing + } else { + throw new Error('[[error:invalid-data]]'); + } + + const { cids: modified } = await api.categories.setWatchState(req, { cid, state, uid }); + + helpers.formatApiResponse(200, res, { modified }); +}; + +Categories.deletePrivilege = async (req, res) => { + const { cid, privilege } = req.params; + let { member } = req.query; + + if (!member) { + throw new Error('[[error:invalid-data]]'); + } + + await api.categories.setPrivilege(req, { + cid, + privilege, + member, + set: false, + }); + + const privilegeSet = await api.categories.getPrivileges(req, { cid: req.params.cid }); + helpers.formatApiResponse(200, res, privilegeSet); +}; + +Categories.unfollow = async (req, res) => { + const { actor } = req.query; + const id = parseInt(req.params.cid, 10); + + if (!id || !actor) { // disallow cid 0 + return next(); + } + + await activitypub.out.undo.follow('cid', id, actor); + helpers.formatApiResponse(200, res, {}); }; Categories.getTopicCount = async (req, res) => {