From 12e16196591d927a0db84ae58d462088ffeb9fd0 Mon Sep 17 00:00:00 2001
From: Sami Spets <savasp@utu.fi>
Date: Mon, 18 Nov 2019 09:12:39 +0200
Subject: [PATCH] Refactoring done

---
 web-service/server/src/index.js | 66 +++++++--------------------------
 1 file changed, 13 insertions(+), 53 deletions(-)

diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js
index b118ab0db..fb7f93038 100644
--- a/web-service/server/src/index.js
+++ b/web-service/server/src/index.js
@@ -230,65 +230,25 @@ 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
-	const settings = encodeURIComponent(req.query.settings);
-	const setting = req.query.settings;
+	//example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi#reconstruction_snap10/merge
+	const settings = req.query.settings;
 	const uri = req.query.uri;
 
-	// let response = await Configs.find({URI: uri});
+	// //Check if DB has data
+	// let response = await Configs.find({URI: settings});
 	// if(dbData[0].data){
 	// 	return res.status(200).json(dbData[0]);
 	// }else{
-		// }
-	// }
-
-	const baseURI = "ftl%3A%2F%2Futu.fi%2Fstream%2Fconfigurations"
-	splittedUri = settings.substring(47);
-	let depth = splittedUri.split("%2F");
-	if(depth[depth.length-1].length === 0){
-		depth.pop();
-	}
-	// console.log("DEPTH", depth)
-	let queryURI = baseURI + '%2F' + depth[0]
-	// 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);
-	// 		}
-	// 		for(let i=depth.length-4; i>=0; i--){
-	// 			if(i<=0){
-	// 				configURI = JSON.stringify(helper) 
-	// 			}
-	// 			lastObject = { [depth[i-1]]: helper }
-	// 			helper = lastObject
-	// 		}
+		let peer = uri_data[uri].peer
+		if(peer){
+			console.log("get_cfg", settings)
+			peer.rpc("get_cfg", (response) => {
+				if(response){
+					return res.status(200).json(response);
+				}
+			}, settings)
+		}
 	// }
-	// return res.status(200).json(configURI);
-	let peer = uri_data[uri].peer
-	if(peer){
-		console.log("get_cfg", setting)
-		peer.rpc("get_cfg", (response) => {
-			console.log(response)
-			if(response){
-				return res.status(200).json(response);
-			}
-		}, setting)
-		
-	}
 })
 
 
-- 
GitLab