From 68955c19963e7a810e1f7253a1a41f527fdd95de Mon Sep 17 00:00:00 2001 From: Sami Spets <savasp@utu.fi> Date: Thu, 14 Nov 2019 10:03:24 +0200 Subject: [PATCH] Debugging stream/config route --- web-service/server/src/index.js | 76 ++++++++++++---------- web-service/server/src/public/js/bundle.js | 8 +-- web-service/server/src/public/js/index.js | 8 +-- 3 files changed, 51 insertions(+), 41 deletions(-) diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index dc7353191..feb2a8d79 100644 --- a/web-service/server/src/index.js +++ b/web-service/server/src/index.js @@ -231,52 +231,62 @@ app.post('/stream/config', async (req, res) => { app.get('/stream/config', async(req, res) => { //example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi/stream/configurations/calibrations/default/board_size - let uri = encodeURIComponent(req.query.uri); + const settings = encodeURIComponent(req.query.settings); + const uri = req.query.uri; + // let response = await Configs.find({URI: uri}); // if(dbData[0].data){ // return res.status(200).json(dbData[0]); // }else{ - // let peer1 = uri_data[] - // console.log("CONFIGURATION URI", uri) - // let peer = uri_data[uri].peer - // let response; - // if(peer){ - // response = peer.rpc("get_cfg", uri) - // console.log("PEER", response) - // if(response){ - // return res.status(200).json(response); - // } // } // } - - //Pitää parsii uri ja tehä siitä JSON-objekti const baseURI = "ftl%3A%2F%2Futu.fi%2Fstream%2Fconfigurations" - splittedUri = uri.substring(47); + splittedUri = settings.substring(47); let depth = splittedUri.split("%2F"); - console.log("DEPTH", depth) + if(depth[depth.length-1].length === 0){ + depth.pop(); + } + // console.log("DEPTH", depth) let queryURI = baseURI + '%2F' + depth[0] - console.log("QUERYURI", queryURI) - - if(depth.length === 0){ - - }else if(depth.length === 1){ - - }else{ - let lastObject; - let helpObj; - let helper; - for(let i=depth.length-2; i=>0; i--){ - helper = { - [depth[i]]: depth[i+1] + // console.log("QUERYURI", queryURI) + + var configURI; + switch(depth.length){ + case 0: + return res.status(502) + case 1: + configURI = JSON.stringify(depth[0]); + break; + case 2: + const obj = { [depth[depth.length-2]]: depth[depth.length-1] } + configURI = JSON.stringify(obj); + break; + default: + let lastObject = { [depth[depth.length-2]]: depth[depth.length-1] } + let helper = { [depth[depth.length-3]]: lastObject } + if(depth.length<4){ + configURI = JSON.stringify(helper); } - helpObj = { - [depth[i]]: depth[i+1] + for(let i=depth.length-4; i>=0; i--){ + if(i<=0){ + configURI = JSON.stringify(helper) + } + lastObject = { [depth[i-1]]: helper } + helper = lastObject } - - } } - + return res.status(200).json(configURI); + let peer = uri_data[uri].peer + let response; + if(peer){ + console.log("get_cfg URI", configURI) + response = peer.rpc("get_cfg", cb(), configURI) + console.log("RESPONSE", response) + if(response){ + return res.status(200).json(response); + } + } diff --git a/web-service/server/src/public/js/bundle.js b/web-service/server/src/public/js/bundle.js index a34a70929..0d5b58d1f 100644 --- a/web-service/server/src/public/js/bundle.js +++ b/web-service/server/src/public/js/bundle.js @@ -4739,11 +4739,11 @@ updateConfigs = async () => { * current_data.configURI is a dropdown menu */ - current_data.configs = 'ftl://utu.fi/stream/configurations/calibrations/default' +current_data.configs = 'ftl://utu.fi/stream/configurations/calibrations/default/board_size' loadConfigs = async () => { - console.log("URI", current_data.uri) - const uri = encodeURIComponent(current_data.configs); - const rawResp = await fetch(`http://localhost:8080/stream/config?uri=${uri}`) + const configURI = encodeURIComponent(current_data.configs); + const uri = encodeURIComponent(current_data.uri) + const rawResp = await fetch(`http://localhost:8080/stream/config?settings=${configURI}&uri=${uri}`) const content = await rawResp.json(); console.log(content) } diff --git a/web-service/server/src/public/js/index.js b/web-service/server/src/public/js/index.js index d5fda5144..2736be6a5 100644 --- a/web-service/server/src/public/js/index.js +++ b/web-service/server/src/public/js/index.js @@ -219,11 +219,11 @@ updateConfigs = async () => { * current_data.configURI is a dropdown menu */ - current_data.configs = 'ftl://utu.fi/stream/configurations/calibrations/default' +current_data.configs = 'ftl://utu.fi/stream/configurations/calibrations/default/board_size' loadConfigs = async () => { - console.log("URI", current_data.uri) - const uri = encodeURIComponent(current_data.configs); - const rawResp = await fetch(`http://localhost:8080/stream/config?uri=${uri}`) + const configURI = encodeURIComponent(current_data.configs); + const uri = encodeURIComponent(current_data.uri) + const rawResp = await fetch(`http://localhost:8080/stream/config?settings=${configURI}&uri=${uri}`) const content = await rawResp.json(); console.log(content) } \ No newline at end of file -- GitLab