# Galleria con json-server e protetto con JWT S6J ## Installazione clonare questa repo e installare tutte le dipendenze con `npm ci` ## Start/Stop servers | Description | Script | | ------------------------- | -------------------- | | Start server senza auth | `npm start-no-auth` | | Start server con auth | `npm run start` | ## Tools | Description | Script | | ------------------------------ | ------------------- | | Generate user hashed passwords | `npm run hash` | [json-server api reference](https://github.com/typicode/json-server) ## Come usarlo clonare e poi installare con ``` npm ci ``` nel file .env ci sono tutti i dati da modificare poi inserire in user.json user e password utilizzati per fare il login la password da inserire è criptata e viene generata con npm run hash il nome viene utilizzato come cartella da scansionare, si trova dentro photos es: ``` name: Fabio public/photos └── Fabio └── original └── 2017Irlanda19-29ago ├── IMG_0092.JPG ├── IMG_0099.JPG ├── IMG_0100.JPG ``` poi dentro Fabio genererà thumbs con tutti i thumbs - npm run start - su IP:4000 ci sarà la galleria e andando su impostazioni si potrà fare lo scan di tutte le foto dopo aver fatto lo scan è possibile richiedere il json al server con tutte le informazioni anche senza autorizzazione basta farlo partire con npm run start-no-auth e le info si possono vedere con ip:4000/photos - npm start --- #### FIT parse (utilizzo di python) Per avere il parse dei fit installare python, pipx e i seguenyi packages ``` sudo apt install pipx pipx ensurepath pipx install fitdecode ``` usa per sapere dove è installato python ``` pipx list ``` in api_v1/scanner/parsers/parseFit.js va inserito il riferimento in questo caso ``` async function parseFit(absPath) { const frames = await new Promise((resolve, reject) => { execFile( "/home/orangepi/.local/pipx/venvs/fitdecode/bin/python", ["api_v1/scanner/parsers/parse_fit.py", absPath], { maxBuffer: 1024 * 1024 * 50 }, // 50 MB ``` Inspired in this [post](https://www.techiediaries.com/fake-api-jwt-json-server/) by [Techiediaries](https://www.techiediaries.com/) #### Interrogazioni manuali per vedere il token ``` curl -s -X POST https://prova.patachina.it/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"fabio@gmail.com","password":"master66"}' ``` per salvare il token ``` TOKEN=$(curl -s -X POST https://prova.patachina.it/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"fabio@gmail.com","password":"master66"}' \ | jq -r '.token') ``` per interrogare le foto ``` curl -s "https://prova.patachina.it/photos/" \ -H "Authorization: Bearer $TOKEN" ``` per interrogare le attività ``` curl -s "https://prova.patachina.it/activities/" \ -H "Authorization: Bearer $TOKEN" ```