@nexrender/core 1.41.0 → 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.0",
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": "01e3428a9194eb50e40f22a66bb236c9fc70a03c"
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) {
@@ -205,19 +205,26 @@ module.exports = (job, settings) => {
205
205
  // the outputfile appears to be forced as .mov.
206
206
  // We need to maintain this here while we have 2022 and 2020
207
207
  // workers simultaneously
208
- const movOutputFile = outputFile.replace(/\.avi$/g, '.mov')
209
- const existsMovOutputFile = fs.existsSync(movOutputFile)
210
- if (existsMovOutputFile) {
211
- job.output = movOutputFile
212
- } else {
213
- // AE 2023 use mp4 output files
214
- const mp4OutputFile = outputFile.replace(/\.avi$/g, '.mp4')
215
- const existsMp4OutputFile = fs.existsSync(mp4OutputFile)
216
- if (existsMp4OutputFile) {
217
- job.output = mp4OutputFile
218
- }
208
+
209
+ const defaultOutputs = [
210
+ job.output,
211
+ job.output.replace(/\.avi$/g, '.mov'),
212
+ job.output.replace(/\.avi$/g, '.mp4'),
213
+ job.output.replace(/\.mov$/g, '.avi'),
214
+ job.output.replace(/\.mov$/g, '.mp4'),
215
+ ]
216
+
217
+ while (!fs.existsSync(defaultOutputs[0]) && defaultOutputs.length > 0) {
218
+ defaultOutputs.shift();
219
219
  }
220
220
 
221
+ if (defaultOutputs.length === 0) {
222
+ clearTimeout(timeoutID);
223
+ return reject(new Error(`Output file not found: ${job.output}`));
224
+ }
225
+
226
+ job.output = defaultOutputs[0];
227
+
221
228
  if (!fs.existsSync(job.output)) {
222
229
  if (fs.existsSync(logPath)) {
223
230
  settings.logger.log(`[${job.uid}] dumping aerender log:`)