Aggiorna public/index.html

This commit is contained in:
Fabio 2026-02-20 18:57:21 +08:00
parent 2c2f125ef7
commit 030e9011d6

View file

@ -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>
<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>