Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunlumbcgov committed Dec 8, 2023
1 parent 3dd6183 commit 682a7fa
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions backend/src/routes/download-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ async function flushFileCache(req, res) {
if (providedToken !== configuredToken) {
return res.status(403).send('Invalid token');
}
// Check if fileCache is less than 5 minutes old



fileCache.flushAll();
schoolCache.flushAll();
const directoryPath = FILE_STORAGE_DIR ;
Expand All @@ -48,6 +44,7 @@ async function flushFileCache(req, res) {

async function createCSVFile(req,res, next){
try {

jsonExport(req.jsonData, async function(err, csv){
if (err) return console.error(err);
await writeFileAsync(filePath, csv, 'binary');
Expand Down Expand Up @@ -80,14 +77,14 @@ async function getDownload(req, res,next){
return res.status(400).send("Invalid 'filepath' parameter");
}
}

filePath = path.join(FILE_STORAGE_DIR, `${filepath}.csv`);
if(fileCache.has(filepath)){
const file = path.join(FILE_STORAGE_DIR, `${filepath}.csv`);
res.setHeader('Content-Disposition', `attachment; filename="${filepath}.csv"`);
return res.sendFile(file);
}else{
try {
const path = req.url.replace('/csv', ''); // Modify the URL path as needed
const path = req.url.replace('/csv', ''); // Modify the URL path as neededz
const url =`${config.get("server:backend")}/v1${path}`
const response = await axios.get(url, { headers: { Authorization: `Bearer ${req.accessToken}` } });
// Attach the fetched data to the request object
Expand Down Expand Up @@ -116,7 +113,6 @@ async function getCSVDownload(req, res) {
}
}
const filePath = path.join(FILE_STORAGE_DIR, `${filepath}.csv`);
console.log(filePath)
res.sendFile(filePath);
} catch (error) {
console.error("Error:", error);
Expand Down

0 comments on commit 682a7fa

Please sign in to comment.