From 09e172e81ea0652c33020f693267294afd1d5540 Mon Sep 17 00:00:00 2001 From: PipeItToDevNull Date: Sun, 3 Nov 2024 17:59:54 -0500 Subject: [PATCH 1/2] when getting a file name it after the time in milliseconds --- api/api.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/api/api.js b/api/api.js index ef20777..661fc27 100755 --- a/api/api.js +++ b/api/api.js @@ -106,17 +106,16 @@ const analyzeFile = (filePath, res) => { // PUT and POST endpoint to receive .dmp file or URL and analyze it const handleAnalyzeDmp = async (req, res) => { - if (req.file) { - // If a file is uploaded - const filePath = path.join(uploadsDir, req.file.originalname); + const currentTime = new Date().toISOString().slice(11, 23).replace(/[:.]/g, ''); // Get current time in HHMMSSmmm format + + if (req.file) { // If a file is uploaded + const filePath = path.join(uploadsDir, `${currentTime}.dmp`); logger.info(`File uploaded: ${filePath}`); analyzeFile(filePath, res); - } else if (req.query.url) { - // If a URL is provided + } else if (req.query.url) { // If a URL is provided const encodedUrl = req.query.url; const url = decodeURIComponent(encodedUrl); // Decode the URL - const fileName = path.basename(url); - const filePath = path.join(uploadsDir, fileName); + const filePath = path.join(uploadsDir, `${currentTime}.dmp`); try { logger.info(`Fetching file from URL: ${url}`); From 9b0a836724c143ad39bd0ddc8f8fa317c38ebeb5 Mon Sep 17 00:00:00 2001 From: PipeItToDevNull Date: Sun, 3 Nov 2024 20:17:15 -0500 Subject: [PATCH 2/2] correct our method of setting the time and consolidate variables --- api/api.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/api/api.js b/api/api.js index 661fc27..7774595 100755 --- a/api/api.js +++ b/api/api.js @@ -37,13 +37,18 @@ if (!fs.existsSync(uploadsDir)) { fs.mkdirSync(uploadsDir); } +// Set our filename based on the current time +const currentTime = new Date().toISOString().slice(11, 23).replace(/[:.]/g, ''); // Get current time in HHMMSSmmm format +const fileName = `${currentTime}.dmp`; +const filePath = path.join(uploadsDir, `${fileName}`); + // Configure multer for file uploads const storage = multer.diskStorage({ destination: (req, file, cb) => { cb(null, uploadsDir); }, filename: (req, file, cb) => { - cb(null, file.originalname); + cb(null, fileName); } }); @@ -106,16 +111,14 @@ const analyzeFile = (filePath, res) => { // PUT and POST endpoint to receive .dmp file or URL and analyze it const handleAnalyzeDmp = async (req, res) => { - const currentTime = new Date().toISOString().slice(11, 23).replace(/[:.]/g, ''); // Get current time in HHMMSSmmm format if (req.file) { // If a file is uploaded - const filePath = path.join(uploadsDir, `${currentTime}.dmp`); logger.info(`File uploaded: ${filePath}`); analyzeFile(filePath, res); + } else if (req.query.url) { // If a URL is provided const encodedUrl = req.query.url; const url = decodeURIComponent(encodedUrl); // Decode the URL - const filePath = path.join(uploadsDir, `${currentTime}.dmp`); try { logger.info(`Fetching file from URL: ${url}`);