Add comments to file heads and imporove readability

This commit is contained in:
Fred Boniface 2022-12-08 12:37:23 +00:00
parent cc8dcd864c
commit fccb00232c
4 changed files with 33 additions and 29 deletions

24
app.js
View File

@ -1,9 +1,9 @@
// OwlBoard - © Fred Boniface 2022 - Licensed under GPLv3 (or later) // OwlBoard - © Fred Boniface 2022 - Licensed under GPLv3 (or later)
// Please see the included LICENSE file statically served fonts are // Please see the included LICENSE file. Statically served fonts are
// licensed separately, each folder contains a license file // licensed separately, each folder contains a license file where a
// different license applies.
// Load & prepare modules:
const express = require('express'); const express = require('express');
const app = express(); const app = express();
const config = require('./src/configs/server.configs'); const config = require('./src/configs/server.configs');
@ -11,20 +11,10 @@ const version = require('./src/configs/version.configs');
const testRtr = require('./src/routes/test.routes'); const testRtr = require('./src/routes/test.routes');
const listRtr = require('./src/routes/list.routes'); const listRtr = require('./src/routes/list.routes');
// TESTING ONLY
const corpus = require('./src/utils/corpus.utils');
corpus.getCorpus();
// Print version number: // Print version number:
console.log(`Starting OwlBoard - App Version: ${version.app} - API versions: ${version.api}`); console.log(`Starting OwlBoard - App Version: ${version.app} - API versions: ${version.api}`);
// Check database: // Express Error Handling:
// Check for presece of DB Credentials
// Check tables are correct
// Build lookup table is not present or if not been updated in X time.
// Error Handling:
app.use((err, req, res, next) => { app.use((err, req, res, next) => {
const statusCode = err.statuscode || 500; const statusCode = err.statuscode || 500;
console.error(err.message, err.stack); console.error(err.message, err.stack);
@ -32,15 +22,15 @@ app.use((err, req, res, next) => {
return; return;
}); });
// Submodules: // Express Submodules:
app.use(express.json()); //JSON Parsing for POST Requests app.use(express.json()); //JSON Parsing for POST Requests
app.use(express.static('static')); //Serve static content from static app.use(express.static('static')); //Serve static content from static
// Point to Routes // Express Routes
app.use('/api/v1/test', testRtr); app.use('/api/v1/test', testRtr);
app.use('/api/v1/list', listRtr); app.use('/api/v1/list', listRtr);
// Start server // Start Express
app.listen(config.port, config.listen, (error) =>{ app.listen(config.port, config.listen, (error) =>{
if(!error) { if(!error) {
console.log(`Started server on http://${config.listen}:${config.port}`); console.log(`Started server on http://${config.listen}:${config.port}`);

View File

@ -0,0 +1,7 @@
const database = {
port: 8460,
location: "localhost",
dbType: "postgres"
};
module.exports = database;

View File

@ -1,6 +1,6 @@
// Get CORPUS data from Network Rail and format the data for OwlBoard // Get CORPUS data from Network Rail and format the data for OwlBoard
// Username and password must be stored in `/srv/keys/owlboard/keys.config.js` // Network Rail Datafeed user and pass must be stored in `/srv/keys/owlboard/keys.config.js`
// FUNCTIONS // FUNCTIONS
// init() : Exported: Uses the internal functions to return a clean CORPUS file. // init() : Exported: Uses the internal functions to return a clean CORPUS file.
@ -19,15 +19,14 @@ async function initCorpus() {
async function getCorpus() { async function getCorpus() {
authHead = Buffer.from(`${keys.nr_user}:${keys.nr_pass}`).toString('base64'); authHead = Buffer.from(`${keys.nr_user}:${keys.nr_pass}`).toString('base64');
const url = 'https://datafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS'
const options = { const options = {
method: 'get', method: 'get',
baseURL: 'https://datafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS',
timeout: 3000, timeout: 3000,
headers: {'Authorization': `Basic ${authHead}`}, headers: {'Authorization': `Basic ${authHead}`},
responseType: 'arraybuffer' responseType: 'arraybuffer'
}; };
let download = axios.get(options); return await axios.get(url, options).then(function (response){console.log(response.data);return response.data;});
console.log(download);
} }
async function getCorpusAgain() { async function getCorpusAgain() {
@ -53,8 +52,10 @@ async function getCorpusAgain() {
}) })
} }
async function init() { async function init() { // PSUEDOCODE
var zipData = await get();
var rawData = extract(zipData);
var cleanData = clean(rawData)
} }
async function get() { async function get() {
@ -66,11 +67,12 @@ async function extract() {
} }
async function clean() { async function clean() {
} }
module.exports = { module.exports = {
initCorpus, initCorpus,
getCorpusAgain, getCorpusAgain,
getCorpus getCorpus,
init
} }

View File

@ -1,5 +1,10 @@
// Initialise database functions here // FUNCTIONS
// Rewrite Python3 script to clean CORPUS data // init() : Exported: Uses the internal functions to initialise databases.
// Also maybe scripting to FETCH the CORPUS data // check() : Checks authentication, presence of tables and contents of tables.
// build() : Builds the lookup table using the corpus.utils to download data.
const dbCfg = require('../configs/database.configs');
const corpus = require('../utils/corpus.utils');
const corpus = require('../utils/corpus.utils'); module.exports = {
init
}