Aggiorna public/index.html
This commit is contained in:
parent
8ce422c5a7
commit
90619f2d99
1 changed files with 14 additions and 7 deletions
|
|
@ -16,43 +16,49 @@
|
|||
<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('/auth/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('/photos', {
|
||||
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('/scan', {
|
||||
await fetch(`${BASE_URL}/scan`, {
|
||||
headers: { 'Authorization': 'Bearer ' + tok }
|
||||
});
|
||||
await readDB();
|
||||
}
|
||||
|
||||
async function resetDB() {
|
||||
await fetch('/initDB', {
|
||||
await fetch(`${BASE_URL}/initDB`, {
|
||||
headers: { 'Authorization': 'Bearer ' + tok }
|
||||
});
|
||||
await readDB();
|
||||
|
|
@ -60,7 +66,7 @@ async function resetDB() {
|
|||
|
||||
async function deleteAll() {
|
||||
for (const item of db) {
|
||||
await fetch('/photos/' + item.id, {
|
||||
await fetch(`${BASE_URL}/photos/${item.id}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': 'Bearer ' + tok }
|
||||
});
|
||||
|
|
@ -71,5 +77,6 @@ async function deleteAll() {
|
|||
start();
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in a new issue