chore: remove deprecated getObject routes [breaking]

`/api/post/pid/:pid`, `/api/topic/tid/:tid`, `/api/category/cid/:cid` have now been removed in favour of routes in the Write API (`/api/v3/(posts|topics|categories)/:id`)
v1.18.x
Julian Lam 4 years ago
parent 7b090c588b
commit 2ad0d0d0d8

@ -2,7 +2,6 @@
const validator = require('validator'); const validator = require('validator');
const nconf = require('nconf'); const nconf = require('nconf');
const winston = require('winston');
const meta = require('../meta'); const meta = require('../meta');
const user = require('../user'); const user = require('../user');
@ -10,7 +9,6 @@ const categories = require('../categories');
const plugins = require('../plugins'); const plugins = require('../plugins');
const translator = require('../translator'); const translator = require('../translator');
const languages = require('../languages'); const languages = require('../languages');
const api = require('../api');
const apiController = module.exports; const apiController = module.exports;
@ -116,36 +114,6 @@ apiController.getConfig = async function (req, res) {
res.json(config); res.json(config);
}; };
// TODO: Deprecate these four controllers in 1.17.0
apiController.getPostData = async (pid, uid) => api.posts.get({ uid }, { pid });
apiController.getTopicData = async (tid, uid) => api.topics.get({ uid }, { tid });
apiController.getCategoryData = async (cid, uid) => api.categories.get({ uid }, { cid });
apiController.getObject = async function (req, res, next) {
const methods = {
post: apiController.getPostData,
topic: apiController.getTopicData,
category: apiController.getCategoryData,
};
const method = methods[req.params.type];
if (!method) {
return next();
}
winston.warn('[api] This route has been deprecated and will likely be removed in v1.17.0');
winston.warn('[api] Use GET /api/v3/(posts|topics|categories)/:id instead');
try {
const result = await method(req.params.id, req.uid);
if (!result) {
return next();
}
res.json(result);
} catch (err) {
next(err);
}
};
apiController.getModerators = async function (req, res) { apiController.getModerators = async function (req, res) {
const moderators = await categories.getModerators(req.params.cid); const moderators = await categories.getModerators(req.params.cid);
res.json({ moderators: moderators }); res.json({ moderators: moderators });

@ -19,11 +19,6 @@ module.exports = function (app, middleware, controllers) {
router.get('/user/uid/:userslug/export/uploads', middleware.checkAccountPermissions, middleware.exposeUid, controllers.user.exportUploads); router.get('/user/uid/:userslug/export/uploads', middleware.checkAccountPermissions, middleware.exposeUid, controllers.user.exportUploads);
router.get('/user/uid/:userslug/export/profile', middleware.checkAccountPermissions, middleware.exposeUid, controllers.user.exportProfile); router.get('/user/uid/:userslug/export/profile', middleware.checkAccountPermissions, middleware.exposeUid, controllers.user.exportProfile);
// TODO: Deprecate in v1.17.0
router.get('/:type/pid/:id', middleware.authenticateOrGuest, controllers.api.getObject);
router.get('/:type/tid/:id', middleware.authenticateOrGuest, controllers.api.getObject);
router.get('/:type/cid/:id', middleware.authenticateOrGuest, controllers.api.getObject);
router.get('/categories/:cid/moderators', controllers.api.getModerators); router.get('/categories/:cid/moderators', controllers.api.getModerators);
router.get('/recent/posts/:term?', controllers.posts.getRecentPosts); router.get('/recent/posts/:term?', controllers.posts.getRecentPosts);
router.get('/unread/total', middleware.authenticate, controllers.unread.unreadTotal); router.get('/unread/total', middleware.authenticate, controllers.unread.unreadTotal);

Loading…
Cancel
Save