v1.js 2.18 KB
Newer Older
Athanasios's avatar
Athanasios committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
55
56
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");
const bb = require("../src/boundingbox");

let router = express.Router();

const checks = [
  ...checkFactory.commonChecks(),
  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")
];

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);
    }

    getSceneHandler(req, res);

  });

module.exports = router;