@strapi/provider-upload-cloudinary 4.0.0-next.8 → 4.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.
Files changed (3) hide show
  1. package/README.md +58 -18
  2. package/lib/index.js +6 -6
  3. package/package.json +21 -26
package/README.md CHANGED
@@ -1,4 +1,25 @@
1
- # strapi-provider-upload-cloudinary
1
+ # @strapi/provider-upload-cloudinary
2
+
3
+ ## Resources
4
+
5
+ - [LICENSE](LICENSE)
6
+
7
+ ## Links
8
+
9
+ - [Strapi website](https://strapi.io/)
10
+ - [Strapi documentation](https://docs.strapi.io)
11
+ - [Strapi community on Discord](https://discord.strapi.io)
12
+ - [Strapi news on Twitter](https://twitter.com/strapijs)
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ # using yarn
18
+ yarn add @strapi/provider-upload-cloudinary
19
+
20
+ # using npm
21
+ npm install @strapi/provider-upload-cloudinary --save
22
+ ```
2
23
 
3
24
  ## Configurations
4
25
 
@@ -6,9 +27,9 @@ Your configuration is passed down to the cloudinary configuration. (e.g: `cloudi
6
27
 
7
28
  `actionOptions` are passed directly to the upload and delete functions respectively allowing for custom options such as folder, type, etc. You can see the complete list of upload options [here](https://cloudinary.com/documentation/image_upload_api_reference#upload_optional_parameters) and delete options [here](https://cloudinary.com/documentation/image_upload_api_reference#destroy_optional_parameters)
8
29
 
9
- See the [using a provider](https://strapi.io/documentation/developer-docs/latest/development/plugins/upload.html#using-a-provider) documentation for information on installing and using a provider. And see the [environment variables](https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/configurations.html#environment-variables) for setting and using environment variables in your configs.
30
+ See the [using a provider](https://docs.strapi.io/developer-docs/latest/plugins/upload.html#using-a-provider) documentation for information on installing and using a provider. And see the [environment variables](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.html#environment-variables) for setting and using environment variables in your configs.
10
31
 
11
- **Example**
32
+ ### Provider Configuration
12
33
 
13
34
  `./config/plugins.js`
14
35
 
@@ -16,27 +37,46 @@ See the [using a provider](https://strapi.io/documentation/developer-docs/latest
16
37
  module.exports = ({ env }) => ({
17
38
  // ...
18
39
  upload: {
19
- provider: 'cloudinary',
20
- providerOptions: {
21
- cloud_name: env('CLOUDINARY_NAME'),
22
- api_key: env('CLOUDINARY_KEY'),
23
- api_secret: env('CLOUDINARY_SECRET'),
24
- },
25
- actionOptions: {
26
- upload: {},
27
- delete: {},
40
+ config: {
41
+ provider: 'cloudinary',
42
+ providerOptions: {
43
+ cloud_name: env('CLOUDINARY_NAME'),
44
+ api_key: env('CLOUDINARY_KEY'),
45
+ api_secret: env('CLOUDINARY_SECRET'),
46
+ },
47
+ actionOptions: {
48
+ upload: {},
49
+ delete: {},
50
+ },
28
51
  },
29
52
  },
30
53
  // ...
31
54
  });
32
55
  ```
33
56
 
34
- ## Resources
57
+ ### Security Middleware Configuration
35
58
 
36
- - [License](LICENSE)
59
+ Due to the default settings in the Strapi Security Middleware you will need to modify the `contentSecurityPolicy` settings to properly see thumbnail previews in the Media Library. You should replace `strapi::security` string with the object bellow instead as explained in the [middleware configuration](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/required/middlewares.html#loading-order) documentation.
37
60
 
38
- ## Links
61
+ `./config/middlewares.js`
39
62
 
40
- - [Strapi website](https://strapi.io/)
41
- - [Strapi community on Slack](https://slack.strapi.io)
42
- - [Strapi news on Twitter](https://twitter.com/strapijs)
63
+ ```js
64
+ module.exports = [
65
+ // ...
66
+ {
67
+ name: 'strapi::security',
68
+ config: {
69
+ contentSecurityPolicy: {
70
+ useDefaults: true,
71
+ directives: {
72
+ 'connect-src': ["'self'", 'https:'],
73
+ 'img-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
74
+ 'media-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
75
+ upgradeInsecureRequests: null,
76
+ },
77
+ },
78
+ },
79
+ },
80
+ // ...
81
+ ];
82
+ ```
package/lib/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  // Public node modules.
8
8
  const cloudinary = require('cloudinary').v2;
9
9
  const intoStream = require('into-stream');
10
- const { errors } = require('@strapi/plugin-upload');
10
+ const { PayloadTooLargeError } = require('@strapi/utils').errors;
11
11
 
12
12
  module.exports = {
13
13
  init(config) {
@@ -15,7 +15,7 @@ module.exports = {
15
15
 
16
16
  return {
17
17
  upload(file, customConfig = {}) {
18
- return new Promise((resolve, reject) => {
18
+ return new Promise(resolve => {
19
19
  const config = {
20
20
  resource_type: 'auto',
21
21
  public_id: file.hash,
@@ -30,9 +30,9 @@ module.exports = {
30
30
  (err, image) => {
31
31
  if (err) {
32
32
  if (err.message.includes('File size too large')) {
33
- return reject(errors.entityTooLarge());
33
+ throw new PayloadTooLargeError();
34
34
  }
35
- return reject(errors.unknownError(`Error uploading to cloudinary: ${err.message}`));
35
+ throw new Error(`Error uploading to cloudinary: ${err.message}`);
36
36
  }
37
37
 
38
38
  if (image.resource_type === 'video') {
@@ -67,10 +67,10 @@ module.exports = {
67
67
  });
68
68
 
69
69
  if (response.result !== 'ok' && response.result !== 'not found') {
70
- throw errors.unknownError(`Error deleting on cloudinary: ${response.result}`);
70
+ throw new Error(`Error deleting on cloudinary: ${response.result}`);
71
71
  }
72
72
  } catch (error) {
73
- throw errors.unknownError(`Error deleting on cloudinary: ${error.message}`);
73
+ throw new Error(`Error deleting on cloudinary: ${error.message}`);
74
74
  }
75
75
  },
76
76
  };
package/package.json CHANGED
@@ -1,53 +1,48 @@
1
1
  {
2
2
  "name": "@strapi/provider-upload-cloudinary",
3
- "version": "4.0.0-next.8",
3
+ "version": "4.0.2",
4
4
  "description": "Cloudinary provider for strapi upload",
5
- "homepage": "https://strapi.io",
6
5
  "keywords": [
7
6
  "upload",
8
7
  "cloudinary",
9
8
  "strapi"
10
9
  ],
11
- "directories": {
12
- "lib": "./lib"
13
- },
14
- "main": "./lib",
15
- "dependencies": {
16
- "cloudinary": "^1.25.1",
17
- "into-stream": "^5.1.0"
18
- },
19
- "peerDependencies": {
20
- "@strapi/plugin-upload": "^4.0.0"
10
+ "homepage": "https://strapi.io",
11
+ "bugs": {
12
+ "url": "https://github.com/strapi/strapi/issues"
21
13
  },
22
- "strapi": {
23
- "isProvider": true
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git://github.com/strapi/strapi.git"
24
17
  },
18
+ "license": "SEE LICENSE IN LICENSE",
25
19
  "author": {
26
- "email": "perret.luca@gmail.com",
27
20
  "name": "Luca Perret",
21
+ "email": "perret.luca@gmail.com",
28
22
  "url": "https://github.com/lucaperret"
29
23
  },
30
24
  "maintainers": [
31
25
  {
32
- "name": "Strapi team",
26
+ "name": "Strapi Solutions SAS",
33
27
  "email": "hi@strapi.io",
34
28
  "url": "https://strapi.io"
35
29
  }
36
30
  ],
37
- "repository": {
38
- "type": "git",
39
- "url": "git://github.com/strapi/strapi.git"
31
+ "main": "./lib",
32
+ "directories": {
33
+ "lib": "./lib"
40
34
  },
41
- "bugs": {
42
- "url": "https://github.com/strapi/strapi/issues"
35
+ "scripts": {
36
+ "test": "echo \"no tests yet\""
37
+ },
38
+ "dependencies": {
39
+ "@strapi/utils": "4.0.2",
40
+ "cloudinary": "^1.25.1",
41
+ "into-stream": "^5.1.0"
43
42
  },
44
43
  "engines": {
45
44
  "node": ">=12.x.x <=16.x.x",
46
45
  "npm": ">=6.0.0"
47
46
  },
48
- "license": "SEE LICENSE IN LICENSE",
49
- "scripts": {
50
- "test": "echo \"no tests yet\""
51
- },
52
- "gitHead": "e3452f6662a45a4ba96e96861e076e313b297666"
47
+ "gitHead": "fd656a47698e0a33aae42abd4330410c8cba1d08"
53
48
  }