@nexrender/core 1.41.1 → 1.42.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexrender/core",
3
- "version": "1.41.1",
3
+ "version": "1.42.0",
4
4
  "main": "src/index.js",
5
5
  "author": "Inlife",
6
6
  "scripts": {
@@ -11,10 +11,10 @@
11
11
  "data-uri-to-buffer": "^3.0.0",
12
12
  "file-uri-to-path": "^2.0.0",
13
13
  "is-wsl": "^2.2.0",
14
+ "make-fetch-happen": "^11.0.2",
14
15
  "match-all": "^1.2.5",
15
16
  "mime-types": "^2.1.29",
16
17
  "mkdirp": "^1.0.4",
17
- "node-fetch": "^2.6.7",
18
18
  "requireg": "^0.2.1",
19
19
  "rimraf": "^3.0.2"
20
20
  },
@@ -30,5 +30,5 @@
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "f7cbfd9d2a20c145547c30e16176e2fcb97a8813"
33
+ "gitHead": "8f7fb490c786fa1532e0f6608b2c18d1b690affb"
34
34
  }
package/readme.md CHANGED
@@ -72,3 +72,4 @@ Second one is responsible for mainly job-related operations of the full cycle: d
72
72
  * `forceCommandLinePatch` - boolean, providing true will force patch re-installation
73
73
  * `onInstanceSpawn` - a callback, if provided, gets called when **aerender** instance is getting spawned, with instance pointer. Can be later used to kill a hung aerender process. Callback signature: `function (instance, job, settings) {}`
74
74
  * `actions` - an object with keys corresponding to the `module` field when defining an action, value should be a function matching expected signature of an action. Used for defining actions programmatically without needing to package the action as a separate package
75
+ * `cache` - boolean or string. Set the cache folder used by HTTP assets. If `true` will use the default path of `${workpath}/http-cache`, if set to a string it will be interpreted as a filesystem path to the cache folder.
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs')
2
2
  const url = require('url')
3
3
  const path = require('path')
4
- const fetch = require('node-fetch').default
4
+ const fetch = require('make-fetch-happen')
5
5
  const uri2path = require('file-uri-to-path')
6
6
  const data2buf = require('data-uri-to-buffer')
7
7
  const mime = require('mime-types')
@@ -66,17 +66,29 @@ const download = (job, settings, asset) => {
66
66
 
67
67
  case 'http':
68
68
  case 'https':
69
+ // Use default cache path if `settings.cache` param is set to simply `true`
70
+ // Otherwise use value directly (can be string to file path or undefined)
71
+ const cachePath = settings.cache === true ?
72
+ path.join(settings.workpath, "http-cache") :
73
+ settings.cache;
74
+
75
+ if(!asset.params) asset.params = {};
76
+ // Asset's own `params.cachePath` takes precedence (including falsy values)
77
+ asset.params.cachePath = Object.hasOwn(asset.params, 'cachePath') ?
78
+ asset.params.cachePath :
79
+ cachePath;
80
+
69
81
  /* TODO: maybe move to external package ?? */
70
82
  const src = decodeURI(asset.src) === asset.src ? encodeURI(asset.src): asset.src
71
- return fetch(src, asset.params || {})
83
+ return fetch(src, asset.params)
72
84
  .then(res => res.ok ? res : Promise.reject({reason: 'Initial error downloading file', meta: {src, error: res.error}}))
73
85
  .then(res => {
74
86
  // Set a file extension based on content-type header if not already set
75
87
  if (!asset.extension) {
76
- const contentType = res.headers.get('content-type')
77
- const fileExt = mime.extension(contentType) || undefined
88
+ const contentType = res.headers.get('content-type')
89
+ const fileExt = mime.extension(contentType) || undefined
78
90
 
79
- asset.extension = fileExt
91
+ asset.extension = fileExt
80
92
  const destHasExtension = path.extname(asset.dest) ? true : false
81
93
  //don't do this if asset.dest already has extension else it gives you example.jpg.jpg like file in case of assets and aep/aepx file
82
94
  if (asset.extension && !destHasExtension) {