Skip to content
Snippets Groups Projects
Commit c669dca6 authored by Josefine Wegert's avatar Josefine Wegert
Browse files

clientCounter fixed

parent a907921e
No related branches found
No related tags found
No related merge requests found
...@@ -42,10 +42,8 @@ app.set('zipFunctions', zipFunctions); ...@@ -42,10 +42,8 @@ app.set('zipFunctions', zipFunctions);
//clientCounter holds the number of clients who wants to download files //clientCounter holds the number of clients who wants to download files
let clientCounter = 0; let clientCounter = 0;
app.set('clientCounter', clientCounter); app.locals.clientCounter = clientCounter;
//routes //routes
//app.use('/', home);
require('./routes/home.js')(app); require('./routes/home.js')(app);
require('./routes/download.js')(app); require('./routes/download.js')(app);
......
...@@ -6,7 +6,6 @@ module.exports= function(app){ ...@@ -6,7 +6,6 @@ module.exports= function(app){
const downloadNames = app.get('downloadNames'); const downloadNames = app.get('downloadNames');
const downloadFiles = app.get('downloadFiles'); const downloadFiles = app.get('downloadFiles');
let clientCounter = app.get('clientCounter');
const clientFolder = app.get('clientFolder'); const clientFolder = app.get('clientFolder');
const backendFunctions = app.get('backendFunctions'); const backendFunctions = app.get('backendFunctions');
const frontendFunctions = app.get('frontendFunctions'); const frontendFunctions = app.get('frontendFunctions');
...@@ -16,18 +15,17 @@ const zipFunctions = app.get('zipFunctions'); ...@@ -16,18 +15,17 @@ const zipFunctions = app.get('zipFunctions');
app.get('/download', function(req, res, next){ app.get('/download', function(req, res, next){
const checkedFiles = req.query.checkedFiles.split(','); const checkedFiles = req.query.checkedFiles.split(',');
let clientName; let clientName;
let clientCounter = req.app.locals.clientCounter;
const zip = new JSZip(); const zip = new JSZip();
zip.file("README.txt", "text for README"); zip.file("README.txt", "text for README");
//holds promises for backend and/or frontend for synchronizing //holds promises for backend and/or frontend for synchronizing
const promiseArray = [] const promiseArray = []
console.log('clientCounter, download: ', clientCounter);
//TODO handle multiple clients //TODO handle multiple clients
if (clientCounter > 5){ if (clientCounter > 5){
res.render('tooManyClients'); res.render('tooManyClients');
}else{ }else{
clientName = 'client_' + clientCounter; clientName = 'client_' + clientCounter;
console.log('clientCounter, download.makeClientFolder: ', clientCounter);
clientFolder.makeClientFolder(clientName); clientFolder.makeClientFolder(clientName);
} }
...@@ -121,7 +119,7 @@ function createZip(zip){ ...@@ -121,7 +119,7 @@ function createZip(zip){
}).on('finish', function () { }).on('finish', function () {
console.log('explorviz-builds.zip written.'); console.log('explorviz-builds.zip written.');
//client finishes everything except getting the download //client finishes everything except getting the download
clientCounter = clientCounter - 1; req.app.locals.clientCounter = clientCounter - 1;
res.download('explorviz-builds.zip', function(error){ res.download('explorviz-builds.zip', function(error){
if(error){ if(error){
let response = let response =
......
...@@ -4,8 +4,6 @@ const express = require('express'); ...@@ -4,8 +4,6 @@ const express = require('express');
module.exports= function(app){ module.exports= function(app){
const downloadNames = app.get('downloadNames'); const downloadNames = app.get('downloadNames');
let clientCounter = app.get('clientCounter');
console.log('clientCounter, home: ', clientCounter);
//This route shows the homepage. //This route shows the homepage.
app.get('/', function(req, res){ app.get('/', function(req, res){
...@@ -15,12 +13,10 @@ 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. //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){ app.post('/', function(req, res, next){
const checkedFiles = Object.keys(req.body); const checkedFiles = Object.keys(req.body);
let clientCounter = req.app.locals.clientCounter;
if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){ if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){
let increasedClientCounter = clientCounter + 1; req.app.locals.clientCounter = clientCounter + 1;
app.set('clientCounter', increasedClientCounter);
console.log('clientCounter, home +1: ', clientCounter);
res.render('download', {checkedFiles: checkedFiles, downloadFiles: downloadNames}); res.render('download', {checkedFiles: checkedFiles, downloadFiles: downloadNames});
} }
else { else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment