- Session-based login (username/password, 30-day cookie) - SQLite user store with bcrypt password hashing (modernc.org/sqlite) - Per-user upload permission (can_upload flag) - Admin CLI (cmd/admin) for user management: user add/list/delete/set-upload - Upload handler for EPUB/PDF with path-traversal protection - All routes protected by requireAuth middleware; /upload additionally requires requireUpload - Login/logout UI, upload form, logout button in header - New env var: USERS_DB (default: users.db, gitignored) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
84 lines
1.6 KiB
Markdown
84 lines
1.6 KiB
Markdown
# eBook Library (Go + templ)
|
|
|
|
Minimalistische eBook-Bibliothek für den Tolino-Webbrowser.
|
|
|
|
## Features (MVP)
|
|
|
|
- Listet EPUB/PDF-Dateien aus `books/`
|
|
- Detailseite pro Buch
|
|
- Download-Link pro Buch (für Tolino)
|
|
- Schlichtes, kontrastreiches UI ohne JavaScript-Abhängigkeit
|
|
- Login-Pflicht (Session-Cookie, 30 Tage)
|
|
- Optionaler Buch-Upload für berechtigte Benutzer
|
|
|
|
## Voraussetzungen
|
|
|
|
- Go 1.22+
|
|
- [templ](https://github.com/a-h/templ)
|
|
|
|
Templ CLI installieren:
|
|
|
|
```bash
|
|
go install github.com/a-h/templ/cmd/templ@latest
|
|
```
|
|
|
|
## Start
|
|
|
|
1. Abhängigkeiten laden:
|
|
|
|
```bash
|
|
go mod tidy
|
|
```
|
|
|
|
2. Templates generieren:
|
|
|
|
```bash
|
|
templ generate
|
|
```
|
|
|
|
3. Ersten Benutzer anlegen:
|
|
|
|
```bash
|
|
go run ./cmd/admin user add <benutzername>
|
|
# mit Upload-Recht:
|
|
go run ./cmd/admin user add <benutzername> --upload
|
|
```
|
|
|
|
4. Server starten:
|
|
|
|
```bash
|
|
go run ./cmd/server
|
|
```
|
|
|
|
5. Browser öffnen:
|
|
|
|
- `http://localhost:8080`
|
|
|
|
## Bücher hinzufügen
|
|
|
|
Lege deine Dateien in den Ordner `books/`:
|
|
|
|
- `.epub` (bevorzugt)
|
|
- `.pdf` (optional)
|
|
|
|
Alternativ können Benutzer mit Upload-Recht Bücher direkt im Browser hochladen.
|
|
|
|
## Benutzerverwaltung (CLI)
|
|
|
|
```bash
|
|
go run ./cmd/admin user list
|
|
go run ./cmd/admin user add <name> [--upload]
|
|
go run ./cmd/admin user delete <name>
|
|
go run ./cmd/admin user set-upload <name> <true|false>
|
|
```
|
|
|
|
## Konfiguration
|
|
|
|
Umgebungsvariablen:
|
|
|
|
| Variable | Standard | Beschreibung |
|
|
|------------|------------|---------------------------------|
|
|
| `ADDR` | `:8080` | Listen-Adresse des Servers |
|
|
| `BOOKS_DIR`| `books` | Verzeichnis mit Büchern |
|
|
| `USERS_DB` | `users.db` | Pfad zur SQLite-Benutzerdatenbank |
|