diff --git a/src/models/File.js b/src/models/File.js index 730b018..e518e56 100644 --- a/src/models/File.js +++ b/src/models/File.js @@ -7,6 +7,8 @@ const https = require('https'); const exec = util.promisify(require('child_process').exec); const EventEmitter = require('events'); +const csvParser = require('csv-parser'); +const { PassThrough } = require('stream'); const slugify = require('slugify'); 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 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() { const url = URL.parse(this.url); 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 request = url.protocol === 'https:' ? https : http;