Commit 9a2f0ed2 authored by Athanasios's avatar Athanasios
Browse files

Complete service

parent 7681b81e
......@@ -4,8 +4,9 @@ module.exports = {
FOLDER_INDEX: {
SCENELAYER: "3dSceneLayer.json.gz",
NODE: "3dNodeIndexDocument.json.gz",
SHARED: "sharedResource.json.gz",
FEATURES: "0.json.gz",
GEOMETRIES: "0.bin.gz",
SHARED: "sharedResource.json.gz"
ATTRIBUTES: "0.bin.gz"
}
};
\ No newline at end of file
......@@ -3,19 +3,43 @@ const getHandler = require('../src/handler');
let router = express.Router();
router.route("/").get((req, res) => {
router.route("/:nodeid/?").get((req, res) => {
res.sendStatus(404);
res.end();
let param = req.params.nodeid;
let handler = getHandler(param);
handler(req, res);
});
router.route("/:nodeid/:resource").get((req, res) => {
let param = req.params.resource;
let handler = getHandler(param);
handler(req, res);
});
router.route("[/]?*/:leaf").get((req, res) => {
router.route("/:nodeid/:resource/0").get((req, res) => {
let leaf = req.params.leaf;
let handler = getHandler(leaf);
let param = req.params.resource;
let handler = getHandler(param);
handler(req, res);
});
router.route("/:nodeid/:resource/:resourceid/0").get((req, res) => {
let param = req.params.resource;
let handler = getHandler(param);
handler(req, res);
});
router.route("*").get((req, res) => {
res.sendStatus(404);
res.end();
});
module.exports = router;
\ No newline at end of file
......@@ -22,7 +22,7 @@ router.route("/").get((req, res) => {
});
router.route("/:layer").get((req, res) => {
router.route("/:layer/layers/0").get((req, res) => {
let handler = getHandler("layer");
handler(req, res);
......
const config = require('../config');
const fs = require('fs');
const handle = (req, res) => {
let baseUrl = req.baseUrl.replace(/^\/?|\/?$/g, "");
let resourse = `${config.BASE_DIR}/${baseUrl}/${req.params.nodeid}/${req.params.resource}/${req.params.resourceid}/${config.FOLDER_INDEX.ATTRIBUTES}`;
if (!fs.existsSync(resourse)) throw new Error("not found");
res.set({
'Content-Disposition': 'attachment; filename=0.bin',
'Content-Type': 'application/octet-stream',
'Content-Encoding': 'gzip'
});
res.sendFile(resourse);
};
module.exports = handle;
\ No newline at end of file
......@@ -3,13 +3,9 @@ const fs = require('fs');
const handle = (req, res) => {
let resourse = `${config.BASE_DIR}${req.originalUrl}/${config.FOLDER_INDEX.NODE}`;
if (!fs.existsSync(resourse)) {
res.sendStatus(404);
res.end();
return;
}
let originalUrl = req.originalUrl.replace(/^\/?|\/?$/g, "");
let resourse = `${config.BASE_DIR}/${originalUrl}/${config.FOLDER_INDEX.NODE}`;
if (!fs.existsSync(resourse)) throw new Error("not found");
res.set({
'Content-Type': 'application/json',
......
......@@ -3,13 +3,9 @@ const fs = require('fs');
const handle = (req, res) => {
let resourse = `${config.BASE_DIR}${req.originalUrl}/${config.FOLDER_INDEX.FEATURES}`;
if (!fs.existsSync(resourse)) {
res.sendStatus(404);
res.end();
return;
}
let baseUrl = req.baseUrl.replace(/^\/?|\/?$/g, "");
let resourse = `${config.BASE_DIR}/${baseUrl}/${req.params.nodeid}/${req.params.resource}/${config.FOLDER_INDEX.FEATURES}`;
if (!fs.existsSync(resourse)) throw new Error("not found");
res.set({
'Content-Type': 'application/json',
......
......@@ -3,13 +3,9 @@ const fs = require('fs');
const handle = (req, res) => {
let resourse = `${config.BASE_DIR}${req.originalUrl}/${config.FOLDER_INDEX.GEOMETRIES}`;
if (!fs.existsSync(resourse)) {
res.sendStatus(404);
res.end();
return;
}
let baseUrl = req.baseUrl.replace(/^\/?|\/?$/g, "");
let resourse = `${config.BASE_DIR}/${baseUrl}/${req.params.nodeid}/${req.params.resource}/${config.FOLDER_INDEX.GEOMETRIES}`;
if (!fs.existsSync(resourse)) throw new Error("not found");
res.set({
'Content-Disposition': 'attachment; filename=0.bin',
......
const _default_ = require('./default');
const shared = require('./shared');
const features = require('./features');
const geometries = require('./geometries');
const shared = require('./shared');
const attributes = require('./attributes');
const layer = require('./layer');
const layers = require('./layers');
const handlers = {
_default_: _default_,
shared: shared,
features: features,
geometries: geometries,
shared: shared,
attributes: attributes,
layer: layer,
layers: layers
}
......
......@@ -3,13 +3,8 @@ const fs = require('fs');
const handle = (req, res) => {
let resourse = `${config.BASE_DIR}/scenelayers/${req.params.layer}/${config.FOLDER_INDEX.SCENELAYER}`;
if (!fs.existsSync(resourse)) {
res.sendStatus(404);
res.end();
return;
}
let resourse = `${config.BASE_DIR}/scenelayers/${req.params.layer}/layers/0/${config.FOLDER_INDEX.SCENELAYER}`;
if (!fs.existsSync(resourse)) throw new Error("not found");
res.set({
'Content-Type': 'application/json',
......
......@@ -3,13 +3,9 @@ const fs = require('fs');
const handle = (req, res) => {
let resourse = `${config.BASE_DIR}${req.originalUrl}/${config.FOLDER_INDEX.SHARED}`;
if (!fs.existsSync(resourse)) {
res.sendStatus(404);
res.end();
return;
}
let baseUrl = req.baseUrl.replace(/^\/?|\/?$/g, "");
let resourse = `${config.BASE_DIR}/${baseUrl}/${req.params.nodeid}/${req.params.resource}/${config.FOLDER_INDEX.SHARED}`;
if (!fs.existsSync(resourse)) throw new Error("not found");
res.set({
'Content-Type': 'application/json',
......
......@@ -7,4 +7,4 @@ style.
ul
each layer in layers
li
a(href=`${layer}`)= layer
\ No newline at end of file
a(href=`${layer}/layers/0`)= layer
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment