@strapi/provider-upload-cloudinary 4.0.7 → 4.1.1-alpha.0
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 +43 -37
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -13,49 +13,55 @@ module.exports = {
|
|
|
13
13
|
init(config) {
|
|
14
14
|
cloudinary.config(config);
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
if (file.ext) {
|
|
25
|
-
config.filename = `${file.hash}${file.ext}`;
|
|
26
|
-
}
|
|
16
|
+
const upload = (file, customConfig = {}) =>
|
|
17
|
+
new Promise(resolve => {
|
|
18
|
+
const config = {
|
|
19
|
+
resource_type: 'auto',
|
|
20
|
+
public_id: file.hash,
|
|
21
|
+
};
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (err) {
|
|
32
|
-
if (err.message.includes('File size too large')) {
|
|
33
|
-
throw new PayloadTooLargeError();
|
|
34
|
-
}
|
|
35
|
-
throw new Error(`Error uploading to cloudinary: ${err.message}`);
|
|
36
|
-
}
|
|
23
|
+
if (file.ext) {
|
|
24
|
+
config.filename = `${file.hash}${file.ext}`;
|
|
25
|
+
}
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
resource_type: 'video',
|
|
45
|
-
});
|
|
27
|
+
const upload_stream = cloudinary.uploader.upload_stream(
|
|
28
|
+
{ ...config, ...customConfig },
|
|
29
|
+
(err, image) => {
|
|
30
|
+
if (err) {
|
|
31
|
+
if (err.message.includes('File size too large')) {
|
|
32
|
+
throw new PayloadTooLargeError();
|
|
46
33
|
}
|
|
34
|
+
throw new Error(`Error uploading to cloudinary: ${err.message}`);
|
|
35
|
+
}
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
file.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
if (image.resource_type === 'video') {
|
|
38
|
+
file.previewUrl = cloudinary.url(`${image.public_id}.gif`, {
|
|
39
|
+
video_sampling: 6,
|
|
40
|
+
delay: 200,
|
|
41
|
+
width: 250,
|
|
42
|
+
crop: 'scale',
|
|
43
|
+
resource_type: 'video',
|
|
44
|
+
});
|
|
54
45
|
}
|
|
55
|
-
);
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
file.url = image.secure_url;
|
|
48
|
+
file.provider_metadata = {
|
|
49
|
+
public_id: image.public_id,
|
|
50
|
+
resource_type: image.resource_type,
|
|
51
|
+
};
|
|
52
|
+
resolve();
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
file.stream ? file.stream.pipe(upload_stream) : intoStream(file.buffer).pipe(upload_stream);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
uploadStream(file, customConfig = {}) {
|
|
61
|
+
return upload(file, customConfig);
|
|
62
|
+
},
|
|
63
|
+
upload(file, customConfig = {}) {
|
|
64
|
+
return upload(file, customConfig);
|
|
59
65
|
},
|
|
60
66
|
async delete(file, customConfig = {}) {
|
|
61
67
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/provider-upload-cloudinary",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.1-alpha.0",
|
|
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.0
|
|
39
|
+
"@strapi/utils": "4.1.1-alpha.0",
|
|
40
40
|
"cloudinary": "^1.25.1",
|
|
41
41
|
"into-stream": "^5.1.0"
|
|
42
42
|
},
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"node": ">=12.22.0 <=16.x.x",
|
|
45
45
|
"npm": ">=6.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "bedb04a0cc23719e4eac43e6005fe0fa3d48a9a6"
|
|
48
48
|
}
|