Massive refactor complete
This commit is contained in:
+9
-5
@@ -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
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user