Skip to content

Commit

Permalink
Merge pull request #363 from neuroanatomy/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
katjaq authored Jan 17, 2023
2 parents df48d96 + 04513c3 commit a652e0b
Show file tree
Hide file tree
Showing 66 changed files with 13,273 additions and 12,079 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/public/lib/
/public/js/
dist/
/view/atlasmaker/src/tools/render3D/three.js*
11 changes: 6 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"[javascript]": {
"editor.formatOnSave": false
"editor.formatOnSave": false,
"editor.codeActionsOnSave": [
"source.formatDocument", // used by rohit-gohri.format-code-action
"source.fixAll.eslint" // used by dbaeumer.vscode-eslint
]
}
}
}
4 changes: 1 addition & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const nwl = require('neuroweblab');
const fs = require('fs');
const express = require('express');
var compression = require('compression');
const compression = require('compression');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
Expand Down Expand Up @@ -36,7 +36,6 @@ if (DOCKER_DB) {

/** @todo Handle the case when MongoDB is not installed */
// var db = monk(MONGO_DB);
var expressValidator = require('express-validator');

/* jslint nomen: true */
const dirname = __dirname; // Local directory
Expand Down Expand Up @@ -108,7 +107,6 @@ const start = async function () {
};
}
app.use(logger(':remote-addr :method :url :status :response-time ms - :res[content-length]', loggerOptions));//app.use(logger('dev'));
app.use(expressValidator());
app.use(cookieParser());
app.use(express.static(path.join(dirname, 'public')));

Expand Down
40 changes: 21 additions & 19 deletions controller/admin/admin.controller.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
const notifier = require("../../notifier");
const notifier = require('../../notifier');
const { body, validationResult } = require('express-validator');

const validator = (req, res, next) => {
const authorizedIP = ["1"]; // hardcoded authorized IPs
const authorizedIP = ['1']; // hardcoded authorized IPs
let ip;
if(req.connection.remoteAddress) {
if (req.connection.remoteAddress) {
ip = req.connection.remoteAddress;
} else if(req.socket._peername) {
} else if (req.socket._peername) {
ip = req.socket._peername.address;
}

ip = ip.split(":").pop();
console.log({ip});
ip = ip.split(':').pop();
console.log({ ip });

if(authorizedIP.includes(ip)) {
if (authorizedIP.includes(ip)) {
return next();
}

res.status(403).send({error: "Unauthorized address"})
res.status(403).send({ error: 'Unauthorized address' })
.end();
};

Expand All @@ -27,8 +28,8 @@ const validator = (req, res, next) => {
* @returns {void}
*/
const saveAllAtlases = (req, res) => {
notifier.emit("saveAllAtlases");
res.send({msg: "Will save all atlases", success: true});
notifier.emit('saveAllAtlases');
res.send({ msg: 'Will save all atlases', success: true });
};

/**
Expand All @@ -38,21 +39,22 @@ const saveAllAtlases = (req, res) => {
* @param {object} res Response object
* @returns {void}
*/
const broadcastMessage = (req, res) => {
console.log("broadcastMessage");
const broadcastMessage = async (req, res) => {
console.log('broadcastMessage');

req.checkBody('msg', 'Provide a msg to broadcast')
.notEmpty();
await body('msg', 'Provide a msg to broadcast')
.notEmpty()
.run(req);

const errors = req.validationErrors();
if (errors) {
const errors = validationResult(req).array();
if (errors.length) {
return res.status(403).send(errors)
.end();
}
// const msg = req.sanitize(req.body.msg); // why does this not work?
const {msg} = req.body;
notifier.emit("broadcastMessage", msg);
res.send({msg: "Will broadcast message " + msg, success: true});
const { msg } = req.body;
notifier.emit('broadcastMessage', msg);
res.send({ msg: 'Will broadcast message ' + msg, success: true });
};

module.exports = {
Expand Down
6 changes: 3 additions & 3 deletions controller/admin/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var express = require('express');
var controller = require('./admin.controller');
var router = new express.Router();
const express = require('express');
const controller = require('./admin.controller');
const router = new express.Router();

router.post('/save-all-atlases', controller.validator, controller.saveAllAtlases);
router.post('/broadcast-message', controller.validator, controller.broadcastMessage);
Expand Down
4 changes: 2 additions & 2 deletions controller/api/api.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getLabelsets = async (req, res) => {
const info = [];
for (const label of arr) {
// eslint-disable-next-line no-await-in-loop
var json = JSON.parse(await fs.promises.readFile(path.join(__dirname, '../../public/labels/' + label)));
const json = JSON.parse(await fs.promises.readFile(path.join(__dirname, '../../public/labels/' + label)));
info.push({
name: json.name,
source: label
Expand Down Expand Up @@ -139,7 +139,7 @@ const log = async (req, res) => {
if(result) {
length = parseFloat(result.value.length);
}
var sum = parseFloat(json.value.length) + length;
const sum = parseFloat(json.value.length) + length;
await db.get('log').update(obj, {$set:{
'value.length':sum,
date: (new Date()).toJSON()
Expand Down
6 changes: 3 additions & 3 deletions controller/api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var express = require('express');
var controller = require('./api.controller');
const express = require('express');
const controller = require('./api.controller');

var router = new express.Router();
const router = new express.Router();

router.get('/getLabelsets', controller.getLabelsets);
router.get('/userNameQuery', controller.userNameQuery);
Expand Down
Loading

0 comments on commit a652e0b

Please sign in to comment.