Introduces a three-tier role hierarchy: reader < uploader < admin. - internal/users/role.go: Role type, roleLevel map, AtLeast(min), ParseRole() — new roles added by inserting into roleLevel only - internal/users/store.go: versioned migrations via _schema_version table; v2 migration adds 'role' column and migrates existing can_upload data; SetRole() replaces SetUpload(); Session carries Role instead of CanUpload - internal/web/middleware.go: generic requireRole(minRole) middleware replaces the ad-hoc requireUpload - internal/web/handlers.go: upload routes use requireRole(RoleUploader); listBooks derives canUpload from sess.Role.AtLeast(RoleUploader) - cmd/admin/main.go: user add --role <reader|uploader|admin>, user set-role replaces user set-upload - README, copilot-instructions updated Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
86 lines
1.7 KiB
Markdown
86 lines
1.7 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)
|
|
|
|
Rollen (aufsteigend): `reader` → `uploader` → `admin`
|
|
|
|
```bash
|
|
go run ./cmd/admin user add <name> [--role reader|uploader|admin]
|
|
go run ./cmd/admin user list
|
|
go run ./cmd/admin user delete <name>
|
|
go run ./cmd/admin user set-role <name> <reader|uploader|admin>
|
|
```
|
|
|
|
## 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 |
|