@strapi/provider-upload-cloudinary 4.3.2 → 4.3.5
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/lib/index.js +15 -8
- package/package.json +4 -4
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
|
|
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
|
-
|
|
32
|
+
reject(new PayloadTooLargeError());
|
|
33
|
+
} else {
|
|
34
|
+
reject(new Error(`Error uploading to cloudinary: ${err.message}`));
|
|
33
35
|
}
|
|
34
|
-
|
|
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
|
-
|
|
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(
|
|
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:
|
|
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.
|
|
3
|
+
"version": "4.3.5",
|
|
4
4
|
"description": "Cloudinary provider for strapi upload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"upload",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"test": "echo \"no tests yet\""
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@strapi/utils": "4.3.
|
|
40
|
-
"cloudinary": "^1.
|
|
39
|
+
"@strapi/utils": "4.3.5",
|
|
40
|
+
"cloudinary": "^1.30.1",
|
|
41
41
|
"into-stream": "^5.1.0"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=14.19.1 <=16.x.x",
|
|
45
45
|
"npm": ">=6.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "a52b0535513ff35b4ef46c9daf7be48f2ba71737"
|
|
48
48
|
}
|