Aggiorna public/index.html
This commit is contained in:
parent
2c2f125ef7
commit
030e9011d6
1 changed files with 72 additions and 10 deletions
|
|
@ -1,13 +1,75 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Gestione Foto</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script>
|
||||
window.addEventListener("load", (event) => {
|
||||
window.location.href = "pub/index.html";
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<h1>Gestione Foto</h1>
|
||||
|
||||
<button onclick="scan()">Scansiona</button>
|
||||
<button onclick="readDB()">Leggi DB</button>
|
||||
<button onclick="resetDB()">Reset DB</button>
|
||||
<button onclick="deleteAll()">Cancella tutto</button>
|
||||
|
||||
<pre id="out"></pre>
|
||||
|
||||
<script>
|
||||
let tok = null;
|
||||
let db = [];
|
||||
|
||||
async function start() {
|
||||
await login();
|
||||
await readDB();
|
||||
}
|
||||
|
||||
async function login() {
|
||||
const res = await fetch('/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email: 'fabio@gmail.com', password: 'master66' })
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
tok = data.token;
|
||||
}
|
||||
|
||||
async function readDB() {
|
||||
const res = await fetch('/photos', {
|
||||
headers: { 'Authorization': 'Bearer ' + tok }
|
||||
});
|
||||
|
||||
db = await res.json();
|
||||
document.getElementById('out').textContent = JSON.stringify(db, null, 2);
|
||||
}
|
||||
|
||||
async function scan() {
|
||||
await fetch('/scan', {
|
||||
headers: { 'Authorization': 'Bearer ' + tok }
|
||||
});
|
||||
await readDB();
|
||||
}
|
||||
|
||||
async function resetDB() {
|
||||
await fetch('/initDB', {
|
||||
headers: { 'Authorization': 'Bearer ' + tok }
|
||||
});
|
||||
await readDB();
|
||||
}
|
||||
|
||||
async function deleteAll() {
|
||||
for (const item of db) {
|
||||
await fetch('/photos/' + item.id, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': 'Bearer ' + tok }
|
||||
});
|
||||
}
|
||||
await readDB();
|
||||
}
|
||||
|
||||
start();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in a new issue