@nexrender/core 1.60.2 → 1.60.5

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.60.2",
3
+ "version": "1.60.5",
4
4
  "main": "src/index.js",
5
5
  "author": "Inlife",
6
6
  "homepage": "https://www.nexrender.com",
@@ -24,6 +24,7 @@
24
24
  "strip-comments": "^2.0.1"
25
25
  },
26
26
  "peerDependencies": {
27
+ "@nexrender/action-cache": "^1.53.2",
27
28
  "@nexrender/action-copy": "^1.0.0",
28
29
  "@nexrender/action-decompress": "^1.48.2",
29
30
  "@nexrender/action-encode": "^1.1.4",
@@ -42,5 +43,5 @@
42
43
  "publishConfig": {
43
44
  "access": "public"
44
45
  },
45
- "gitHead": "5717f5a812623265f51c49c67ba4c15eef0c3b24"
46
+ "gitHead": "5ab029fe67966f2cd481c1d4adb3b076513525b8"
46
47
  }
@@ -0,0 +1,20 @@
1
+ const withTimeout = (promise, timeoutMs, errorMsg) => {
2
+ let timeoutHandle;
3
+
4
+ const timeoutPromise = new Promise((_, reject) => {
5
+ timeoutHandle = setTimeout(() => {
6
+ reject(new Error(errorMsg));
7
+ }, timeoutMs);
8
+ });
9
+
10
+ return Promise.race([
11
+ promise,
12
+ timeoutPromise,
13
+ ]).finally(() => {
14
+ clearTimeout(timeoutHandle);
15
+ });
16
+ };
17
+
18
+ module.exports = {
19
+ withTimeout,
20
+ };
package/src/index.js CHANGED
@@ -36,6 +36,7 @@ if (process.env.NEXRENDER_REQUIRE_PLUGINS) {
36
36
  require('@nexrender/action-link');
37
37
  require('@nexrender/action-webhook');
38
38
  require('@nexrender/action-mogrt');
39
+ require('@nexrender/action-cache');
39
40
 
40
41
  require('@nexrender/provider-s3');
41
42
  require('@nexrender/provider-ftp');
@@ -7,6 +7,9 @@ const uri2path = require('file-uri-to-path')
7
7
  const data2buf = require('data-uri-to-buffer')
8
8
  const mime = require('mime-types')
9
9
  const {expandEnvironmentVariables} = require('../helpers/path')
10
+ const { withTimeout } = require('../helpers/timeout');
11
+
12
+ const NEXRENDER_DOWNLOAD_TIMEOUT = process.env.NEXRENDER_DOWNLOAD_TIMEOUT || 3 * 60 * 1000; // 3 minutes timeout by default
10
13
 
11
14
  const download = (job, settings, asset) => {
12
15
  if (asset.type == 'data') return Promise.resolve();
@@ -85,7 +88,7 @@ const download = (job, settings, asset) => {
85
88
 
86
89
  /* TODO: maybe move to external package ?? */
87
90
  const src = asset.src
88
- return fetch(src, asset.params)
91
+ return withTimeout(fetch(src, asset.params), NEXRENDER_DOWNLOAD_TIMEOUT, 'Download timed out')
89
92
  .then(res => res.ok ? res : Promise.reject(new Error(`Unable to download file ${src}`)))
90
93
  .then(res => {
91
94
  // Set a file extension based on content-type header if not already set