Feat/excel (#45)

* add dependency

adding dependency to parse the excel file in the node side

* import file

ability to import file
- add extension
- safeguard file type and size

* user is able to upload json or excel

* chore: extract logic into self contained function

* associate model with version

* test id generation

* parse excel data

* prevent UI crash on bad data

* extract validation into self contained function

* chore: add more tests for bad data

* config: stop from opening browser on start

* fix comma in sample db

* handle corrupt files

* error boundary around main components

* jsdocs

* increase id length

* parse excel time string

* feat: excel parsing

* validate json db before import

* chore: test event validator

* feat: make function to clean convert strings

* chore: test parser

* chore: jsdocs

* fix: bug on upload

prevent bug where the component would prevent upload of same file twice
This commit is contained in:
Carlos Valente
2021-11-24 22:07:31 +01:00
committed by GitHub
parent bf8170a947
commit 8c740b7111
22 changed files with 1222 additions and 169 deletions
+17 -7
View File
@@ -26,22 +26,33 @@ import { Client } from 'node-osc';
import express from 'express';
import http from 'http';
import cors from 'cors';
import { dbModel } from './models/dataModel.js';
import { dbModelv1 as dbModel } from './models/dataModel.js';
import { parseJsonv1 as parseJson, validateFile } from './utils/parser.js';
import ua from 'universal-analytics';
// Read data from JSON file, this will set db.data content
await db.read();
// validate JSON before attempting read
let isValid = validateFile(file);
if (isValid) {
console.log('reading this');
// Read data from JSON file, this will set db.data content
await db.read();
}
// If file.json doesn't exist, db.data will be null
// Set default data
// db.data ||= { events: [] }; NODE v15 - v16
if (db.data == null) {
if (db.data == null || !isValid) {
db.data = dbModel;
db.write();
await db.write();
}
// get data
export const data = db.data;
// there is also the case of the db being corrupt
// try to parse the data
export const data = await parseJson(db.data);
db.data = data;
await db.write();
// Import Routes
import { router as eventsRouter } from './routes/eventsRouter.js';
@@ -107,7 +118,6 @@ app.use((err, req, res, next) => {
*/
const s = data.settings;
const oscIP = s.oscOutIP || config.osc.ipOut;
const oscOutPort = s.oscOutPort || config.osc.portOut;
const oscInPort = s.oscInPort || config.osc.port;