mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46: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();
|
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) {
|
middleware.configureResponse = async function (req, res, next) {
|
||||||
res.header('Content-Type', 'application/activity+json');
|
res.header('Content-Type', 'application/activity+json');
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ module.exports = function (app, middleware, controllers) {
|
|||||||
const inboxMiddlewares = [
|
const inboxMiddlewares = [
|
||||||
middleware.activitypub.assertPayload,
|
middleware.activitypub.assertPayload,
|
||||||
middleware.activitypub.resolveObjects,
|
middleware.activitypub.resolveObjects,
|
||||||
|
middleware.activitypub.normalize,
|
||||||
];
|
];
|
||||||
|
|
||||||
app.get('/actor', middlewares, controllers.activitypub.actors.application);
|
app.get('/actor', middlewares, controllers.activitypub.actors.application);
|
||||||
|
|||||||
Reference in New Issue
Block a user