@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.
Files changed (2) hide show
  1. package/lib/index.js +43 -37
  2. 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
- return {
17
- upload(file, customConfig = {}) {
18
- return new Promise(resolve => {
19
- const config = {
20
- resource_type: 'auto',
21
- public_id: file.hash,
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
- const upload_stream = cloudinary.uploader.upload_stream(
29
- { ...config, ...customConfig },
30
- (err, image) => {
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
- if (image.resource_type === 'video') {
39
- file.previewUrl = cloudinary.url(`${image.public_id}.gif`, {
40
- video_sampling: 6,
41
- delay: 200,
42
- width: 250,
43
- crop: 'scale',
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
- file.url = image.secure_url;
49
- file.provider_metadata = {
50
- public_id: image.public_id,
51
- resource_type: image.resource_type,
52
- };
53
- resolve();
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
- intoStream(file.buffer).pipe(upload_stream);
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.7",
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.7",
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": "af0cba8c5b2ba7b371523e8f55413ef0fce98e1e"
47
+ "gitHead": "bedb04a0cc23719e4eac43e6005fe0fa3d48a9a6"
48
48
  }