Compare View

switch
from
...
to
 
Commits (2)

Changes

Showing 4 changed files Side-by-side Diff

... ... @@ -17,6 +17,7 @@ const routerMatrix = require('./router-matrix');
17 17 const routerServices = require('./router-services');
18 18 const routerProducts = require('./router-products');
19 19 const routerRemoteProducts = require('./router-remote-products');
  20 +const routerLocations = require('./router-locations');
20 21  
21 22 const app = express();
22 23  
... ... @@ -48,3 +49,4 @@ app.use('/apikey/:apikey/matrix', routerMatrix);
48 49 app.use('/apikey/:apikey/services', routerServices);
49 50 app.use('/apikey/:apikey/products', routerProducts);
50 51 app.use('/apikey/:apikey/remote-products', routerRemoteProducts);
  52 +app.use('/apikey/:apikey/locations', routerLocations);
api-server/router-locations.js
... ... @@ -0,0 +1,106 @@
  1 +"use strict";
  2 +
  3 +const express = require('express');
  4 +const naturalSort = require('node-natural-sort');
  5 +const unique = require('array-unique');
  6 +
  7 +const config = require('../config');
  8 +const logger = require('../logger');
  9 +const matrix = require('../matrix');
  10 +
  11 +const router = express.Router();
  12 +module.exports = router;
  13 +
  14 +function pageIndex(req, res, next) {
  15 + res.json({
  16 + method: '/locations',
  17 + error: null,
  18 + result: config.locations
  19 + });
  20 +}
  21 +
  22 +function pageAdd(req, res, next) {
  23 + let locations = req.params.locations || req.query.locations
  24 +
  25 + if (!locations) {
  26 + res.json({
  27 + method: '/locations/add',
  28 + error: true,
  29 + error_msg: 'Usage: /locations/add/<NEW_LOCATION>'
  30 + });
  31 +
  32 + return;
  33 + }
  34 +
  35 + if (typeof locations === 'string') {
  36 + locations = locations.trim().split(/[\s,]+/);
  37 + }
  38 +
  39 + const locationsCount = locations.length;
  40 + for (let i=0; i<locationsCount; i++) {
  41 + const location = locations[i];
  42 + if (!location.trim()) {
  43 + continue;
  44 + }
  45 +
  46 + config.locations.push(location.trim().toUpperCase());
  47 + }
  48 +
  49 + config.locations.map(function(x) { return x.toUpperCase(); });
  50 + unique(config.locations);
  51 + config.locations.sort(naturalSort());
  52 + matrix.config_is_dirty = true;
  53 +
  54 + res.json({
  55 + method: '/locations/add',
  56 + error: null,
  57 + new_location: locations,
  58 + locations: config.locations
  59 + })
  60 +}
  61 +
  62 +function pageDel(req, res, next) {
  63 + let locations = req.params.locations || req.query.locations
  64 + if (!locations) {
  65 + res.json({
  66 + method: '/locations/del',
  67 + error: true,
  68 + error_msg: 'Usage: /locations/del/<LOCATION_TO_DELETE> or /locations/del?locations=<LOCATION_TO_DELETE>'
  69 + });
  70 +
  71 + return;
  72 + }
  73 +
  74 + if (typeof locations === 'string') {
  75 + locations = locations.trim().split(/[\s,]+/);
  76 + }
  77 +
  78 + config.locations.map(function(x) { return x.toUpperCase(); });
  79 + const locationsCount = locations.length;
  80 + for (let i=0; i<locationsCount; i++) {
  81 + const location = locations[i].toUpperCase();
  82 + const idx = config.locations.indexOf(location);
  83 + if (idx >= 0) {
  84 + matrix.config_is_dirty = true;
  85 + config.locations.splice(idx, 1)
  86 + }
  87 + }
  88 +
  89 + res.json({
  90 + method: '/locations/del',
  91 + error: null,
  92 + locations_to_delete: locations,
  93 + locations: config.locations
  94 + })
  95 +}
  96 +
  97 +router.get('/', pageIndex);
  98 +router.get('/add/:locations', pageAdd);
  99 +router.get('/add', pageAdd);
  100 +
  101 +router.get('/del/:locations', pageDel);
  102 +router.get('/delete/:locations', pageDel);
  103 +router.get('/remove/:locations', pageDel);
  104 +router.get('/del', pageDel);
  105 +router.get('/delete', pageDel);
  106 +router.get('/remove', pageDel);
1 1 {
2 2 "name": "komodo-sdk",
3   - "version": "1.35.0",
  3 + "version": "1.36.0",
4 4 "lockfileVersion": 1,
5 5 "requires": true,
6 6 "dependencies": {
1 1 {
2 2 "name": "komodo-sdk",
3   - "version": "1.35.0",
  3 + "version": "1.36.0",
4 4 "description": "SDK for Komodo",
5 5 "main": "index.js",
6 6 "scripts": {