|
@ -7,6 +7,8 @@ const https = require('https'); |
|
|
const exec = util.promisify(require('child_process').exec); |
|
|
const exec = util.promisify(require('child_process').exec); |
|
|
|
|
|
|
|
|
const EventEmitter = require('events'); |
|
|
const EventEmitter = require('events'); |
|
|
|
|
|
const csvParser = require('csv-parser'); |
|
|
|
|
|
const { PassThrough } = require('stream'); |
|
|
const slugify = require('slugify'); |
|
|
const slugify = require('slugify'); |
|
|
|
|
|
|
|
|
const dest = path.join(appRoot, 'public/csv'); |
|
|
const dest = path.join(appRoot, 'public/csv'); |
|
@ -14,7 +16,10 @@ const dest = path.join(appRoot, 'public/csv'); |
|
|
|
|
|
|
|
|
// Create a generateFilePath function witch returns a path with a filename and datetime
|
|
|
// Create a generateFilePath function witch returns a path with a filename and datetime
|
|
|
function generateFilePath(filename) { |
|
|
function generateFilePath(filename) { |
|
|
return path.join(dest, `${filename}-${Date.now()}.csv`); |
|
|
return { |
|
|
|
|
|
filepath: path.join(dest, `${filename}-${Date.now()}.csv`), |
|
|
|
|
|
generatedpath: path.join('csv', `${filename}-generated-${Date.now()}.csv`), |
|
|
|
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -39,7 +44,9 @@ class File extends EventEmitter { |
|
|
async download() { |
|
|
async download() { |
|
|
const url = URL.parse(this.url); |
|
|
const url = URL.parse(this.url); |
|
|
this.filename = slugify(url.hostname, { lower: true }); |
|
|
this.filename = slugify(url.hostname, { lower: true }); |
|
|
this.filepath = generateFilePath(this.filename); |
|
|
const { filepath, generatedpath } = generateFilePath(this.filename); |
|
|
|
|
|
this.filepath = filepath; |
|
|
|
|
|
this.generatedpath = generatedpath; |
|
|
|
|
|
|
|
|
const file = fs.createWriteStream(this.filepath); |
|
|
const file = fs.createWriteStream(this.filepath); |
|
|
const request = url.protocol === 'https:' ? https : http; |
|
|
const request = url.protocol === 'https:' ? https : http; |
|
|