@strapi/provider-upload-local 4.6.0 → 4.6.1

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 +27 -11
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -9,17 +9,21 @@ const { pipeline } = require('stream');
9
9
  const fs = require('fs');
10
10
  const path = require('path');
11
11
  const fse = require('fs-extra');
12
- const { PayloadTooLargeError } = require('@strapi/utils').errors;
12
+ const {
13
+ errors: { PayloadTooLargeError },
14
+ file: { kbytesToBytes, bytesToHumanReadable },
15
+ } = require('@strapi/utils');
13
16
 
14
17
  const UPLOADS_FOLDER_NAME = 'uploads';
15
18
 
16
19
  module.exports = {
17
- init({ sizeLimit = 1000000 } = {}) {
18
- const verifySize = (file) => {
19
- if (file.size > sizeLimit) {
20
- throw new PayloadTooLargeError();
21
- }
22
- };
20
+ init({ sizeLimit: providerOptionsSizeLimit } = {}) {
21
+ // TODO V5: remove providerOptions sizeLimit
22
+ if (providerOptionsSizeLimit) {
23
+ process.emitWarning(
24
+ `[deprecated] In future versions, "sizeLimit" argument will be ignored from upload.config.providerOptions. Move it to upload.config`
25
+ );
26
+ }
23
27
 
24
28
  // Ensure uploads folder exists
25
29
  const uploadPath = path.resolve(strapi.dirs.static.public, UPLOADS_FOLDER_NAME);
@@ -30,9 +34,23 @@ module.exports = {
30
34
  }
31
35
 
32
36
  return {
37
+ checkFileSize(file, { sizeLimit } = {}) {
38
+ // TODO V5: remove providerOptions sizeLimit
39
+ if (providerOptionsSizeLimit) {
40
+ if (kbytesToBytes(file.size) > providerOptionsSizeLimit)
41
+ throw new PayloadTooLargeError(
42
+ `${file.name} exceeds size limit of ${bytesToHumanReadable(
43
+ providerOptionsSizeLimit
44
+ )}.`
45
+ );
46
+ } else if (sizeLimit) {
47
+ if (kbytesToBytes(file.size) > sizeLimit)
48
+ throw new PayloadTooLargeError(
49
+ `${file.name} exceeds size limit of ${bytesToHumanReadable(sizeLimit)}.`
50
+ );
51
+ }
52
+ },
33
53
  uploadStream(file) {
34
- verifySize(file);
35
-
36
54
  return new Promise((resolve, reject) => {
37
55
  pipeline(
38
56
  file.stream,
@@ -50,8 +68,6 @@ module.exports = {
50
68
  });
51
69
  },
52
70
  upload(file) {
53
- verifySize(file);
54
-
55
71
  return new Promise((resolve, reject) => {
56
72
  // write file in public/assets folder
57
73
  fs.writeFile(path.join(uploadPath, `${file.hash}${file.ext}`), file.buffer, (err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/provider-upload-local",
3
- "version": "4.6.0",
3
+ "version": "4.6.1",
4
4
  "description": "Local provider for strapi upload",
5
5
  "keywords": [
6
6
  "upload",
@@ -35,12 +35,12 @@
35
35
  "test": "echo \"no tests yet\""
36
36
  },
37
37
  "dependencies": {
38
- "@strapi/utils": "4.6.0",
38
+ "@strapi/utils": "4.6.1",
39
39
  "fs-extra": "10.0.0"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=14.19.1 <=18.x.x",
43
43
  "npm": ">=6.0.0"
44
44
  },
45
- "gitHead": "a9e55435c489f3379d88565bf3f729deb29bfb45"
45
+ "gitHead": "17a7845e3d453ea2e7911bda6ec25ed196dd5f16"
46
46
  }