chore: use axios for the download and typo
This commit is contained in:
parent
908baa4fb0
commit
c4d695934c
2 changed files with 28 additions and 12 deletions
|
|
@ -72,8 +72,8 @@ function validateOfac (deviceId, sanctionsActive, customer) {
|
||||||
|
|
||||||
function validationPatch (deviceId, sanctionsActive, customer) {
|
function validationPatch (deviceId, sanctionsActive, customer) {
|
||||||
return validateOfac(deviceId, sanctionsActive, customer)
|
return validateOfac(deviceId, sanctionsActive, customer)
|
||||||
.then(sactions =>
|
.then(sanctions =>
|
||||||
_.isNil(customer.sanctions) || customer.sanctions !== sactions ?
|
_.isNil(customer.sanctions) || customer.sanctions !== sanctions ?
|
||||||
{ sanctions } :
|
{ sanctions } :
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const parser = require('./parsing')
|
const parser = require('./parsing')
|
||||||
const https = require('https')
|
const axios = require('axios')
|
||||||
const { createWriteStream } = require('fs')
|
const { createWriteStream } = require('fs')
|
||||||
const fs = require('fs/promises')
|
const fs = require('fs/promises')
|
||||||
const { rename } = fs
|
const { rename } = fs
|
||||||
|
|
@ -22,18 +22,34 @@ const mkdir = path =>
|
||||||
fs.mkdir(path)
|
fs.mkdir(path)
|
||||||
.catch(err => err.code === 'EEXIST' ? Promise.resolve() : Promise.reject(err))
|
.catch(err => err.code === 'EEXIST' ? Promise.resolve() : Promise.reject(err))
|
||||||
|
|
||||||
|
const newDownload = (dstDir, { name, url }) => {
|
||||||
|
return path.join('/tmp/', name + '.xml')
|
||||||
|
}
|
||||||
|
|
||||||
const download = (dstDir, { name, url }) => {
|
const download = (dstDir, { name, url }) => {
|
||||||
const dstFile = path.join(dstDir, name + '.xml')
|
const dstFile = path.join(dstDir, name + '.xml')
|
||||||
const file = createWriteStream(dstFile)
|
const writer = createWriteStream(dstFile)
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return axios({
|
||||||
const request = https.get(url, response => {
|
method: 'get',
|
||||||
response.pipe(file)
|
url: url,
|
||||||
file.on('finish', () => file.close(() => resolve(dstFile)))
|
responseType: 'stream',
|
||||||
})
|
}).then(response => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
request.on('error', reject)
|
response.data.pipe(writer);
|
||||||
})
|
let error = null;
|
||||||
|
writer.on('error', err => {
|
||||||
|
error = err;
|
||||||
|
writer.close();
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
writer.on('close', () => {
|
||||||
|
if (!error) {
|
||||||
|
resolve(dstFile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseToJson = srcFile => {
|
const parseToJson = srcFile => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue