diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index dc735319112998f1dba38dd91b4128abd1b80851..feb2a8d79b33087920e08f8bfa23028259900779 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 a34a709297bc2ce96ab9e5d2cd9a929fd5b45791..0d5b58d1f828365ff6395a2f8b7c97786dc09962 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 d5fda51448f5fc69035a2e073ed48b56a9f4d782..2736be6a5fd93d0ceddfceb4b263827791ebd648 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