@cloudimage-strapi/content-plugin 1.0.1 → 1.0.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
@@ -6,28 +6,6 @@
6
6
 
7
7
  ## Config
8
8
 
9
-
10
- `config/middlewares.js`
11
-
12
- Replace `'strapi::security',` with:
13
-
14
- ```
15
- {
16
- name: 'strapi::security',
17
- config: {
18
- contentSecurityPolicy: {
19
- useDefaults: true,
20
- directives: {
21
- 'connect-src': ["'self'", 'https:'],
22
- 'img-src': ["'self'", 'data:', 'blob:', 'scaleflex.cloudimg.io', 'assets.scaleflex.com', '*.cloudimg.io'],
23
- 'media-src': ["'self'", 'data:', 'blob:', 'scaleflex.cloudimg.io', 'assets.scaleflex.com', '*.cloudimg.io'],
24
- upgradeInsecureRequests: null,
25
- },
26
- },
27
- },
28
- },
29
- ```
30
-
31
9
  `config/server.js`
32
10
 
33
11
  Append `url: 'domain (including the http/https:// part)'`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudimage-strapi/content-plugin",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Strapi v4 plugin for Filerobot by Scaleflex",
5
5
  "strapi": {
6
6
  "name": "scaleflex-cloudimage",
@@ -1,5 +1,25 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports = ({ strapi }) => {
4
- // bootstrap phase
4
+ strapi.store({
5
+ environment: strapi.config.environment,
6
+ type: 'plugin',
7
+ name: 'cloudimage',
8
+ })
9
+ .get({key: 'options'})
10
+ .then((config) => {
11
+ if (config && config.hasOwnProperty('domain') && config.domain)
12
+ {
13
+ for (let index = 1; index < strapi.config.middlewares.length; index++)
14
+ {
15
+ let item = strapi.config.middlewares[index];
16
+
17
+ if (typeof item === 'object' && item.name === 'strapi::security' && !item.config.contentSecurityPolicy.directives['img-src'].includes(config.domain))
18
+ {
19
+ strapi.config.middlewares[index].config.contentSecurityPolicy.directives['img-src'].push(config.domain);
20
+ strapi.config.middlewares[index].config.contentSecurityPolicy.directives['media-src'].push(config.domain);
21
+ }
22
+ }
23
+ }
24
+ });
5
25
  };
@@ -1,65 +1,65 @@
1
1
  'use strict';
2
- //@Todo: Think about how this can be done in a cluster of may servers. Maybe persist the plugin's middleware settings in DB, then load it into that memory object upon start
2
+
3
3
  module.exports = ({ strapi }) => {
4
- // const pluginMiddleware = {
5
- // name: 'strapi::security',
6
- // config: {
7
- // contentSecurityPolicy: {
8
- // useDefaults: true,
9
- // directives: {
10
- // 'connect-src': ["'self'", 'https:'],
11
- // 'img-src': ["'self'", 'data:', 'blob:', 'scaleflex.cloudimg.io', 'assets.scaleflex.com', '*.cloudimg.io'],
12
- // 'media-src': ["'self'", 'data:', 'blob:', 'scaleflex.cloudimg.io', 'assets.scaleflex.com', '*.cloudimg.io'],
13
- // upgradeInsecureRequests: null,
14
- // },
15
- // },
16
- // },
17
- // };
4
+ const pluginMiddleware = {
5
+ name: 'strapi::security',
6
+ config: {
7
+ contentSecurityPolicy: {
8
+ useDefaults: true,
9
+ directives: {
10
+ 'connect-src': ["'self'", 'https:'],
11
+ 'img-src': ["'self'", 'data:', 'blob:', 'scaleflex.cloudimg.io', 'assets.scaleflex.com', '*.cloudimg.io'],
12
+ 'media-src': ["'self'", 'data:', 'blob:', 'scaleflex.cloudimg.io', 'assets.scaleflex.com', '*.cloudimg.io'],
13
+ upgradeInsecureRequests: null,
14
+ },
15
+ },
16
+ },
17
+ };
18
18
 
19
- // // Merge a `source` object to a `target` recursively
20
- // const merge = (target, source) => {
21
- // // Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
22
- // for (const key of Object.keys(source))
23
- // {
24
- // if (Array.isArray(source[key]))
25
- // {
26
- // Object.assign(source[key], [...new Set(target[key].concat(source[key]))]);
27
- // }
19
+ // Merge a `source` object to a `target` recursively
20
+ const merge = (target, source) => {
21
+ // Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
22
+ for (const key of Object.keys(source))
23
+ {
24
+ if (Array.isArray(source[key]))
25
+ {
26
+ Object.assign(source[key], [...new Set(target[key].concat(source[key]))]);
27
+ }
28
28
 
29
- // if (source[key] instanceof Object && !Array.isArray(source[key]))
30
- // {
31
- // Object.assign(source[key], merge(target[key], source[key]));
32
- // }
33
- // }
29
+ if (source[key] instanceof Object && !Array.isArray(source[key]))
30
+ {
31
+ Object.assign(source[key], merge(target[key], source[key]));
32
+ }
33
+ }
34
34
 
35
- // // Join `target` and modified `source`
36
- // Object.assign(target || {}, source);
35
+ // Join `target` and modified `source`
36
+ Object.assign(target || {}, source);
37
37
 
38
- // return target;
39
- // };
38
+ return target;
39
+ };
40
40
 
41
- // for (let index = 1; index < strapi.config.middlewares.length; index++)
42
- // {
43
- // let item = strapi.config.middlewares[index];
41
+ for (let index = 1; index < strapi.config.middlewares.length; index++)
42
+ {
43
+ let item = strapi.config.middlewares[index];
44
44
 
45
- // if (typeof item === 'object' && item.name === 'strapi::security')
46
- // {
47
- // let mergedSettings = merge(item.config, pluginMiddleware.config);
48
- // strapi.config.middlewares.splice(index, 1, {name: 'strapi::security', config: mergedSettings});
45
+ if (typeof item === 'object' && item.name === 'strapi::security')
46
+ {
47
+ let mergedSettings = merge(item.config, pluginMiddleware.config);
48
+ strapi.config.middlewares.splice(index, 1, {name: 'strapi::security', config: mergedSettings});
49
49
 
50
- // break;
51
- // }
52
- // else if (typeof item === 'string' && item === 'strapi::security')
53
- // {
54
- // strapi.config.middlewares.splice(index, 1, pluginMiddleware);
50
+ break;
51
+ }
52
+ else if (typeof item === 'string' && item === 'strapi::security')
53
+ {
54
+ strapi.config.middlewares.splice(index, 1, pluginMiddleware);
55
55
 
56
- // break;
57
- // }
58
- // else
59
- // {
60
- // strapi.config.middlewares.push(pluginMiddleware);
56
+ break;
57
+ }
58
+ else
59
+ {
60
+ strapi.config.middlewares.push(pluginMiddleware);
61
61
 
62
- // break;
63
- // }
64
- // }
62
+ break;
63
+ }
64
+ }
65
65
  };
@@ -40,21 +40,6 @@ module.exports = ({ strapi }) => ({
40
40
 
41
41
  const config = await pluginStore.get({key: 'options'});
42
42
 
43
- // if (config.domain)
44
- // {
45
- // for (let index = 1; index < strapi.config.middlewares.length; index++)
46
- // {
47
- // let item = strapi.config.middlewares[index];
48
-
49
- // if (typeof item === 'object' && item.name === 'strapi::security'
50
- // && !item.config.contentSecurityPolicy.directives['img-src'].includes(config.domain))
51
- // {
52
- // strapi.config.middlewares[index].config.contentSecurityPolicy.directives['img-src'].push(config.domain);
53
- // strapi.config.middlewares[index].config.contentSecurityPolicy.directives['media-src'].push(config.domain);
54
- // }
55
- // }
56
- // }
57
-
58
43
  return config;
59
44
  },
60
45
  async checkV7(ctx) {