@localazy/strapi-plugin 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
## Quick Installation
|
|
2
2
|
|
|
3
3
|
```
|
|
4
|
-
npx @localazy/strapi-plugin
|
|
4
|
+
npm install @localazy/strapi-plugin@latest && npx @localazy/strapi-plugin
|
|
5
5
|
```
|
|
6
6
|
|
|
7
7
|
## The Official Strapi Localization Plugin by Localazy
|
|
@@ -22,11 +22,28 @@ The plugin is available on [NPM](https://www.npmjs.com/package/@localazy/strapi-
|
|
|
22
22
|
You can also follow the installation commands located in your Strapi project Marketplace or [Strapi Marketplace > Localazy](https://market.strapi.io/plugins/@localazy-strapi-plugin) itself. This is the recommended approach.
|
|
23
23
|
|
|
24
24
|
```
|
|
25
|
-
npx @localazy/strapi-plugin
|
|
25
|
+
npm install @localazy/strapi-plugin@latest && npx @localazy/strapi-plugin
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
Note: Localazy plugin requires an updated Webpack configuration of your Strapi project. Follow the instructions in the console output during the installation process. Steps are also available in the [Install plugin via NPM](https://localazy.com/docs/strapi/strapi-plugin-introduction-installation#install-plugin-via-npm) section of the Localazy Docs.
|
|
29
29
|
|
|
30
|
+
## Configuration
|
|
31
|
+
|
|
32
|
+
Additional configuration object may be provided in the `plugins.js` file. The following options are available:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
localazy: {
|
|
36
|
+
config: {
|
|
37
|
+
/**
|
|
38
|
+
* both options may help guard against DoS attacks
|
|
39
|
+
* if `populateMaxDepth` < 5; the Localazy Strapi Plugin may not work as expected
|
|
40
|
+
*/
|
|
41
|
+
populateDefaultDepth?: number, // default is 5
|
|
42
|
+
populateMaxDepth?: number, // default is 10
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
```
|
|
46
|
+
|
|
30
47
|
## Additional Resources
|
|
31
48
|
|
|
32
49
|
- Localazy Docs: [Introduction to Strapi](https://localazy.com/docs/strapi/strapi-plugin-introduction-installation)
|
|
@@ -20,6 +20,6 @@ export default {
|
|
|
20
20
|
ui_languages: "Select languages to download",
|
|
21
21
|
ui_languages_info: "Select translations of which languages wil be downloaded from Localazy",
|
|
22
22
|
ui_languages_placeholder: "Download all languages",
|
|
23
|
-
download_in_progress: "Download in progress
|
|
24
|
-
to_see_to_progress: "
|
|
23
|
+
download_in_progress: "Download in progress: Please do not close or refresh this page if you wish to see the progress information.",
|
|
24
|
+
to_see_to_progress: "The operation will continue running in the background even if you close the page, but you will lose access to the status report.",
|
|
25
25
|
};
|
|
@@ -15,6 +15,6 @@ export default {
|
|
|
15
15
|
upload_success: "Content successfully imported to the Localazy project.",
|
|
16
16
|
upload_failed:
|
|
17
17
|
"Upload partially failed, please check the report for details...",
|
|
18
|
-
upload_in_progress: "Upload in progress
|
|
19
|
-
to_see_to_progress: "
|
|
18
|
+
upload_in_progress: "Upload in progress: Please do not close or refresh this page if you wish to see the progress information.",
|
|
19
|
+
to_see_to_progress: "The operation will continue running in the background even if you close the page, but you will lose access to the status report.",
|
|
20
20
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
const getFullPopulateObject = require('../utils/get-full-populate-object');
|
|
1
|
+
const { getFullPopulateObject, DEFAULT_POPULATE_DEPTH } = require('../utils/get-full-populate-object');
|
|
2
2
|
|
|
3
3
|
module.exports = (event) => {
|
|
4
4
|
const populate = event.params?.populate;
|
|
5
5
|
|
|
6
6
|
if (populate && populate[0] === 'deep') {
|
|
7
|
-
const
|
|
7
|
+
const populateDefaultDepth = strapi.plugin("localazy")?.config('populateDefaultDepth') ?? DEFAULT_POPULATE_DEPTH;
|
|
8
|
+
const depth = populate[1] ?? populateDefaultDepth;
|
|
8
9
|
const modelObject = getFullPopulateObject(event.model.uid, depth);
|
|
9
|
-
event.params.populate = modelObject.populate
|
|
10
|
+
event.params.populate = modelObject.populate;
|
|
10
11
|
}
|
|
11
12
|
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
const isEmpty = require("lodash/isEmpty");
|
|
7
7
|
const merge = require("lodash/merge");
|
|
8
|
+
const DEFAULT_MAX_POPULATE_DEPTH = 10;
|
|
9
|
+
const DEFAULT_POPULATE_DEPTH = 5;
|
|
8
10
|
|
|
9
11
|
const getModelPopulationAttributes = (model) => {
|
|
10
12
|
if (model.uid === "plugin::upload.file") {
|
|
@@ -15,13 +17,18 @@ const getModelPopulationAttributes = (model) => {
|
|
|
15
17
|
return model.attributes;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
|
-
const getFullPopulateObject = (modelUid,
|
|
19
|
-
|
|
20
|
+
const getFullPopulateObject = (modelUid, depth = DEFAULT_POPULATE_DEPTH) => {
|
|
21
|
+
let localDepth = depth;
|
|
22
|
+
if (localDepth <= 1) {
|
|
20
23
|
return true;
|
|
21
24
|
}
|
|
22
25
|
if (modelUid === "admin::user") {
|
|
23
26
|
return undefined;
|
|
24
27
|
}
|
|
28
|
+
const populateMaxDepth = strapi.plugin("localazy")?.config("populateMaxDepth") ?? DEFAULT_MAX_POPULATE_DEPTH;
|
|
29
|
+
if (Number.isInteger(populateMaxDepth) && localDepth > populateMaxDepth) {
|
|
30
|
+
localDepth = populateMaxDepth;
|
|
31
|
+
}
|
|
25
32
|
|
|
26
33
|
const populate = {};
|
|
27
34
|
const model = strapi.getModel(modelUid);
|
|
@@ -30,17 +37,17 @@ const getFullPopulateObject = (modelUid, maxDepth = 20) => {
|
|
|
30
37
|
)) {
|
|
31
38
|
if (value) {
|
|
32
39
|
if (value.type === "component") {
|
|
33
|
-
populate[key] = getFullPopulateObject(value.component,
|
|
40
|
+
populate[key] = getFullPopulateObject(value.component, localDepth - 1);
|
|
34
41
|
} else if (value.type === "dynamiczone") {
|
|
35
42
|
const dynamicPopulate = value.components.reduce((prev, cur) => {
|
|
36
|
-
const curPopulate = getFullPopulateObject(cur,
|
|
43
|
+
const curPopulate = getFullPopulateObject(cur, localDepth - 1);
|
|
37
44
|
return curPopulate === true ? prev : merge(prev, curPopulate);
|
|
38
45
|
}, {});
|
|
39
46
|
populate[key] = isEmpty(dynamicPopulate) ? true : dynamicPopulate;
|
|
40
47
|
} else if (value.type === "relation") {
|
|
41
48
|
const relationPopulate = getFullPopulateObject(
|
|
42
49
|
value.target,
|
|
43
|
-
|
|
50
|
+
localDepth - 1
|
|
44
51
|
);
|
|
45
52
|
if (relationPopulate) {
|
|
46
53
|
populate[key] = relationPopulate;
|
|
@@ -53,4 +60,7 @@ const getFullPopulateObject = (modelUid, maxDepth = 20) => {
|
|
|
53
60
|
return isEmpty(populate) ? true : { populate };
|
|
54
61
|
};
|
|
55
62
|
|
|
56
|
-
module.exports =
|
|
63
|
+
module.exports = {
|
|
64
|
+
getFullPopulateObject,
|
|
65
|
+
DEFAULT_POPULATE_DEPTH
|
|
66
|
+
};
|