From d7987bcd73bfa8755ada6b5b985d9a3d6ee47022 Mon Sep 17 00:00:00 2001 From: Sami Spets <savasp@utu.fi> Date: Thu, 14 Nov 2019 07:55:17 +0200 Subject: [PATCH] Changes in the GET /stream/config route --- web-service/server/src/index.js | 51 +++++++++++++++------- web-service/server/src/public/js/bundle.js | 3 +- web-service/server/src/public/js/index.js | 3 +- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index 9d0457082..dc7353191 100644 --- a/web-service/server/src/index.js +++ b/web-service/server/src/index.js @@ -231,34 +231,55 @@ 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 = req.query.uri; + let uri = encodeURIComponent(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", peer) - } - return res.status(200).json(response); + // 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); + let depth = splittedUri.split("%2F"); + 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] + } + helpObj = { + [depth[i]]: depth[i+1] + } + + } + } + + - // const baseURI = "ftl%3A%2F%2Futu.fi%2Fstream%2Fconfigurations" - // const uri = wholeURI.substring(47); - // let depth = uri.split("%2F"); - // console.log("DEPTH", depth) - // let queryURI = baseURI + '%2F' + depth[0] - // console.log("QUERYURI", queryURI) // let response = await Configs.find({ URI : queryURI}); // const objects = response[0].data diff --git a/web-service/server/src/public/js/bundle.js b/web-service/server/src/public/js/bundle.js index 3cc86614e..a34a70929 100644 --- a/web-service/server/src/public/js/bundle.js +++ b/web-service/server/src/public/js/bundle.js @@ -4739,9 +4739,10 @@ updateConfigs = async () => { * current_data.configURI is a dropdown menu */ + current_data.configs = 'ftl://utu.fi/stream/configurations/calibrations/default' loadConfigs = async () => { console.log("URI", current_data.uri) - const uri = encodeURIComponent(current_data.uri); + const uri = encodeURIComponent(current_data.configs); const rawResp = await fetch(`http://localhost:8080/stream/config?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 05bf292ff..d5fda5144 100644 --- a/web-service/server/src/public/js/index.js +++ b/web-service/server/src/public/js/index.js @@ -219,9 +219,10 @@ updateConfigs = async () => { * current_data.configURI is a dropdown menu */ + current_data.configs = 'ftl://utu.fi/stream/configurations/calibrations/default' loadConfigs = async () => { console.log("URI", current_data.uri) - const uri = encodeURIComponent(current_data.uri); + const uri = encodeURIComponent(current_data.configs); const rawResp = await fetch(`http://localhost:8080/stream/config?uri=${uri}`) const content = await rawResp.json(); console.log(content) -- GitLab