diff --git a/package.json b/package.json index 23af98a..da91d80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "strapi-plugin-populate-deep", - "version": "0.1.2", + "name": "strapi-plugin-populate-deep-with-params", + "version": "0.1.4", "description": "This is the description of the plugin.", "strapi": { "name": "strapi-plugin-populate-deep", @@ -18,7 +18,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/Barelydead/strapi-plugin-deep-populate" + "url": "https://github.com/jacopobonomi/strapi-plugin-deep-populate" }, "engines": { "node": ">=12.x. <=16.x.x", diff --git a/server/bootstrap.js b/server/bootstrap.js index 53d38dc..d358efd 100644 --- a/server/bootstrap.js +++ b/server/bootstrap.js @@ -8,7 +8,7 @@ module.exports = ({ strapi }) => { const populate = event.params?.populate; if (populate && populate[0] === 'deep') { - const depth = populate[1] ?? 5 + const depth = populate[1] ?? process.env.DEFAULT_POPULATE_DEPTH ?? 5; const modelObject = getFullPopulateObject(event.model.uid, depth); event.params.populate = modelObject.populate } diff --git a/server/helpers/index.js b/server/helpers/index.js index ed15108..134a186 100644 --- a/server/helpers/index.js +++ b/server/helpers/index.js @@ -9,7 +9,15 @@ const getModelPopulationAttributes = (model) => { return model.attributes; }; -const getFullPopulateObject = (modelUid, maxDepth = 20) => { +const getFullPopulateObject = ( + modelUid, + maxDepth = process.env.MAX_POPULATE_DEPTH ?? 20 +) => { + + if (maxDepth > process.env.MAX_POPULATE_DEPTH) { + maxDepth = process.env.MAX_POPULATE_DEPTH; + } + if (maxDepth <= 1) { return true; } @@ -48,5 +56,5 @@ const getFullPopulateObject = (modelUid, maxDepth = 20) => { }; module.exports = { - getFullPopulateObject -} \ No newline at end of file + getFullPopulateObject, +};