clipboard

This commit is contained in:
2026-11-01 20:47:27 +01:00
parent b77b348d54
commit cbf5f20c75
14 changed files with 563 additions and 9 deletions
+33 -5
View File
@@ -3,9 +3,9 @@
Two Flask services with separate responsibilities and separate databases:
- **main app** (`app.py`) — all user-facing views: login, home, notes,
notifications, API docs and the `/sensors` dashboard. It owns the **main app**
database (`main_app.db`: users, notes and notifications) and proxies data
requests to the sensors API.
notifications, clipboard, API docs and the `/sensors` dashboard. It owns the
**main app** database (`main_app.db`: users, notes, notifications and clipboard
file metadata) and proxies data requests to the sensors API.
- **sensors app** (`sensors_app.py`) — API only. It owns the **sensors**
database (`sensors.db`, tables `sensor` and `sensor_readout`) and has no
knowledge of users. Its API is open to every user on the local machine.
@@ -35,7 +35,7 @@ server/
├── auth.py # Flask-Login setup
├── config.py # Config (databases, secret key, sensors URL)
├── models.py # Sensor, SensorReadout (sensors DB)
├── user_models.py # User, Note, NoteItem, Notification
├── user_models.py # User, Note, NoteItem, Notification, ClipboardFile
├── seed.py # Sample sensor data
├── migrate_legacy_db.py # Import old combined data.db into split DBs
├── run.sh # Development launcher (main/sensors + port)
@@ -47,6 +47,7 @@ server/
├── alembic_users/ # Users DB migration scripts
├── sensors.db # Sensors database (sensors app)
├── main_app.db # Users database (main app)
├── clipboard/ # Uploaded clipboard files (runtime, not in git)
├── data.db # Legacy combined DB (not used by default)
├── requirements.txt
└── templates/
@@ -54,6 +55,7 @@ server/
├── login.html
├── notes.html
├── notifications.html
├── clipboard.html
├── docs.html
└── sensors.html
```
@@ -164,6 +166,27 @@ sudo -u mateusz env USERS_DB_PATH=/data/main_app.db \
The service does not need to be restarted; the new account is used on the next
login.
## Clipboard
Logged-in users can upload, download and delete files at `/clipboard`. Files
are stored on the server in the clipboard directory (random file name) and only
metadata (original name, content type, size, owner) is kept in `main_app.db`.
Limits:
- one file: **100 MB** (`CLIPBOARD_MAX_FILE_BYTES`)
- total storage per user: **1 GB** (`CLIPBOARD_MAX_TOTAL_BYTES`)
The per-file limit is enforced while uploading; the per-user total quota is
checked before a file is stored.
Apply the users database migration once (the production launcher does this
automatically):
```bash
alembic -c alembic_users.ini upgrade head
```
## Notes
Logged-in users manage their own private short notes at `/notes`. Each note has
@@ -186,6 +209,8 @@ Each user has their own short text notifications in `main_app.db`. A
notification is either **new** or **read**. The main navigation shows the number
of new notifications next to the `Notifications` link. Opening a notification
from the `/notifications` page marks it as read and moves it below the new ones.
A notification can be deleted from the `/notifications` page with the `[x]`
button (endpoint: `POST /notifications/<id>/delete`).
Create notifications with the CLI (run it as the same user as the service):
@@ -257,6 +282,9 @@ BIND=0.0.0.0:8001 ./run-prod.sh sensors 8001
| `USERS_DATABASE_URL` | `sqlite:///<server>/main_app.db` | Users database URL |
| `USERS_DB_PATH` | `<server>/main_app.db` | SQLite path when URL is unset |
| `SECRET_KEY` | `.secret_key` file | Main app session signing key |
| `CLIPBOARD_DIR` | `<server>/clipboard` | Directory where uploaded files are stored |
| `CLIPBOARD_MAX_FILE_BYTES` | `104857600` (100 MB) | Maximum size of a single uploaded file |
| `CLIPBOARD_MAX_TOTAL_BYTES` | `1073741824` (1 GB) | Maximum total size of files per user |
| `HOST` | main `0.0.0.0`, sensors `127.0.0.1` | Listen address |
| `BIND` | `<HOST>:<port>` | Gunicorn bind override |
@@ -321,7 +349,7 @@ deployment path or user is different.
| Service | Port | Routes |
|---|---|---|
| main | 8000 | `/`, `/login`, `/home`, `/notes`, `/notifications`, `/sensors`, `/api/docs`, `/api/*` (proxy) |
| main | 8000 | `/`, `/login`, `/home`, `/clipboard`, `/notes`, `/notifications`, `/sensors`, `/api/docs`, `/api/*` (proxy) |
| sensors | 8001 | `/api/*` (sensors and readouts) |
### Tests