90 lines
1.9 KiB
HTML
90 lines
1.9 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Photo Manager</title>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="login-box" style="padding:20px;">
|
|
<h2>Login</h2>
|
|
<input id="email" type="text" placeholder="Email"><br><br>
|
|
<input id="password" type="password" placeholder="Password"><br><br>
|
|
<button onclick="login()">Accedi</button>
|
|
</div>
|
|
|
|
<div id="app" style="display:none;">
|
|
<h2>Gestione Foto</h2>
|
|
|
|
<button onclick="scan()">Scansiona Foto</button>
|
|
<button onclick="resetDB()">Reset DB</button>
|
|
<button onclick="readDB()">Leggi DB</button>
|
|
|
|
<pre id="out"></pre>
|
|
</div>
|
|
|
|
<script>
|
|
let BASE_URL = null;
|
|
let token = null;
|
|
let db = [];
|
|
|
|
async function loadConfig() {
|
|
const res = await fetch('/config');
|
|
const cfg = await res.json();
|
|
BASE_URL = cfg.baseUrl;
|
|
}
|
|
|
|
async function login() {
|
|
const email = document.getElementById("email").value;
|
|
const password = document.getElementById("password").value;
|
|
|
|
const res = await fetch(`${BASE_URL}/auth/login`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ email, password })
|
|
});
|
|
|
|
if (!res.ok) {
|
|
alert("Credenziali errate");
|
|
return;
|
|
}
|
|
|
|
const data = await res.json();
|
|
token = data.token;
|
|
|
|
document.getElementById("login-box").style.display = "none";
|
|
document.getElementById("app").style.display = "block";
|
|
|
|
await readDB();
|
|
}
|
|
|
|
async function readDB() {
|
|
const res = await fetch(`${BASE_URL}/photos`, {
|
|
headers: { "Authorization": "Bearer " + token }
|
|
});
|
|
|
|
db = await res.json();
|
|
document.getElementById("out").textContent = JSON.stringify(db, null, 2);
|
|
}
|
|
|
|
async function scan() {
|
|
await fetch(`${BASE_URL}/scan`, {
|
|
headers: { "Authorization": "Bearer " + token }
|
|
});
|
|
await readDB();
|
|
}
|
|
|
|
async function resetDB() {
|
|
await fetch(`${BASE_URL}/initDB`, {
|
|
headers: { "Authorization": "Bearer " + token }
|
|
});
|
|
await readDB();
|
|
}
|
|
|
|
window.onload = async () => {
|
|
await loadConfig();
|
|
};
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|