@nexrender/core 1.60.9 → 1.60.11
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 +2 -2
- package/src/tasks/download.js +38 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexrender/core",
|
|
3
|
-
"version": "1.60.
|
|
3
|
+
"version": "1.60.11",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"author": "Inlife",
|
|
6
6
|
"homepage": "https://www.nexrender.com",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "50f8168326645ea39d97035b5548dfd73a0b32fc"
|
|
47
47
|
}
|
package/src/tasks/download.js
CHANGED
|
@@ -9,7 +9,7 @@ const mime = require('mime-types')
|
|
|
9
9
|
const {expandEnvironmentVariables} = require('../helpers/path')
|
|
10
10
|
const { withTimeout } = require('../helpers/timeout');
|
|
11
11
|
|
|
12
|
-
const NEXRENDER_DOWNLOAD_TIMEOUT = process.env.NEXRENDER_DOWNLOAD_TIMEOUT || 3 * 60 * 1000; // 3 minutes timeout by default
|
|
12
|
+
const NEXRENDER_DOWNLOAD_TIMEOUT = Number(process.env.NEXRENDER_DOWNLOAD_TIMEOUT) || 3 * 60 * 1000; // 3 minutes timeout by default
|
|
13
13
|
|
|
14
14
|
const download = (job, settings, asset) => {
|
|
15
15
|
if (asset.type == 'data') return Promise.resolve();
|
|
@@ -90,39 +90,49 @@ const download = (job, settings, asset) => {
|
|
|
90
90
|
|
|
91
91
|
/* TODO: maybe move to external package ?? */
|
|
92
92
|
const src = asset.src
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
return withTimeout(
|
|
96
|
+
fetch(src, {
|
|
97
|
+
...asset.params,
|
|
98
|
+
timeout: NEXRENDER_DOWNLOAD_TIMEOUT
|
|
99
|
+
})
|
|
100
|
+
.then(res => res.ok ? res : Promise.reject(new Error(`Unable to download file ${src}`)))
|
|
101
|
+
.then(res => {
|
|
102
|
+
// Set a file extension based on content-type header if not already set
|
|
103
|
+
if (!asset.extension) {
|
|
104
|
+
const contentType = res.headers.get('content-type')
|
|
105
|
+
const fileExt = mime.extension(contentType) || undefined
|
|
106
|
+
|
|
107
|
+
asset.extension = fileExt
|
|
108
|
+
const destHasExtension = path.extname(asset.dest) ? true : false
|
|
109
|
+
// don't do this if asset.dest already has extension else it gives you example.jpg.jpg
|
|
110
|
+
// like file in case of assets and aep/aepx file
|
|
111
|
+
if (asset.extension && !destHasExtension) {
|
|
112
|
+
asset.dest += `.${fileExt}`
|
|
113
|
+
}
|
|
107
114
|
}
|
|
108
|
-
}
|
|
109
115
|
|
|
110
|
-
|
|
116
|
+
const stream = fs.createWriteStream(asset.dest)
|
|
111
117
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
return withTimeout(new Promise((resolve, reject) => {
|
|
119
|
+
const errorHandler = (error) => {
|
|
120
|
+
reject(new Error('Unable to download file ' + asset.src + ' due to ' + error))
|
|
121
|
+
};
|
|
116
122
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
res.body
|
|
124
|
+
.on('error', errorHandler)
|
|
125
|
+
.pipe(stream)
|
|
120
126
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
stream
|
|
128
|
+
.on('error', errorHandler)
|
|
129
|
+
.on('finish', resolve)
|
|
130
|
+
}), NEXRENDER_DOWNLOAD_TIMEOUT, 'Download timed out for asset ' + asset.src)
|
|
124
131
|
}), NEXRENDER_DOWNLOAD_TIMEOUT, 'Download timed out for asset ' + asset.src)
|
|
125
|
-
|
|
132
|
+
} catch (error) {
|
|
133
|
+
settings.logger.log(`[download] error downloading asset ${asset.src}: ${error}`);
|
|
134
|
+
return Promise.reject(error);
|
|
135
|
+
}
|
|
126
136
|
|
|
127
137
|
case 'file':
|
|
128
138
|
const filepath = uri2path(expandEnvironmentVariables(asset.src))
|