v1.js 3.34 KB
Newer Older
Athanasios's avatar
Athanasios committed
1
2
3
4
5
6
const express = require("express");
const { check, validationResult, oneOf } = require("express-validator")
const { toLower } = require("../src/customSanitizers");
const { errorHandler } = require("../src/errorHandler");
const checkFactory = require("../src/validationCheckFactory");
const { getSceneHandler } = require("../src/getSceneHandler");
Athanasios's avatar
Athanasios committed
7
const { getCapabilitiesHandler } = require("../src/getCapabilitiesHandler");
Athanasios's avatar
Athanasios committed
8
const bb = require("../src/boundingbox");
Athanasios's avatar
Athanasios committed
9
const redirectTo = require("../src/redirectTo");
Athanasios's avatar
Athanasios committed
10
11
12
13
14

let router = express.Router();

const checks = [
  ...checkFactory.commonChecks(),
Athanasios's avatar
Athanasios committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  check("request")
    .exists().withMessage("MissingParameterValue")
    .customSanitizer(toLower)
    .isIn(["getscene", "getcapabilities"]).withMessage("InvalidParameterValue")
];

router.route("/").get(checks, (req, res) => {

  const errors = validationResult(req);
  if (!errors.isEmpty()) {
    let exception = errorHandler(errors);
    res.set("Content-Type", "application/xml");
    return res.status(400).send(exception);
  }

  redirectTo(req.query.request, req, res);

});

const capabilitiesChecks = [
  check("request")
    .exists().withMessage("MissingParameterValue")
    .customSanitizer(toLower)
    .equals("getcapabilities").withMessage("InvalidParameterValue")
];

router.route("/capabilities").get(capabilitiesChecks, (req, res) => {

  const errors = validationResult(req);
  if (!errors.isEmpty()) {
    let exception = errorHandler(errors);
    res.set("Content-Type", "application/xml");
    return res.status(400).send(exception);
  }

  getCapabilitiesHandler(req, res);

});

const sceneChecks = [
Athanasios's avatar
Athanasios committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  check("request")
    .exists().withMessage("MissingParameterValue")
    .customSanitizer(toLower)
    .equals("getscene").withMessage("InvalidParameterValue"),
  check("boundingbox")
    .exists().withMessage("MissingParameterValue")
    .matches(/^((\-?\d+(\.\d+)?),){3}(\-?\d+(\.\d+)?)$/).withMessage("InvalidParameterValue")
    .custom(value => bb.isValid(value)).withMessage("InvalidParameterValue"),
  check("cullingvolume")
    .exists().withMessage("MissingParameterValue")
    .matches(/^((\-?\d+(\.\d+)?),){23}(\-?\d+(\.\d+)?)$/).withMessage("InvalidParameterValue"),
  check("camera")
    .exists().withMessage("MissingParameterValue")
    .matches(/^((\-?\d+(\.\d+)?),){5}(\-?\d+(\.\d+)?)$/).withMessage("InvalidParameterValue"),
  check("frustum")
    .exists().withMessage("MissingParameterValue")
    .matches(/^((\-?\d+(\.\d+)?),){2}(\-?\d+(\.\d+)?)$/).withMessage("InvalidParameterValue"),
  check("drawingbuffer")
    .exists().withMessage("MissingParameterValue")
    .matches(/^((\-?\d+(\.\d+)?),){1}(\-?\d+(\.\d+)?)$/).withMessage("InvalidParameterValue"),
  check("time")
    .exists().withMessage("MissingParameterValue")
    .matches(/\d+/).withMessage("InvalidParameterValue"),
  check("intersect")
    .exists().withMessage("MissingParameterValue")
    .customSanitizer(toLower)
    .isIn(["true", "false"]).withMessage("InvalidParameterValue")
];

Athanasios's avatar
Athanasios committed
84
router.route("/scene").get(sceneChecks, (req, res) => {
Athanasios's avatar
Athanasios committed
85

Athanasios's avatar
Athanasios committed
86
87
88
89
90
91
  const errors = validationResult(req);
  if (!errors.isEmpty()) {
    let exception = errorHandler(errors);
    res.set("Content-Type", "application/xml");
    return res.status(400).send(exception);
  }
Athanasios's avatar
Athanasios committed
92

Athanasios's avatar
Athanasios committed
93
  getSceneHandler(req, res);
Athanasios's avatar
Athanasios committed
94

Athanasios's avatar
Athanasios committed
95
});
Athanasios's avatar
Athanasios committed
96
97

module.exports = router;