Massive refactor complete

This commit is contained in:
2019-05-31 13:44:01 +10:00
parent b97d8fc184
commit 4a2bfb3db9
47 changed files with 1223 additions and 991 deletions
+9 -5
View File
@@ -5,18 +5,20 @@ require('dotenv').config();
let fs = require('fs');
let path = require('path');
let { log } = require('../common/utilities.js');
const newsRequest = () => (req, res) => {
let fpath = path.join(__dirname, '..', 'public', 'news');
let fileNames = fs.readdirSync(fpath);
//set the maximum
let max = parseInt(req.body.max);
if (max > fileNames.length) {
let max = parseInt(req.body.length) || 99;
if (isNaN(max) || max > fileNames.length) {
max = fileNames.length;
}
//build the object to send
let json = {} //TODO: caching
let json = {}; //TODO: caching
//send each file as json
for (let i = 0; i < max; i++) {
@@ -26,8 +28,10 @@ const newsRequest = () => (req, res) => {
//actually send the data
res.json(json);
res.end();
}
log('News sent', max, fileNames, JSON.stringify(json));
};
module.exports = {
newsRequest: newsRequest
}
};