From 11406c91df752a3aad1098c3c9375b87f76fd21a Mon Sep 17 00:00:00 2001 From: Nedya Prakasa Date: Fri, 25 Jun 2021 00:32:32 +0700 Subject: [PATCH 1/5] feat: custom dir on fs storage --- src/utils.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index ea4a8a5..a3bb588 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,10 +1,17 @@ -const fs = require('fs').promises +const fs = require('fs') +const promises = require('fs/promises') const os = require('os') +const path = require('path') const writeData = async (data, fileName, config, s3Client) => { if (config.storage.type === 'fs') { - const tmpDir = os.tmpdir() - await fs.writeFile(`${tmpDir}/${fileName}`, JSON.stringify(data)) + let pathDestination = os.tmpdir() + const customPath = config?.storage?.dir ?? '' + if (customPath && fs.existsSync(path.resolve(customPath))) { + pathDestination = customPath + } + + await promises.writeFile(`${pathDestination}/${fileName}`, JSON.stringify(data)) } else if (config.storage.type === 's3') { const { PutObjectCommand } = require('@aws-sdk/client-s3') const params = { From a80c0dc8ed242920042046f09d01ecbd41ef5716 Mon Sep 17 00:00:00 2001 From: Nedya Prakasa Date: Fri, 25 Jun 2021 00:34:52 +0700 Subject: [PATCH 2/5] chore: remove typo new line --- src/utils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index a3bb588..2e79cdd 100644 --- a/src/utils.js +++ b/src/utils.js @@ -10,7 +10,6 @@ const writeData = async (data, fileName, config, s3Client) => { if (customPath && fs.existsSync(path.resolve(customPath))) { pathDestination = customPath } - await promises.writeFile(`${pathDestination}/${fileName}`, JSON.stringify(data)) } else if (config.storage.type === 's3') { const { PutObjectCommand } = require('@aws-sdk/client-s3') From 7c57655463558fb1c871b4cd3120bed111db3c3a Mon Sep 17 00:00:00 2001 From: Nedya Prakasa Date: Fri, 25 Jun 2021 00:37:43 +0700 Subject: [PATCH 3/5] fix: fixing static code analytics --- src/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 2e79cdd..b459f0b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,9 +6,9 @@ const path = require('path') const writeData = async (data, fileName, config, s3Client) => { if (config.storage.type === 'fs') { let pathDestination = os.tmpdir() - const customPath = config?.storage?.dir ?? '' + const customPath = config.storage.dir || '' if (customPath && fs.existsSync(path.resolve(customPath))) { - pathDestination = customPath + pathDestination = path.resolve(customPath) } await promises.writeFile(`${pathDestination}/${fileName}`, JSON.stringify(data)) } else if (config.storage.type === 's3') { From 0867ebd086afd7214ee92787fc450a2568e4e2bf Mon Sep 17 00:00:00 2001 From: Nedya Prakasa Date: Fri, 25 Jun 2021 00:40:27 +0700 Subject: [PATCH 4/5] style: change path to dir variable --- src/utils.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils.js b/src/utils.js index b459f0b..d8a44df 100644 --- a/src/utils.js +++ b/src/utils.js @@ -5,12 +5,12 @@ const path = require('path') const writeData = async (data, fileName, config, s3Client) => { if (config.storage.type === 'fs') { - let pathDestination = os.tmpdir() - const customPath = config.storage.dir || '' - if (customPath && fs.existsSync(path.resolve(customPath))) { - pathDestination = path.resolve(customPath) + let destDir = os.tmpdir() + const customDir = config.storage.dir || '' + if (customDir && fs.existsSync(path.resolve(customDir))) { + destDir = path.resolve(customDir) } - await promises.writeFile(`${pathDestination}/${fileName}`, JSON.stringify(data)) + await promises.writeFile(`${destDir}/${fileName}`, JSON.stringify(data)) } else if (config.storage.type === 's3') { const { PutObjectCommand } = require('@aws-sdk/client-s3') const params = { From 30f56a4ec37e36a701cd603e920a0f56514e23df Mon Sep 17 00:00:00 2001 From: Nedya Prakasa Date: Fri, 25 Jun 2021 01:05:12 +0700 Subject: [PATCH 5/5] fix: fixing invalid import fs promise --- src/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index d8a44df..0dea36c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,5 +1,5 @@ const fs = require('fs') -const promises = require('fs/promises') +const fsPromises = require('fs').promises const os = require('os') const path = require('path') @@ -10,7 +10,7 @@ const writeData = async (data, fileName, config, s3Client) => { if (customDir && fs.existsSync(path.resolve(customDir))) { destDir = path.resolve(customDir) } - await promises.writeFile(`${destDir}/${fileName}`, JSON.stringify(data)) + await fsPromises.writeFile(`${destDir}/${fileName}`, JSON.stringify(data)) } else if (config.storage.type === 's3') { const { PutObjectCommand } = require('@aws-sdk/client-s3') const params = {