143 lines
No EOL
3.2 KiB
HTML
143 lines
No EOL
3.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Page Title</title>
|
|
</head>
|
|
<body>
|
|
|
|
<h1>This is a Heading</h1>
|
|
<p>This is a paragraph.</p>
|
|
<button type="button" onclick="scan()">Scan</button>
|
|
<button type="button" onclick="read()">Read</button>
|
|
<button type="button" onclick="writ()">write</button>
|
|
<button type="button" onclick="azz()">Azz</button>
|
|
<button type="button" onclick="log()">Log DB</button>
|
|
<button type="button" onclick="myReset()">Reset</button>
|
|
<script>
|
|
|
|
var tok;
|
|
var db;
|
|
function read() {
|
|
myGet();
|
|
}
|
|
|
|
function writ() {
|
|
myPost({'email':'fabio@gmail.com', 'password':'master66'})
|
|
}
|
|
|
|
function scan() {
|
|
fetch('http://192.168.1.3:7771/scan', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
}
|
|
|
|
function log() {
|
|
lineGet("log")
|
|
console.log("log inviato");
|
|
}
|
|
|
|
function myReset() {
|
|
lineGet("initDB")
|
|
console.log("reset inviato");
|
|
}
|
|
|
|
async function azz(){
|
|
await azz1();
|
|
console.log("azzerato");
|
|
}
|
|
|
|
async function azz1() {
|
|
for(let v =0; v < db.length; v++){
|
|
//console.log(db[v].id);
|
|
myDel(db[v].id);
|
|
if (v==db.length-1){
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
function toc() {
|
|
fetch('http://192.168.1.3:7771/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({'email':'fabio@gmail.com', 'password':'master66'}),
|
|
})
|
|
.then(response => response.json())
|
|
.then(user1 => {
|
|
tok = user1.token;
|
|
console.log(tok);
|
|
})
|
|
}
|
|
|
|
function myPost(json) {
|
|
const myHeaders = new Headers();
|
|
myHeaders.append('Authorization', 'Bearer ' + tok);
|
|
myHeaders.append('Content-Type', 'application/json');
|
|
//console.log(myHeaders.get("Content-Type"));
|
|
//console.log(myHeaders.get("Authorization"));
|
|
fetch('http://192.168.1.3:7771/photos', {
|
|
method: 'POST',
|
|
headers: myHeaders,
|
|
body: JSON.stringify(json),
|
|
})
|
|
.then(response => response.json())
|
|
.then(user => console.log(user));
|
|
}
|
|
|
|
function myGet() {
|
|
const myHeaders = new Headers();
|
|
myHeaders.append('Authorization', 'Bearer ' + tok);
|
|
fetch('http://192.168.1.3:7771/photos', {
|
|
method: 'GET',
|
|
headers: myHeaders,
|
|
})
|
|
.then(response => response.json())
|
|
.then(user => {
|
|
console.log(user);
|
|
db=user;
|
|
});
|
|
}
|
|
|
|
function myDel(id) {
|
|
|
|
const myHeaders = new Headers();
|
|
myHeaders.append('Authorization', 'Bearer ' + tok);
|
|
myHeaders.append('Content-Type', 'application/json');
|
|
//console.log(myHeaders.get("Content-Type"));
|
|
//console.log(myHeaders.get("Authorization"));
|
|
fetch('http://192.168.1.3:7771/photos/'+id, {
|
|
method: 'DELETE',
|
|
headers: myHeaders,
|
|
})
|
|
.then(response => response.json())
|
|
.then(user => console.log(""));
|
|
|
|
}
|
|
|
|
function lineGet(dir) {
|
|
const myHeaders = new Headers();
|
|
myHeaders.append('Authorization', 'Bearer ' + tok);
|
|
fetch('http://192.168.1.3:7771/'+dir, {
|
|
method: 'GET',
|
|
headers: myHeaders,
|
|
})
|
|
.then(response => response.json())
|
|
.then(user => {
|
|
console.log(user);
|
|
});
|
|
}
|
|
|
|
|
|
toc();
|
|
myGet();
|
|
|
|
|
|
|
|
</script>
|
|
</body>
|
|
</html> |