photo_server_json_flutter/public/index.html.old
2026-02-22 22:25:00 +01:00

82 lines
1.6 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 BASE_URL = null;
let tok = null;
let db = [];
async function loadConfig() {
const res = await fetch('/config');
const cfg = await res.json();
BASE_URL = cfg.baseUrl;
}
async function start() {
await loadConfig();
await login();
await readDB();
}
async function login() {
const res = await fetch(`${BASE_URL}/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(`${BASE_URL}/photos`, {
headers: { 'Authorization': 'Bearer ' + tok }
});
db = await res.json();
document.getElementById('out').textContent = JSON.stringify(db, null, 2);
}
async function scan() {
await fetch(`${BASE_URL}/scan`, {
headers: { 'Authorization': 'Bearer ' + tok }
});
await readDB();
}
async function resetDB() {
await fetch(`${BASE_URL}/initDB`, {
headers: { 'Authorization': 'Bearer ' + tok }
});
await readDB();
}
async function deleteAll() {
for (const item of db) {
await fetch(`${BASE_URL}/photos/${item.id}`, {
method: 'DELETE',
headers: { 'Authorization': 'Bearer ' + tok }
});
}
await readDB();
}
start();
</script>
</body>
</html>