Skip to content

Commit

Permalink
Merge pull request #8 from PipeItToDevNull/4-download-files-as-a-spec…
Browse files Browse the repository at this point in the history
…ifc-name-naming-convention-to-avoid-issues

correct our method of setting the time and consolidate variables
  • Loading branch information
PipeItToDevNull authored Nov 4, 2024
2 parents bccd201 + 9b0a836 commit 46859ce
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit 46859ce

Please sign in to comment.