server-json/public/index.html
2026-02-20 18:57:21 +08:00

75 lines
1.4 KiB
HTML

<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>Gestione Foto</title>
</head>
<body>
<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>