Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
PipeItToDevNull committed Nov 4, 2024
2 parents 6f13601 + 46859ce commit 692a204
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 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,17 +111,14 @@ 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);

if (req.file) { // If a file is uploaded
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);

try {
logger.info(`Fetching file from URL: ${url}`);
Expand Down

0 comments on commit 692a204

Please sign in to comment.