2
This commit is contained in:
parent
35cf1e641c
commit
2901cbd381
4 changed files with 12 additions and 88 deletions
|
|
@ -256,7 +256,7 @@ async function scanDir(dirAbs, results = []) {
|
|||
|
||||
const ext = path.extname(dirent.name).toLowerCase();
|
||||
if (!SUPPORTED_EXTS.has(ext)) continue;
|
||||
|
||||
console.log("Elaboro:", absPath);
|
||||
const isVideo = ['.mp4', '.mov', '.m4v'].includes(ext);
|
||||
|
||||
const relFile = toPosix(path.relative(WEB_ROOT, absPath));
|
||||
|
|
@ -368,7 +368,7 @@ async function scanPhoto(dir) {
|
|||
await fsp.mkdir(path.dirname(absIndexPath), { recursive: true });
|
||||
await fsp.writeFile(absIndexPath, JSON.stringify(photos, null, 2), 'utf8');
|
||||
}
|
||||
|
||||
await new Promise(r => setTimeout(r, 500));
|
||||
return photos;
|
||||
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
<button onclick="scan()">Scansiona Foto</button>
|
||||
<button onclick="resetDB()">Reset DB</button>
|
||||
<button onclick="readDB()">Leggi DB</button>
|
||||
|
||||
<pre id="out"></pre>
|
||||
</div>
|
||||
|
|
@ -25,6 +26,7 @@
|
|||
<script>
|
||||
let BASE_URL = null;
|
||||
let token = null;
|
||||
let db = [];
|
||||
|
||||
async function loadConfig() {
|
||||
const res = await fetch('/config');
|
||||
|
|
@ -61,7 +63,7 @@ async function readDB() {
|
|||
headers: { "Authorization": "Bearer " + token }
|
||||
});
|
||||
|
||||
const db = await res.json();
|
||||
db = await res.json();
|
||||
document.getElementById("out").textContent = JSON.stringify(db, null, 2);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
<!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>
|
||||
10
readme.md
10
readme.md
|
|
@ -4,15 +4,15 @@ This project allows us to use an API Rest to develop in the frontend with mock d
|
|||
|
||||
## Install
|
||||
|
||||
Clone this repo on your machine and before run `npm i` to install all dependences.
|
||||
Clone this repo on your machine and before run `npm ci` to install all dependences.
|
||||
|
||||
|
||||
## Start/Stop servers
|
||||
|
||||
| Description | Script |
|
||||
| ------------------------- | -------------------- |
|
||||
| Start server without auth | `npm start` |
|
||||
| Start server with auth | `npm run start-auth` |
|
||||
| Start server without auth | `npm start-no-auth` |
|
||||
| Start server with auth | `npm run start` |
|
||||
|
||||
## Tools
|
||||
|
||||
|
|
@ -27,6 +27,10 @@ Clone this repo on your machine and before run `npm i` to install all dependence
|
|||
| `localhost:4000/auth/login` | Login user |
|
||||
| `localhost:4000/photos` | Products list (token needed) |
|
||||
|
||||
## Open admin website
|
||||
```
|
||||
http://ip:4000
|
||||
```
|
||||
## Change port
|
||||
|
||||
in package.json mod -p 4000
|
||||
|
|
|
|||
Loading…
Reference in a new issue