diff --git a/web-service/server/public/index.html b/web-service/server/public/index.html index e827d537000bb5178e1b02012ee048edf618b9be..9a99592171f99413a7020bb002123421540ecc3b 100644 --- a/web-service/server/public/index.html +++ b/web-service/server/public/index.html @@ -5,27 +5,7 @@ <link rel="stylesheet" href="./css/index.css"> </head> <body onload="checkIfLoggedIn()"> - <div id="container" style="padding-top: 150px; text-align: center"> - <div id='Login'> - <h2>Welcome to Future Technology Lab</h2> - <h3>Please login!</h3> - <a className="button" onClick="handleLogin()"> - <div> - <span class="svgIcon t-popup-svg"> - <svg class="svgIcon-use" width="25" height="37" viewBox="0 0 25 25"> - <g fill="none" fill-rule="evenodd"> - <path d="M20.66 12.693c0-.603-.054-1.182-.155-1.738H12.5v3.287h4.575a3.91 3.91 0 0 1-1.697 2.566v2.133h2.747c1.608-1.48 2.535-3.65 2.535-6.24z" fill="#4285F4"/> - <path d="M12.5 21c2.295 0 4.22-.76 5.625-2.06l-2.747-2.132c-.76.51-1.734.81-2.878.81-2.214 0-4.088-1.494-4.756-3.503h-2.84v2.202A8.498 8.498 0 0 0 12.5 21z" fill="#34A853"/> - <path d="M7.744 14.115c-.17-.51-.267-1.055-.267-1.615s.097-1.105.267-1.615V8.683h-2.84A8.488 8.488 0 0 0 4 12.5c0 1.372.328 2.67.904 3.817l2.84-2.202z" fill="#FBBC05"/> - <path d="M12.5 7.38c1.248 0 2.368.43 3.25 1.272l2.437-2.438C16.715 4.842 14.79 4 12.5 4a8.497 8.497 0 0 0-7.596 4.683l2.84 2.202c.668-2.01 2.542-3.504 4.756-3.504z" fill="#EA4335"/> - </g> - </svg> - </span> - <span class="button-label">Sign in with Google</span> - </div> - </a> - </div> - </div> + <div id="container" style="padding-top: 150px; text-align: center"></div> </body> <script src='./js/index.js'></script> <script src='./js/lib/libde265.min.js'></script> diff --git a/web-service/server/public/js/index.js b/web-service/server/public/js/index.js index 209b38ef4ddfbc767968c5beffff4b5ccfec9763..f0d647bef34fcd5dfe0c95d98d572f13e27405f4 100644 --- a/web-service/server/public/js/index.js +++ b/web-service/server/public/js/index.js @@ -4,7 +4,26 @@ const checkIfLoggedIn = async () => { if(!token){ console.log("You need to login") const containerDiv = document.getElementById('container'); - containerDiv = login; + containerDiv.innerHTML = + `<div id='Login'> + <h2>Welcome to Future Technology Lab</h2> + <h3>Please login!</h3> + <a className="button" onClick="handleLogin()"> + <div> + <span class="svgIcon t-popup-svg"> + <svg class="svgIcon-use" width="25" height="37" viewBox="0 0 25 25"> + <g fill="none" fill-rule="evenodd"> + <path d="M20.66 12.693c0-.603-.054-1.182-.155-1.738H12.5v3.287h4.575a3.91 3.91 0 0 1-1.697 2.566v2.133h2.747c1.608-1.48 2.535-3.65 2.535-6.24z" fill="#4285F4"/> + <path d="M12.5 21c2.295 0 4.22-.76 5.625-2.06l-2.747-2.132c-.76.51-1.734.81-2.878.81-2.214 0-4.088-1.494-4.756-3.503h-2.84v2.202A8.498 8.498 0 0 0 12.5 21z" fill="#34A853"/> + <path d="M7.744 14.115c-.17-.51-.267-1.055-.267-1.615s.097-1.105.267-1.615V8.683h-2.84A8.488 8.488 0 0 0 4 12.5c0 1.372.328 2.67.904 3.817l2.84-2.202z" fill="#FBBC05"/> + <path d="M12.5 7.38c1.248 0 2.368.43 3.25 1.272l2.437-2.438C16.715 4.842 14.79 4 12.5 4a8.497 8.497 0 0 0-7.596 4.683l2.84 2.202c.668-2.01 2.542-3.504 4.756-3.504z" fill="#EA4335"/> + </g> + </svg> + </span> + <span class="button-label">Sign in with Google</span> + </div> + </a> + </div>` //User has a token saved in the browser }else{ diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index 1d6c06be0e02544b7325d87a689ebb42f832db98..27f00d76272c0fb8100759080354a7fb8020b704 100644 --- a/web-service/server/src/index.js +++ b/web-service/server/src/index.js @@ -10,6 +10,7 @@ const mongoose = require('mongoose') const config = require('./utils/config') const User = require('./models/users') const Config = require('./models/configs') +const Disparity = require('./models/disparity') const bodyParser = require('body-parser') // ---- INDEXES ---------------------------------------------------------------- @@ -159,11 +160,14 @@ app.get('/', (req, res) => { app.post('/auth/validation', async (req, res) => { const token = req.headers.authorization.split(" ") const decoded = jwt.verify(token[1], keys.jwt.secret) + console.log('DECODED', decoded) try{ - const data = await User.find({decoded}) - if(data){ - console.log(data) + const data = await User.find({ googleID: decoded }) + console.log('DATA', data) + if(data.length !== 0){ return res.status(200).json("success") + }else { + return res.status(403) } }catch(err){ console.log('ERROR ERROR') @@ -205,7 +209,6 @@ app.get('/stream/depth', (req, res) => { app.post('/stream/config', async (req, res) => { const {board_size, square_size, frame_delay, num_frames, name} = req.body - const savedConfigs = new Config({ board_size, square_size, @@ -213,6 +216,7 @@ app.post('/stream/config', async (req, res) => { num_frames, name }); + try{ await savedConfigs.save(); return res.status(200).json('Your configurations were saved successfully') @@ -225,9 +229,24 @@ app.post('/stream/config', async (req, res) => { app.get('/stream/config', async(req, res) => { //example of uri ftl.utu.fi/stream/config?uri=ftl://utu.fi/stream/calibrations/ //example of uri /stream/config?uri=ftl://utu.fi/stream/calibrations/board_size/value=1 - const wholeURI = req.query.uri - const uri = wholeURI.substring(13) + const wholeURI = req.query.urinote + const uri = wholeURI.substring(20) const depth = uri.split("/"); + if(depth.length === 1){ + let data + switch(depth[0]){ + case 'calibrations': + data = await Config.find({}); + return res.status(200).json(data); + case 'disparity': + data = await Disparity.find({}); + return res.status(200).json(data); + default: + return res.status(500).json('Error'); + } + }else if(depth.length === 2){ + } + console.log(wholeURI) console.log(uri) console.log(depth) @@ -437,6 +456,16 @@ app.ws('/', (ws, req) => { } }); + /** + * Gets config values for + */ + //p.bind("get_cfg", ) + + /** + * gets list of configurations from the C++ + */ + //p.bind("update_cfg", ) + // Register a new stream p.bind("add_stream", (uri) => { console.log("Adding stream: ", uri); diff --git a/web-service/server/src/models/disparity.js b/web-service/server/src/models/disparity.js new file mode 100644 index 0000000000000000000000000000000000000000..03795f815cead0e1663a8595b0656df6071b63ef --- /dev/null +++ b/web-service/server/src/models/disparity.js @@ -0,0 +1,23 @@ +const mongoose = require('mongoose') + +const disparitySchema = mongoose.Schema({ + name: {type: String, default: null}, + algorithm: {type: String, default: 'libsgm'}, + use_cuda: {type: Boolean, default: true}, + minimum: {type: Number, default: 0}, + maximum: {type: Number, default: 256}, + tau: {type: Number, default: 0.0}, + gamma: {type: Number, default: 0.0}, + window_size: {type: Number, default: 5}, + sigma: {type: Number, default: 1.5}, + lambda: {type: Number, default: 8000.0} +}) + +disparitySchema.set('toJSON', { + transform: (document, returnedObject) => { + delete returnedObject._id + delete returnedObject.__v + } + }) + +module.exports = mongoose.model('disparityConfig', disparitySchema) \ No newline at end of file