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);
//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);
......
......@@ -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 =
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment