Skip to content
Snippets Groups Projects
Commit 26e6f2bf authored by Sami Spets's avatar Sami Spets
Browse files

Added comments

parent f6a0b74c
Branches
Tags
No related merge requests found
Pipeline #14854 passed
This diff is collapsed.
......@@ -35,7 +35,6 @@ body {
display: inline-block;
}
.div {
vertical-align: center;
text-align: center
img {
padding: 25px;
}
\ No newline at end of file
<!DOCTYPE html>
<html onload="checkIfLoggedIn()">
<html>
<head>
<title>FTL web-service</title>
<link rel="stylesheet" href="./css/index.css">
</head>
<body onload="checkIfLoggedIn()">
<div id="container" style="padding-top: 150px; text-align: center">
......@@ -27,4 +28,5 @@
</div>
</body>
<script src='./js/index.js'></script>
<script src='./js/lib/libde265.min.js'></script>
</html>
\ No newline at end of file
......@@ -2,20 +2,65 @@
const checkIfLoggedIn = async () => {
const token = window.localStorage.getItem('token')
if(!token){
console.log("FAIL")
return ""
console.log("You need to login")
//User has a token saved in the browser
}else{
//validate that token
const response = await fetch('http://localhost:8080/auth/validation', {
method: 'POST',
headers: {'Authorization': token}
})
console.log(response)
//Token is valid
if(response.status === 200){
console.log("SUCCESS")
/*
Most likely it will render a new HTML file
*/
document.getElementById('container').innerHTML = "<p>Salainen sivu</p>"
}
}
}
//Redirects the user to google authentication
const handleLogin = () => {
window.location.href="/google";
}
/**
* Returns a list of available streams
*/
const getAvailableStreams = async () => {
const streamsInJson = await fetch('http://localhost:8080/streams');
const streams = await streamsInJson.json();
return streams;
}
//Creates thumbnail (image) for all available streams and adds them to div class='container'
const renderThumbnails = async () => {
// const thumbnails = getAvailableStreams();
// console.log('THUMBNAILS', thumbnails)
const containerDiv = document.getElementById('container')
containerDiv.innerHTML = '';
console.log(containerDiv)
for(var i=0; i<2; i++){
// const encodedURI = encodeURIComponent(thumbnails[i])
// try{
// const someData = await fetch(`http://localhost:8080/stream/rgb?uri=${encodedURI}`)
// console.log('SOME DATA', someData)
// if(!someData.ok){
// throw new Error('Image not found')
// }
// const myBlob = await someData.blob();
// const objectURL = URL.createObjectURL(myBlob);
// containerDiv.innerHTML += `<img src='${objectURL}' alt="Hups" width='500px'></img>`
containerDiv.innerHTML += `<img src='https://via.placeholder.com/350x150' alt="Hups" width='350px'></img>`
// }catch(err){
// console.log("Couldn't create thumbnail");
// return
// }
}
}
\ No newline at end of file
......@@ -116,6 +116,7 @@ RGBDStream.prototype.subscribe = function() {
}
RGBDStream.prototype.pushFrames = function(latency, spacket, packet) {
//Checks that the type is jpg
if (packet[0] === 0){
if (spacket[1] & 0x1) this.depth = packet[4];
else this.rgb = packet[4];
......@@ -143,12 +144,10 @@ app.get('/', (req, res) => {
});
app.post('/auth/validation', (req, res) => {
const token = req.headers.authorization
const parts = token.split(" ")
const token = req.headers.authorization.split(" ")
const decoded = jwt.verify(token[1], keys.jwt.secret)
const decoded = jwt.verify(parts[1], keys.jwt.secret)
console.log(decoded)
return res.status(200).json("Piipppiip")
return res.status(200)
})
// app.get('/login/google', (req, res) => {
// })
......@@ -158,6 +157,12 @@ app.get('/streams', (req, res) => {
res.json(Object.keys(uri_data));
});
/**
* A list that has Object.keys(uri_data) values and also the image that is
* binded to that
* Joku lista missä on Object.keys(uri_datan) arvot ja niihin bindattu
* se
*/
app.get('/stream/rgb', (req, res) => {
let uri = req.query.uri;
if (uri_data.hasOwnProperty(uri)) {
......@@ -186,9 +191,9 @@ app.get('/google', passport.authenticate('google', {
scope: ['profile']
}))
/*
/**
* Google authentication API callback route.
* Sets the JWT to clients browser and redirects the user back to front page (now has thumbnails).
* Sets the JWT to clients browser and redirects the user back to front page.
*/
app.get('/auth/google/redirect', passport.authenticate('google'), (req, res) => {
console.log(req.user)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment