- requestParams.json['signature'] = {
- host, // Which host we pretend to be
- signature: sign(dataToSign)
- }
- }
+ return new Bluebird<void>((res, rej) => {
+ const file = createWriteStream(destPath)
+ file.on('finish', () => res())
+
+ request(requestOptions)
+ .on('data', onRequestDataLengthCheck(bodyKBLimit))
+ .on('error', err => {
+ file.close()
+
+ remove(destPath)
+ .catch(err => logger.error('Cannot remove %s after request failure.', destPath, { err }))
+
+ return rej(err)
+ })
+ .pipe(file)
+ })
+}
+
+async function downloadImage (url: string, destDir: string, destName: string, size: { width: number, height: number }) {
+ const tmpPath = join(CONFIG.STORAGE.TMP_DIR, 'pending-' + destName)
+ await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath)