@strapi/provider-upload-cloudinary 4.3.4 → 4.3.7

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 (2) hide show
  1. package/lib/index.js +15 -8
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ module.exports = {
14
14
  cloudinary.config(config);
15
15
 
16
16
  const upload = (file, customConfig = {}) =>
17
- new Promise(resolve => {
17
+ new Promise((resolve, reject) => {
18
18
  const config = {
19
19
  resource_type: 'auto',
20
20
  public_id: file.hash,
@@ -24,14 +24,16 @@ module.exports = {
24
24
  config.filename = `${file.hash}${file.ext}`;
25
25
  }
26
26
 
27
- const upload_stream = cloudinary.uploader.upload_stream(
27
+ const uploadStream = cloudinary.uploader.upload_stream(
28
28
  { ...config, ...customConfig },
29
29
  (err, image) => {
30
30
  if (err) {
31
31
  if (err.message.includes('File size too large')) {
32
- throw new PayloadTooLargeError();
32
+ reject(new PayloadTooLargeError());
33
+ } else {
34
+ reject(new Error(`Error uploading to cloudinary: ${err.message}`));
33
35
  }
34
- throw new Error(`Error uploading to cloudinary: ${err.message}`);
36
+ return;
35
37
  }
36
38
 
37
39
  if (image.resource_type === 'video') {
@@ -49,11 +51,16 @@ module.exports = {
49
51
  public_id: image.public_id,
50
52
  resource_type: image.resource_type,
51
53
  };
54
+
52
55
  resolve();
53
56
  }
54
57
  );
55
58
 
56
- file.stream ? file.stream.pipe(upload_stream) : intoStream(file.buffer).pipe(upload_stream);
59
+ if (file.stream) {
60
+ file.stream.pipe(uploadStream);
61
+ } else {
62
+ intoStream(file.buffer).pipe(uploadStream);
63
+ }
57
64
  });
58
65
 
59
66
  return {
@@ -65,10 +72,10 @@ module.exports = {
65
72
  },
66
73
  async delete(file, customConfig = {}) {
67
74
  try {
68
- const { resource_type, public_id } = file.provider_metadata;
69
- const response = await cloudinary.uploader.destroy(public_id, {
75
+ const { resource_type: resourceType, public_id: publicId } = file.provider_metadata;
76
+ const response = await cloudinary.uploader.destroy(publicId, {
70
77
  invalidate: true,
71
- resource_type: resource_type || 'image',
78
+ resource_type: resourceType || 'image',
72
79
  ...customConfig,
73
80
  });
74
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/provider-upload-cloudinary",
3
- "version": "4.3.4",
3
+ "version": "4.3.7",
4
4
  "description": "Cloudinary provider for strapi upload",
5
5
  "keywords": [
6
6
  "upload",
@@ -36,7 +36,7 @@
36
36
  "test": "echo \"no tests yet\""
37
37
  },
38
38
  "dependencies": {
39
- "@strapi/utils": "4.3.4",
39
+ "@strapi/utils": "4.3.7",
40
40
  "cloudinary": "^1.30.1",
41
41
  "into-stream": "^5.1.0"
42
42
  },
@@ -44,5 +44,5 @@
44
44
  "node": ">=14.19.1 <=16.x.x",
45
45
  "npm": ">=6.0.0"
46
46
  },
47
- "gitHead": "28a2a00db8234ffcf644661c4c8092aa82f8c119"
47
+ "gitHead": "73f523b98322cea8992c72977b94a73a624d2e79"
48
48
  }