mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: normalization middleware to ensure incoming objects' data types are as expected (simplifies later logic)
This commit is contained in:
@@ -137,6 +137,21 @@ middleware.resolveObjects = async function (req, res, next) {
|
||||
next();
|
||||
};
|
||||
|
||||
middleware.normalize = async function (req, res, next) {
|
||||
// Normalizes the received data structure
|
||||
const { body } = req;
|
||||
const { object } = body;
|
||||
|
||||
// Ensure `to` and `cc` are arrays in the object
|
||||
['to', 'cc'].forEach((prop) => {
|
||||
if (object[prop] && typeof object[prop] === 'string') {
|
||||
object[prop] = [object[prop]];
|
||||
}
|
||||
});
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
middleware.configureResponse = async function (req, res, next) {
|
||||
res.header('Content-Type', 'application/activity+json');
|
||||
next();
|
||||
|
||||
@@ -21,6 +21,7 @@ module.exports = function (app, middleware, controllers) {
|
||||
const inboxMiddlewares = [
|
||||
middleware.activitypub.assertPayload,
|
||||
middleware.activitypub.resolveObjects,
|
||||
middleware.activitypub.normalize,
|
||||
];
|
||||
|
||||
app.get('/actor', middlewares, controllers.activitypub.actors.application);
|
||||
|
||||
Reference in New Issue
Block a user