@nexrender/core 1.60.10 → 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 +37 -31
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
|
@@ -90,43 +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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
+
}
|
|
111
114
|
}
|
|
112
|
-
}
|
|
113
115
|
|
|
114
|
-
|
|
116
|
+
const stream = fs.createWriteStream(asset.dest)
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
+
};
|
|
120
122
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
res.body
|
|
124
|
+
.on('error', errorHandler)
|
|
125
|
+
.pipe(stream)
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
stream
|
|
128
|
+
.on('error', errorHandler)
|
|
129
|
+
.on('finish', resolve)
|
|
130
|
+
}), NEXRENDER_DOWNLOAD_TIMEOUT, 'Download timed out for asset ' + asset.src)
|
|
128
131
|
}), NEXRENDER_DOWNLOAD_TIMEOUT, 'Download timed out for asset ' + asset.src)
|
|
129
|
-
|
|
132
|
+
} catch (error) {
|
|
133
|
+
settings.logger.log(`[download] error downloading asset ${asset.src}: ${error}`);
|
|
134
|
+
return Promise.reject(error);
|
|
135
|
+
}
|
|
130
136
|
|
|
131
137
|
case 'file':
|
|
132
138
|
const filepath = uri2path(expandEnvironmentVariables(asset.src))
|