diff --git a/app.js b/app.js index 6a5d22b5e1aaa25e24f4c159b6e4ad522cb386d8..4892eeee2d96fbdeb5e5c6412f2ae5e55d613a98 100644 --- a/app.js +++ b/app.js @@ -42,10 +42,8 @@ app.set('zipFunctions', zipFunctions); //clientCounter holds the number of clients who wants to download files let clientCounter = 0; -app.set('clientCounter', clientCounter); - +app.locals.clientCounter = clientCounter; //routes -//app.use('/', home); require('./routes/home.js')(app); require('./routes/download.js')(app); diff --git a/routes/download.js b/routes/download.js index 4ae8060694fcc5f6443a403b2dd6b47ecb3d96ef..2b2d1f17a9f82d547e0f8f5cf4b163d9eaa1875f 100644 --- a/routes/download.js +++ b/routes/download.js @@ -6,7 +6,6 @@ module.exports= function(app){ const downloadNames = app.get('downloadNames'); const downloadFiles = app.get('downloadFiles'); -let clientCounter = app.get('clientCounter'); const clientFolder = app.get('clientFolder'); const backendFunctions = app.get('backendFunctions'); const frontendFunctions = app.get('frontendFunctions'); @@ -16,18 +15,17 @@ const zipFunctions = app.get('zipFunctions'); app.get('/download', function(req, res, next){ const checkedFiles = req.query.checkedFiles.split(','); let clientName; + let clientCounter = req.app.locals.clientCounter; const zip = new JSZip(); zip.file("README.txt", "text for README"); //holds promises for backend and/or frontend for synchronizing const promiseArray = [] - console.log('clientCounter, download: ', clientCounter); //TODO handle multiple clients if (clientCounter > 5){ res.render('tooManyClients'); }else{ clientName = 'client_' + clientCounter; - console.log('clientCounter, download.makeClientFolder: ', clientCounter); clientFolder.makeClientFolder(clientName); } @@ -121,7 +119,7 @@ function createZip(zip){ }).on('finish', function () { console.log('explorviz-builds.zip written.'); //client finishes everything except getting the download - clientCounter = clientCounter - 1; + req.app.locals.clientCounter = clientCounter - 1; res.download('explorviz-builds.zip', function(error){ if(error){ let response = diff --git a/routes/home.js b/routes/home.js index 4864c144402eac96f6526011ad774b122a4dd80b..c55e0dd61c588d84621c24f00fe6c0b856b46aaa 100644 --- a/routes/home.js +++ b/routes/home.js @@ -4,8 +4,6 @@ const express = require('express'); module.exports= function(app){ const downloadNames = app.get('downloadNames'); -let clientCounter = app.get('clientCounter'); -console.log('clientCounter, home: ', clientCounter); //This route shows the homepage. app.get('/', function(req, res){ @@ -15,12 +13,10 @@ app.get('/', function(req, res){ //This route takes the checkedFiles the user selected on the homepage, shows the download page on which the actual download is triggered. app.post('/', function(req, res, next){ const checkedFiles = Object.keys(req.body); + let clientCounter = req.app.locals.clientCounter; if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){ -let increasedClientCounter = clientCounter + 1; - - app.set('clientCounter', increasedClientCounter); - console.log('clientCounter, home +1: ', clientCounter); + req.app.locals.clientCounter = clientCounter + 1; res.render('download', {checkedFiles: checkedFiles, downloadFiles: downloadNames}); } else {