Compare commits
5
Commits
dev
..
fe2cfc2b79
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe2cfc2b79 | ||
|
|
0b9046cb7a | ||
|
|
49a49094de | ||
|
|
5c6f162c96 | ||
|
|
33e1223e69 |
No files matched your search
@@ -5,10 +5,7 @@ DATABASE_URL=sqlite:///data/mindsift.db
|
|||||||
JWT_SECRET=change_this_to_a_secure_random_key_min_32_chars
|
JWT_SECRET=change_this_to_a_secure_random_key_min_32_chars
|
||||||
BASE_URL=http://localhost:8080
|
BASE_URL=http://localhost:8080
|
||||||
ALLOW_REGISTRATION=false
|
ALLOW_REGISTRATION=false
|
||||||
# Logging level: debug, info, warn, error (Default: info)
|
|
||||||
LOG_LEVEL=info
|
LOG_LEVEL=info
|
||||||
# LOG_LEVEL=debug
|
|
||||||
# DEBUG=true
|
|
||||||
|
|
||||||
# Optional SMTP Server Configuration for Email Alarms (can also be set in Admin Settings UI)
|
# Optional SMTP Server Configuration for Email Alarms (can also be set in Admin Settings UI)
|
||||||
SMTP_HOST=
|
SMTP_HOST=
|
||||||
|
|||||||
+127
-34
@@ -1,40 +1,133 @@
|
|||||||
# MindSift Technische Dokumentation
|
# 📚 MindSift Technische Dokumentation & Wiki
|
||||||
|
|
||||||
Referenz für Entwickler und Administratoren. Alle Angaben wurden gegen den Code im Branch `dev` geprüft (Stand Oktober 2026). Abweichungen zwischen Doku und Code melde bitte als Fehler in [flaws.md](flaws.md).
|
Willkommen in der zentralen technischen Dokumentation von **MindSift**. Dieses Wiki dient als verbindliche, tiefgehende Referenz für Entwickler, DevOps-Ingenieure und Systemadministratoren. Es dokumentiert die Architektur, das Datenmodell, APIs, Echtzeit-Protokolle, Kernmodule sowie bekannte technische Schwachstellen der Plattform.
|
||||||
|
|
||||||
## Inhalt
|
---
|
||||||
|
|
||||||
| Dokument | Inhalt |
|
## 🧭 Inhaltsverzeichnis (Wiki-Navigation)
|
||||||
|---|---|
|
|
||||||
| [architecture.md](architecture.md) | Aufbau, Technologie-Stack, Start, Konfiguration, Build |
|
|
||||||
| [database.md](database.md) | SQLite-Schema, Migrationen, Datenmodell |
|
|
||||||
| [api/rest.md](api/rest.md) | Alle REST-Endpunkte |
|
|
||||||
| [api/websocket.md](api/websocket.md) | Echtzeit über WebSocket und SSE, Ereignisse |
|
|
||||||
| [modules/triage.md](modules/triage.md) | Schnellerfassung und Triage |
|
|
||||||
| [modules/tasks.md](modules/tasks.md) | Aufgaben, Kanban, Alarme |
|
|
||||||
| [modules/workspace.md](modules/workspace.md) | Outliner-Notizen, Ordner, Tags |
|
|
||||||
| [modules/lists.md](modules/lists.md) | Geteilte Listen |
|
|
||||||
| [sharing-and-permissions.md](sharing-and-permissions.md) | Rollen, Gruppen, Freigaben |
|
|
||||||
| [reverse-proxy.md](reverse-proxy.md) | Nginx, Traefik, Caddy, Cloudflare |
|
|
||||||
| [theming.md](theming.md) | Themes und Design-Variablen |
|
|
||||||
| [flaws.md](flaws.md) | Bekannte Schwachstellen und technische Schulden |
|
|
||||||
|
|
||||||
## Überblick in 60 Sekunden
|
```
|
||||||
|
Doku/
|
||||||
- **Ein Go-Binary** liefert REST-API, WebSocket/SSE und das eingebettete React-Frontend (`go:embed`). Es gibt genau einen Container und eine SQLite-Datei (`/data/mindsift.db`).
|
├── README.md # Einstieg, Inhaltsverzeichnis & Gesamtübersicht (dieses Dokument)
|
||||||
- **Datenhaltung:** vollständig in SQLite. Es gibt keine `.md`-Dateien auf der Platte; Markdown wird bei Bedarf aus den Blöcken erzeugt (`documents.markdown_cache`, Export als `.md`).
|
├── architecture.md # Systemarchitektur, Schichtenmodell, Concurrency & Stack
|
||||||
- **Echtzeit:** ein Hub mit Räumen und Benutzer-Kanälen. Verteilt werden Ereignisse nach REST-Änderungen. Es gibt keine CRDTs, Sperren oder Cursor-Presence.
|
├── database.md # SQLite-Datenbankdesign, Schemas, Indizes & Migrationen
|
||||||
- **Auth:** JWT (HS256, 30 Tage) mit `token_version` und Sperrliste, dazu API-Keys (`mindsift_sec_…`) für Webhooks.
|
├── api/
|
||||||
- **Freigaben:** Aufgabenlisten und geteilte Listen mit Rolle Bearbeiter oder Leser, Notizen und Ordner nur lesend.
|
│ ├── rest.md # Vollständige REST-API Referenz aller Endpunkte
|
||||||
|
│ └── websocket.md # WebSocket-Echtzeitprotokoll, Rooms & Document Locking
|
||||||
## Entwickeln
|
├── modules/
|
||||||
|
│ ├── triage.md # Modul 1: Triage & Quick-Dump (State Machine & Audio)
|
||||||
```bash
|
│ ├── tasks.md # Modul 2: Aufgaben & Kanban-System (Alarme & Scheduler)
|
||||||
# Backend (Go 1.23)
|
│ ├── workspace.md # Modul 3: Workspace Outliner-Engine, Wiki-Links & Disk-Sync
|
||||||
go vet ./... && go test ./...
|
│ └── lists.md # Modul 4: Geteilte Listen (Live-Kollaboration & D&D)
|
||||||
|
├── sharing-and-permissions.md # Synchrones Teilen, Rollen, Isolation & Mount-Entkopplung
|
||||||
# Frontend (Node 22)
|
├── theming.md # Single-File CSS Theme-Engine & Design-System
|
||||||
cd frontend && npm ci && npx tsc --noEmit && npm run build
|
└── flaws.md # Technische Schwachstellen, Risiken & zukünftige Optimierungen
|
||||||
```
|
```
|
||||||
|
|
||||||
Das Frontend wird für das Binary nach `cmd/server/dist` gebaut (siehe `Dockerfile`). Die CI läuft unter `.gitea/workflows/build-and-publish.yaml`.
|
### 📑 Kapitel im Detail
|
||||||
|
1. **[Systemarchitektur & Technologie-Stack](architecture.md)**
|
||||||
|
Schichtenmodell, Go-Backend, React-Frontend, Concurrency-Handling und Thread-Safety.
|
||||||
|
2. **[Datenbank-Design & SQLite Schema](database.md)**
|
||||||
|
Vollständiges relationales Datenmodell, ER-Diagramm, Tabellendefinitionen, Indizes und Migrationsstrategie.
|
||||||
|
3. **[REST-API Referenz](api/rest.md)**
|
||||||
|
Spezifikation aller Endpunkte für Authentifizierung, Gedanken, Aufgaben, Dokumente, Listen, Teams und Webhooks.
|
||||||
|
4. **[WebSocket & Echtzeit-Synchronisation](api/websocket.md)**
|
||||||
|
Gorilla WebSocket Hub, Rooms, Presence-Tracking, Document Locking Mechanismen und Polling-Fallback.
|
||||||
|
5. **[Kernmodul: Triage & Quick-Dump](modules/triage.md)**
|
||||||
|
Instant-Capture-Pipeline, Finite State Machine, Gestensteuerung, Spracheingabe und Webhook-Ingestion.
|
||||||
|
6. **[Kernmodul: Aufgaben & Kanban-System](modules/tasks.md)**
|
||||||
|
Multi-Listen-Konzept, 3-Spalten Kanban-Board, Subtasks, Fälligkeiten und Multi-Channel Alarm-Ticker (SMTP, Discord, Webhooks).
|
||||||
|
7. **[Kernmodul: Workspace & Outliner-Engine](modules/workspace.md)**
|
||||||
|
Logseq-inspirierte hierarchische Block-Engine, Zoom-Hoisting, Wiki-Links, Disk-Mirroring (`.md`) und Globales To-Do Rollup.
|
||||||
|
8. **[Kernmodul: Geteilte Listen & Kollaboration](modules/lists.md)**
|
||||||
|
Listen-Typen, Mengen, Kategorien, Live-Checkoff und Drag & Drop Sortierung.
|
||||||
|
9. **[Synchrones Teilen & Berechtigungskonzept](sharing-and-permissions.md)**
|
||||||
|
Rollenmodell (Admin/Member), System-Isolations-Modi (`strict_private`, `teams_only`, `open`), entkoppelte Ordner-Mounts und Notizen-Freigaben.
|
||||||
|
10. **[Single-File Theming & Design-System](theming.md)**
|
||||||
|
1-Datei = 1-Theme Philosophie, die 6 CSS-Variablen-Blöcke, Semantische CSS-Klassen und Geometrie-Steuerung.
|
||||||
|
11. **[Technische Schwachstellen & Optimierungspotenziale (Flaws)](flaws.md)**
|
||||||
|
Kritische Analyse von Concurrency-Grenzen, Dual-Storage-Risiken, Undo/Redo, Volltextsuche und Skalierungs-Engpässen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🏛️ Systemübersicht (High-Level Architektur)
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
graph TB
|
||||||
|
subgraph Client ["Client Layer (Browser / PWA)"]
|
||||||
|
UI["React 18 SPA (Vite, TS, Tailwind)"]
|
||||||
|
WSClient["WebSocket Client (Auto-Reconnect)"]
|
||||||
|
Cache["IndexedDB / Offline Queue"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph ReverseProxy ["Reverse Proxy / Gateway"]
|
||||||
|
Traefik["Traefik / Nginx (HTTPS, WSS, Rate Limits)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph Backend ["Backend Layer (Go 1.23 Engine)"]
|
||||||
|
ChiRouter["Chi Router (REST API)"]
|
||||||
|
WSHub["Gorilla WebSocket Hub & Lock Manager"]
|
||||||
|
AlarmTicker["Alarm Scheduler (Background Ticker)"]
|
||||||
|
DiskSync["Disk Mirror Engine (/data/workspace)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph Storage ["Storage Layer"]
|
||||||
|
SQLite[("SQLite WAL Database (/data/mindsift.db)")]
|
||||||
|
DiskFiles[("Physische Markdown Files (/data/workspace)")]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph External ["Externe Schnittstellen"]
|
||||||
|
HomeAssistant["Home Assistant / Webhooks"]
|
||||||
|
Discord["Discord Webhooks"]
|
||||||
|
SMTPServer["SMTP Server (E-Mail Alarme)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
UI -->|HTTPS REST| Traefik
|
||||||
|
WSClient -->|WSS Realtime| Traefik
|
||||||
|
Traefik --> ChiRouter
|
||||||
|
Traefik --> WSHub
|
||||||
|
ChiRouter --> SQLite
|
||||||
|
ChiRouter --> DiskSync
|
||||||
|
DiskSync --> DiskFiles
|
||||||
|
AlarmTicker --> Discord
|
||||||
|
AlarmTicker --> SMTPServer
|
||||||
|
HomeAssistant -->|POST /api/v1/inbox| Traefik
|
||||||
|
HomeAssistant -->|POST /api/v1/webhooks/ingest| Traefik
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ Schnellstart für Entwickler
|
||||||
|
|
||||||
|
### Voraussetzungen
|
||||||
|
- **Go:** 1.22 oder 1.23+
|
||||||
|
- **Node.js:** 20+ (LTS) & npm
|
||||||
|
- **Container-Runtime:** Docker oder Podman
|
||||||
|
|
||||||
|
### Lokale Entwicklung ohne Container
|
||||||
|
```bash
|
||||||
|
# 1. Repository klonen
|
||||||
|
git clone https://git.dsit.me/sandrodach/MindSift.git
|
||||||
|
cd MindSift
|
||||||
|
|
||||||
|
# 2. Frontend Abhängigkeiten installieren & Dev-Server starten
|
||||||
|
cd frontend
|
||||||
|
npm install
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# 3. Backend starten (in neuem Terminal)
|
||||||
|
cd ..
|
||||||
|
go run ./cmd/server
|
||||||
|
```
|
||||||
|
|
||||||
|
### Container Build & Testlauf (wie in der CI/CD)
|
||||||
|
```bash
|
||||||
|
# Backend-Tests ausführen
|
||||||
|
podman run --rm -v $(pwd):/app:z -w /app golang:1.23 go test -v ./internal/...
|
||||||
|
|
||||||
|
# Frontend Typecheck & Build testen
|
||||||
|
podman run --rm -v $(pwd):/app:z -w /app/frontend node:20 sh -c "npx tsc --noEmit && npm run build"
|
||||||
|
|
||||||
|
# Komplettes Multi-Stage Image bauen
|
||||||
|
podman build -t mindsift:dev .
|
||||||
|
```
|
||||||
+175
-119
@@ -1,129 +1,185 @@
|
|||||||
# REST-API
|
# 🔌 REST-API Referenz
|
||||||
|
|
||||||
Basis: `/api/v1`. Antworten sind JSON; Fehler haben die Form `{"error": "Text"}`. Authentifizierung über `Authorization: Bearer <JWT>` oder `Bearer mindsift_sec_…` bzw. Header `X-API-Key`. Zeitstempel sind ISO-8601 (UTC). Quelle der Wahrheit sind die Routen in [server.go](../../internal/api/server.go).
|
Die MindSift REST-API ermöglicht den vollständigen Zugriff auf Gedanken, Aufgaben, Workspace-Notizen, Listen, Benutzerkonten und Smarthome-Automationen.
|
||||||
|
|
||||||
## Öffentlich
|
---
|
||||||
|
|
||||||
| Methode | Pfad | Zweck |
|
## 🔐 1. Authentifizierung
|
||||||
|---|---|---|
|
|
||||||
| GET | `/health` | Lebenszeichen |
|
|
||||||
| GET | `/auth/status` | `needsSetup`, `allowRegistration`, `instanceName`, `demoMode` |
|
|
||||||
| POST | `/auth/setup` | Erstes Administratorkonto (`email`, `password`, `displayName`, `instanceName`, `allowRegistration`, `sharingMode`, `seedSampleData`); nur solange es keine Konten gibt |
|
|
||||||
| POST | `/auth/register` | Registrierung (`email`, `password`, `displayName`, `inviteCode`); nur mit Code oder wenn freigegeben |
|
|
||||||
| POST | `/auth/login` | Anmeldung (`login`/`email`/`username`, `password`) → `{token, user}` |
|
|
||||||
| POST | `/auth/quickstart` | Immer `403` (Gastzugang deaktiviert) |
|
|
||||||
| POST | `/webhooks/ingest` | Aufgabe per Webhook anlegen, Token als `?token=`, `X-API-Key` oder Bearer. Body: `title`/`content`/`text`/`message`, `priority`, `source`, `tags`, `dueDate`; Klartext-Body wird als Inhalt genommen |
|
|
||||||
| GET | `/ws`, `/ws/spaces/{id}`, `/ws/lists/{id}` | WebSocket, siehe [websocket.md](websocket.md) |
|
|
||||||
| GET | `/events` | SSE-Fallback |
|
|
||||||
| POST | `/events/rooms` | SSE-Räume beitreten/verlassen ([FLAW-02](../flaws.md)) |
|
|
||||||
|
|
||||||
## Konto und Allgemeines (angemeldet)
|
MindSift unterstützt zwei Authentifizierungsmethoden:
|
||||||
|
|
||||||
| Methode | Pfad | Zweck |
|
1. **JSON Web Token (JWT Bearer):**
|
||||||
|---|---|---|
|
Wird beim Login oder Setup erzeugt und im HTTP-Header mitgesendet:
|
||||||
| GET | `/auth/me` | Benutzer und Kennzahlen |
|
`Authorization: Bearer <jwt-token>`
|
||||||
| POST | `/auth/logout` | Token sperren |
|
2. **Persönliche API-Schlüssel (Smarthome / Automatisierung):**
|
||||||
| POST | `/auth/revoke-all` | Alle Sitzungen beenden (`token_version` +1) |
|
Werden unter *Einstellungen ➔ Private Webhooks* erzeugt (Präfix `mindsift_sec_...`):
|
||||||
| PATCH | `/auth/settings` | `displayName`, `email`, `password`, `avatarUrl`, `alarmChannels`, `alarmEmail`, `discordWebhookUrl`, `customWebhookUrl`, `notifyBeforeMinutes` |
|
- Per HTTP-Header: `X-API-Key: mindsift_sec_xxxxxxxxxxxx`
|
||||||
| POST | `/auth/alarms/test` | Test-Alarm (`channel`: `email`/`discord`/`webhook`, optional `target`) |
|
- Per Authorization-Header: `Authorization: Bearer mindsift_sec_xxxxxxxxxxxx`
|
||||||
| GET | `/users/directory`, `/collaborators` | Benutzerverzeichnis für Freigaben ([FLAW-10](../flaws.md)) |
|
- Per Query-Parameter: `?token=mindsift_sec_xxxxxxxxxxxx`
|
||||||
| GET | `/stats` | Zähler fürs Dashboard |
|
|
||||||
| GET | `/search?q=` | Suche in eigenen Gedanken und Notizen |
|
|
||||||
| GET | `/export` | Datenexport als JSON |
|
|
||||||
| GET/POST/DELETE | `/keys`, `/keys/{id}` | API-Keys verwalten (Klartext nur bei Erstellung) |
|
|
||||||
|
|
||||||
## Gedanken, Triage, Aufgaben
|
---
|
||||||
|
|
||||||
| Methode | Pfad | Zweck |
|
## 🚦 2. Status- & Fehler-Codes
|
||||||
|---|---|---|
|
|
||||||
| POST | `/inbox` | Schnellerfassung. Body: `content`, `priority`, `source`, `dueDate`, `target` (`inbox`/`task`/`list_item`/`document`), `targetListId`, `taskListId` (snake_case-Varianten werden akzeptiert) |
|
|
||||||
| GET | `/thoughts?status=` | Gedanken (`inbox`, `kept`, `converted`, `discarded`, `all`) |
|
|
||||||
| GET/PATCH/DELETE | `/thoughts/{id}` | Einzelabruf; Teiländerung (`content`, `isCompleted`, `dueDate`, `priority`, `taskListId`, `kanbanStatus`, `notes`, `subtasks`, `tags`); Löschen |
|
|
||||||
| DELETE | `/thoughts/discarded/purge` | Papierkorb leeren |
|
|
||||||
| GET | `/triage/deck` | Posteingang (max. 100) |
|
|
||||||
| PATCH | `/triage/{id}` | `action`: `keep`/`discard`/`restore`; mit `convertTo`: `task`/`document`/`list_item` |
|
|
||||||
| GET | `/tasks?taskListId=` | Aufgaben (optional einer Liste) |
|
|
||||||
| POST | `/tasks/reorder`, `/task-lists/{id}/tasks/reorder` | Reihenfolge/Spalte ändern (`items[{id, sortOrder, kanbanStatus}]`) |
|
|
||||||
| POST | `/tasks/{id}/unlink` | Verknüpfung zu Notiz-Block lösen |
|
|
||||||
|
|
||||||
## Aufgabenlisten
|
- `200 OK`: Erfolgreiche Abfrage oder Aktualisierung.
|
||||||
|
- `201 Created`: Ressource erfolgreich angelegt.
|
||||||
|
- `400 Bad Request`: Ungültiges JSON oder fehlende Pflichtfelder.
|
||||||
|
- `401 Unauthorized`: Token ungültig, abgelaufen oder fehlend.
|
||||||
|
- `403 Forbidden`: Unzureichende Berechtigungen (z.B. nur Server-Admin oder nur Lesezugriff).
|
||||||
|
- `404 Not Found`: Ressource existiert nicht oder gehört einem anderen Benutzer.
|
||||||
|
- `409 Conflict`: Ressource gesperrt (z.B. Dokument wird bereits von anderem Benutzer bearbeitet).
|
||||||
|
|
||||||
| Methode | Pfad | Zweck |
|
Fehlerrückgaben erfolgen im einheitlichen Format:
|
||||||
|---|---|---|
|
```json
|
||||||
| GET/POST | `/task-lists` | Listen (`permission` je Liste: `owner`/`editor`/`viewer`); anlegen (`title`, `icon`, `color`, `teamId`) |
|
{
|
||||||
| PUT/DELETE | `/task-lists/{id}` | Ändern (`title`, `icon`, `color`, `teamId`, `columns`) – nicht für Leser; Löschen nur Eigentümer |
|
"error": "Fehlermeldung im Klartext"
|
||||||
| GET | `/task-lists/{id}/shares` | Freigaben |
|
}
|
||||||
| POST | `/task-lists/{id}/shares` | Nur Eigentümer. Body: `targetType` (`team`/`user`), `targetId`, `permission` (`editor`/`viewer`, Standard `editor`). Erneutes Senden für dasselbe Ziel ändert die Stufe |
|
|
||||||
| DELETE | `/task-lists/{id}/shares/{shareId}` | Nur Eigentümer |
|
|
||||||
|
|
||||||
Schreibzugriffe von Lesern auf Listen oder deren Aufgaben liefern `403` („Keine Schreibrechte für diese Aufgabenliste (nur Lesen)“).
|
|
||||||
|
|
||||||
## Workspace
|
|
||||||
|
|
||||||
| Methode | Pfad | Zweck |
|
|
||||||
|---|---|---|
|
|
||||||
| GET/POST/DELETE | `/folders` | Ordnerliste, anlegen (`path`), löschen |
|
|
||||||
| POST | `/folders/move` | `sourcePath`, `targetParentPath` |
|
|
||||||
| GET/POST | `/workspace/folders/shared` | Geteilte Ordner; anlegen (`name`, `mountPath`) |
|
|
||||||
| GET/DELETE | `/workspace/folders/shared/{id}` | Abruf; Löschen |
|
|
||||||
| PUT | `/workspace/folders/shared/{id}/mount` | Eigenen Einhängepfad ändern (`mountPath`) |
|
|
||||||
| GET/POST/DELETE | `/workspace/folders/shared/{id}/shares[/{shareId}]` | Freigaben (nur Lesen wirksam) |
|
|
||||||
| GET | `/workspace/tags`, `/workspace/tags/{tag}` | Tag-Übersicht und -Details |
|
|
||||||
| PUT | `/workspace/tags/{tag}/note` | Tag-Seite speichern (`content`) |
|
|
||||||
| GET/POST | `/documents` | Notizen auflisten; anlegen (`title`, `icon`, `folderPath`, `blocks`, `tags`, `isPinned`) |
|
|
||||||
| GET/PUT/DELETE | `/documents/{id}` | Abruf; Ändern (`title`, `icon`, `folderPath`, `blocks`, `tags`, `isPinned`); Löschen |
|
|
||||||
| PATCH | `/documents/{id}/blocks` | Teil-Update der Blöcke (`upserted`, `deletedIds`, Reihenfolge); löst `DOC_BLOCKS_PATCHED` aus |
|
|
||||||
| PUT | `/documents/{id}/move` | Ordner wechseln (`folderPath`) |
|
|
||||||
| POST | `/documents/{id}/blocks/{blockId}/enhanced-task` | Aus einem Block eine verknüpfte Aufgabe machen (`content`, `checked`) |
|
|
||||||
| GET/POST/DELETE | `/documents/{id}/shares[/{userId}]` | Notiz-Freigaben (`userId`/`email`/`teamId`; wirksam nur Lesen) |
|
|
||||||
|
|
||||||
Nur der Eigentümer schreibt in eine Notiz; Empfänger erhalten `403`/„nur Lesezugriff“ ([FLAW-17](../flaws.md)).
|
|
||||||
|
|
||||||
## Geteilte Listen
|
|
||||||
|
|
||||||
| Methode | Pfad | Zweck |
|
|
||||||
|---|---|---|
|
|
||||||
| GET/POST | `/lists` | Listen; anlegen (`title`, `icon`, `listType`) |
|
|
||||||
| GET/DELETE | `/lists/{id}` | Abruf mit Einträgen; Löschen |
|
|
||||||
| GET/POST/DELETE | `/lists/{id}/shares[/{shareId}]` | Freigaben (`targetType`, `targetId`, `role`: `editor`/`viewer`) |
|
|
||||||
| POST | `/lists/{id}/items` | Eintrag (`content`, `category`, `quantity`) |
|
|
||||||
| PATCH | `/lists/{id}/items/{itemId}` | Abhaken (`isCompleted`) |
|
|
||||||
| PUT | `/lists/{id}/items/{itemId}` | Ändern (`content`, `category`, `quantity`) |
|
|
||||||
| DELETE | `/lists/{id}/items/{itemId}` | Löschen |
|
|
||||||
| POST/PUT | `/lists/{id}/items/reorder` | Reihenfolge/Kategorie (`items[{id, sortOrder, category, content}]`) |
|
|
||||||
| POST | `/lists/{id}/clear-completed` | Erledigte entfernen |
|
|
||||||
|
|
||||||
## Gruppen
|
|
||||||
|
|
||||||
| Methode | Pfad | Zweck |
|
|
||||||
|---|---|---|
|
|
||||||
| GET/POST | `/teams` | Eigene Gruppen; anlegen (`name`, `description`) – Ersteller wird Gruppen-Admin |
|
|
||||||
| PUT/DELETE | `/teams/{id}` | Nur Gruppen-Admin |
|
|
||||||
| POST | `/teams/{id}/members` | Mitglied hinzufügen (`userId` oder `email`, `role`) |
|
|
||||||
| PUT/DELETE | `/teams/{id}/members/{userId}` | Rolle ändern (`admin`/`member`); entfernen |
|
|
||||||
| GET/POST/DELETE | `/organizations`, `/organizations/{id}[/teams]` | Veraltet, ungeschützt ([FLAW-24](../flaws.md)) |
|
|
||||||
|
|
||||||
## Administration (`role = admin`)
|
|
||||||
|
|
||||||
| Methode | Pfad | Zweck |
|
|
||||||
|---|---|---|
|
|
||||||
| GET/POST | `/admin/users` | Benutzer auflisten, anlegen (`email`, `password`, `displayName`, `role`) |
|
|
||||||
| PATCH/DELETE | `/admin/users/{id}` | `displayName`, `email`, `role`, `isActive`, `discordWebhookUrl`; löschen |
|
|
||||||
| PUT | `/admin/users/{id}/password` | Passwort zurücksetzen |
|
|
||||||
| GET/POST/DELETE | `/admin/invites[/{id}]` | Einladungen (`email`, `role`, `teamId`, `validDays`) |
|
|
||||||
| GET/PUT | `/admin/settings` | `instanceName`, `allowRegistration`, `sharingMode`, SMTP-Felder |
|
|
||||||
| POST | `/admin/smtp/test` | Testmail (`toEmail`) |
|
|
||||||
|
|
||||||
## Beispiele
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Gedanken per API-Key erfassen
|
|
||||||
curl -X POST https://mindsift.example.com/api/v1/webhooks/ingest \
|
|
||||||
-H "X-API-Key: mindsift_sec_…" -H "Content-Type: application/json" \
|
|
||||||
-d '{"title":"Milch kaufen #einkauf","priority":"high","dueDate":"2026-11-01"}'
|
|
||||||
|
|
||||||
# Aufgabenliste nur lesend freigeben
|
|
||||||
curl -X POST https://mindsift.example.com/api/v1/task-lists/tkl_…/shares \
|
|
||||||
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
|
|
||||||
-d '{"targetType":"user","targetId":"usr_…","permission":"viewer"}'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 3. Endpunkte nach Modulen
|
||||||
|
|
||||||
|
### 3.1 Authentifizierung & System-Status
|
||||||
|
|
||||||
|
| Methode | Pfad | Auth | Beschreibung |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `GET` | `/api/v1/health` | Öffentlich | Liveness-Check (`{"status":"ok"}`) |
|
||||||
|
| `GET` | `/api/v1/auth/status` | Öffentlich | Prüft ob Ersteinrichtung nötig ist (`needsSetup: true/false`) |
|
||||||
|
| `POST` | `/api/v1/auth/setup` | Öffentlich | Führt First-Boot Setup durch (legt ersten Admin an) |
|
||||||
|
| `POST` | `/api/v1/auth/register` | Öffentlich | Registrierung über Einladungscode (`inviteCode`) |
|
||||||
|
| `POST` | `/api/v1/auth/login` | Öffentlich | Login via E-Mail oder Benutzername + Passwort |
|
||||||
|
| `GET` | `/api/v1/auth/me` | JWT | Gibt das aktuelle Benutzerprofil zurück |
|
||||||
|
| `PATCH` | `/api/v1/auth/settings` | JWT | Aktualisiert Profil, Passwort, Theme oder Alarm-Kanäle |
|
||||||
|
| `POST` | `/api/v1/auth/alarms/test` | JWT | Sendet Test-Alarm an E-Mail, Discord oder Custom Webhook |
|
||||||
|
|
||||||
|
#### Beispiel: `POST /api/v1/auth/login`
|
||||||
|
```json
|
||||||
|
// Request
|
||||||
|
{
|
||||||
|
"login": "sandro",
|
||||||
|
"password": "geheimesPasswort123"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response (200 OK)
|
||||||
|
{
|
||||||
|
"token": "eyJhbGciOiJIUzI1NiIs...",
|
||||||
|
"user": {
|
||||||
|
"id": "usr_abc123",
|
||||||
|
"email": "sandro@example.com",
|
||||||
|
"username": "sandro",
|
||||||
|
"displayName": "Sandro",
|
||||||
|
"role": "admin",
|
||||||
|
"alarmChannels": ["discord", "webhook"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3.2 Triage & Instant Capture
|
||||||
|
|
||||||
|
| Methode | Pfad | Auth | Beschreibung |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `POST` | `/api/v1/inbox` | JWT / API-Key | Erfasst einen neuen Quick Dump oder leitet direkt weiter |
|
||||||
|
| `GET` | `/api/v1/triage/deck` | JWT | Liefert den Stapel aller noch nicht triagierten Gedanken (`status: 'inbox'`) |
|
||||||
|
| `PATCH` | `/api/v1/triage/{id}` | JWT | Führt Triage-Aktion aus (`keep`, `discard`, `restore`) |
|
||||||
|
|
||||||
|
#### Beispiel: `POST /api/v1/inbox`
|
||||||
|
Ermöglicht flexible Direkt-Zuordnungen:
|
||||||
|
```json
|
||||||
|
// Request (Quick Dump in Triage-Deck)
|
||||||
|
{
|
||||||
|
"content": "Kellerfeuchtigkeit über 68% gestiegen #smarthome #alarm",
|
||||||
|
"priority": "urgent"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request (Direkt als Aufgabe anlegen)
|
||||||
|
{
|
||||||
|
"content": "Server Backup prüfen #devops",
|
||||||
|
"priority": "high",
|
||||||
|
"target": "task",
|
||||||
|
"dueDate": "2026-10-30"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
*Hinweis:* Wenn `/api/v1/inbox` über einen API-Key aufgerufen wird und kein `source` definiert ist, wird die Quelle automatisch als `"webhook"` markiert!
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3.3 Aufgaben & Kanban-System
|
||||||
|
|
||||||
|
| Methode | Pfad | Auth | Beschreibung |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `GET` | `/api/v1/tasks` | JWT | Liefert alle Aufgaben des Benutzers (inkl. geteilter Aufgaben) |
|
||||||
|
| `POST` | `/api/v1/tasks/reorder` | JWT | Speichert Kanban-Status und Reihenfolge (`sort_order`) |
|
||||||
|
| `GET` | `/api/v1/task-lists` | JWT | Liefert alle Aufgabenlisten (eigene & geteilte) |
|
||||||
|
| `POST` | `/api/v1/task-lists` | JWT | Erstellt eine neue Aufgabenliste (mit Farbe & Spalten) |
|
||||||
|
| `PUT` | `/api/v1/task-lists/{id}` | JWT | Ändert Titel, Farbe, Icon oder Kanban-Spalten |
|
||||||
|
| `DELETE` | `/api/v1/task-lists/{id}` | JWT | Löscht Aufgabenliste |
|
||||||
|
| `POST` | `/api/v1/task-lists/{id}/shares` | JWT | Teilt Liste mit Team oder Benutzer |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3.4 Workspace & Dokumente
|
||||||
|
|
||||||
|
| Methode | Pfad | Auth | Beschreibung |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `GET` | `/api/v1/documents` | JWT | Liefert Liste aller Dokumente des Benutzers (Metadaten) |
|
||||||
|
| `POST` | `/api/v1/documents` | JWT | Erstellt neues Notiz-Dokument (mit Blocks oder Markdown) |
|
||||||
|
| `GET` | `/api/v1/documents/{id}` | JWT | Lädt komplettes Dokument inklusive aller Blöcke |
|
||||||
|
| `PUT` | `/api/v1/documents/{id}` | JWT | Aktualisiert Dokumenttitel, Icon oder Ordnerpfad |
|
||||||
|
| `PATCH` | `/api/v1/documents/{id}/blocks` | JWT | Granulares Patching von Dokument-Blöcken (Database-First) |
|
||||||
|
| `DELETE` | `/api/v1/documents/{id}` | JWT | Löscht Dokument (Datenbank & physische Datei) |
|
||||||
|
| `POST` | `/api/v1/documents/{id}/shares` | JWT | Notiz mit anderem Benutzer teilen (`read` / `write`) |
|
||||||
|
| `GET` | `/api/v1/documents/{id}/lock` | JWT | Fragt Bearbeitungs-Sperrstatus ab |
|
||||||
|
| `POST` | `/api/v1/documents/{id}/lock` | JWT | Sperrt Dokument für Bearbeitung (30s Lease) |
|
||||||
|
| `DELETE` | `/api/v1/documents/{id}/lock` | JWT | Gibt Bearbeitungssperre wieder frei |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3.5 Workspace Ordner & Geteilte Ordner
|
||||||
|
|
||||||
|
| Methode | Pfad | Auth | Beschreibung |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `GET` | `/api/v1/folders` | JWT | Liefert alle Ordnerpfade des Benutzers |
|
||||||
|
| `POST` | `/api/v1/folders` | JWT | Legt neuen (auch leeren) Ordner an |
|
||||||
|
| `POST` | `/api/v1/folders/move` | JWT | Benennt Ordner um oder verschiebt ihn hierarchisch |
|
||||||
|
| `DELETE` | `/api/v1/folders` | JWT | Löscht Ordner und verschiebt Notizen |
|
||||||
|
| `GET` | `/api/v1/workspace/folders/shared` | JWT | Liefert für den Benutzer freigegebene geteilte Ordner |
|
||||||
|
| `POST` | `/api/v1/workspace/folders/shared` | JWT | Erstellt neuen geteilten Ordner |
|
||||||
|
| `PUT` | `/api/v1/workspace/folders/shared/{id}/mount` | JWT | Ändert den lokalen Einhängepfad beim Empfänger |
|
||||||
|
| `POST` | `/api/v1/workspace/folders/shared/{id}/shares` | JWT | Gibt Ordner für Teams oder Benutzer frei |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3.6 Geteilte Listen (Listen & Einkauf)
|
||||||
|
|
||||||
|
| Methode | Pfad | Auth | Beschreibung |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `GET` | `/api/v1/lists` | JWT | Liefert alle geteilten Listen |
|
||||||
|
| `POST` | `/api/v1/lists` | JWT | Erstellt neue geteilte Liste |
|
||||||
|
| `GET` | `/api/v1/lists/{id}` | JWT | Lädt Liste inklusive aller Einträge |
|
||||||
|
| `POST` | `/api/v1/lists/{id}/items` | JWT | Fügt Eintrag hinzu |
|
||||||
|
| `PATCH` | `/api/v1/lists/{id}/items/{itemId}` | JWT | Hakt Eintrag ab (`isCompleted: true/false`) |
|
||||||
|
| `POST` | `/api/v1/lists/{id}/items/reorder` | JWT | Speichert sortierte Einträge |
|
||||||
|
| `POST` | `/api/v1/lists/{id}/clear-completed`| JWT | Löscht alle abgehakten Einträge |
|
||||||
|
| `POST` | `/api/v1/lists/{id}/shares` | JWT | Teilt Liste mit Team oder Benutzer |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3.7 Smarthome Ingestion & Externe Webhooks
|
||||||
|
|
||||||
|
| Methode | Pfad | Auth | Beschreibung |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `POST` | `/api/v1/webhooks/ingest` | Token / Key | Empfängt externe Webhook-Payloads von Home Assistant / n8n |
|
||||||
|
|
||||||
|
#### Beispiel: `POST /api/v1/webhooks/ingest?token=mindsift_sec_...`
|
||||||
|
Unterstützt flexible Payloads (JSON oder Plain Text):
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"title": "Waschmaschine Keller fertig",
|
||||||
|
"priority": "high",
|
||||||
|
"tags": ["smarthome", "keller"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
*Live-Aktualisierung:* Sendet automatisch ein `TASK_CREATED` WebSocket-Event an alle Clients des Benutzers, sodass die neue Karte sofort ohne Neuladen im Triage-Deck erscheint!
|
||||||
+101
-43
@@ -1,55 +1,113 @@
|
|||||||
# Echtzeit: WebSocket und SSE
|
# 📡 WebSocket & Echtzeit-Synchronisation
|
||||||
|
|
||||||
Der Server verteilt Änderungen als JSON-Ereignisse an verbundene Clients. Die Ereignisse entstehen **nach** einer REST-Änderung; es gibt keinen Schreibkanal über die Verbindung. Implementierung: [hub.go](../../internal/ws/hub.go), Client: [api.ts](../../frontend/src/lib/api.ts).
|
MindSift implementiert eine bidirektionale Echtzeit-Synchronisationsschicht auf Basis von WebSockets ([`internal/ws/hub.go`](../../internal/ws/hub.go)). Sie sorgt dafür, dass Änderungen an Aufgaben, Triage-Karten, Notizen und geteilten Einkaufslisten ohne manuelles Neuladen sofort auf allen geöffneten Geräten und bei allen Kollaborationspartnern sichtbar werden.
|
||||||
|
|
||||||
> Keine CRDTs, keine Sperren, keine Cursor-Presence. Frühere Fassungen dieser Doku beschrieben DocRooms, `clientId`-Echo-Schutz und Yjs; das existiert nicht (mehr).
|
---
|
||||||
|
|
||||||
## Transporte
|
## 🔌 1. Verbindung & Handshake
|
||||||
|
|
||||||
| Transport | Endpunkt | Hinweise |
|
### Verbindungs-Endpunkte
|
||||||
|---|---|---|
|
```
|
||||||
| WebSocket | `GET /api/v1/ws` (auch `/ws/lists/{id}`, `/ws/spaces/{id}`) | Ping alle 30 s, Lesefrist 60 s, Nachrichten bis 4 MB |
|
wss://<domain>/api/v1/ws?token=<jwt-token>
|
||||||
| SSE | `GET /api/v1/events` | Kommentar-Ping alle 15 s, Header `X-Accel-Buffering: no` |
|
wss://<domain>/api/v1/ws/lists/<listId>?token=<jwt-token>
|
||||||
|
|
||||||
Der Client versucht zuerst WebSocket. Gelingt der Aufbau nicht innerhalb von 2,5 s oder bricht die Verbindung unsauber ab, wechselt er auf SSE und bleibt dabei (Firmen-Proxys). Dort liefert der Server `SSE_CONNECTED` mit einer `sseId`; Räume werden über `POST /api/v1/events/rooms` (`sseId`, `room`, `action`: `join`/`leave`) abonniert.
|
|
||||||
|
|
||||||
**Authentifizierung:** Token als `?token=<JWT|API-Key>` oder `Authorization`-Header. Ohne gültiges Token wird die Verbindung als `anonymous` akzeptiert ([FLAW-01](../flaws.md), [FLAW-02](../flaws.md)). Das Token wird nur beim Verbinden geprüft.
|
|
||||||
|
|
||||||
## Nachrichtenformat
|
|
||||||
|
|
||||||
```json
|
|
||||||
{ "event": "TASK_UPDATED", "listId": "", "payload": { … }, "timestamp": "2026-10-27T12:00:00Z" }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Client → Server versteht der Server nur: `{"event":"JOIN_ROOM","room":"<id>"}` und `{"event":"LEAVE_ROOM","room":"<id>"}`. Räume heißen `doc:<docId>` für Notizen oder `<listId>` für geteilte Listen.
|
### Authentifizierung & Upgrade
|
||||||
|
- Die Authentifizierung erfolgt über das JWT-Token im Query-Parameter `?token=...` oder den `Authorization: Bearer`-Header während des HTTP-Upgrade-Requests.
|
||||||
|
- Der Server extrahiert die `userID` und registriert die Verbindung im internen `Hub`.
|
||||||
|
- Der `Upgrader` akzeptiert alle Origins (`CheckOrigin: return true`), um volle Kompatibilität mit Reverse-Proxies (Traefik, Nginx, Caddy, Cloudflare) und Docker-Netzwerken zu gewährleisten.
|
||||||
|
|
||||||
## Zustellung
|
---
|
||||||
|
|
||||||
| Kanal | Wer erhält es |
|
## 🏛️ 2. Hub-Architektur & Rooms
|
||||||
|---|---|
|
|
||||||
| Benutzer-Kanal (`BroadcastToUser`) | alle Verbindungen eines Benutzers |
|
|
||||||
| Raum (`BroadcastRoom`, `Broadcast`) | Verbindungen im Raum |
|
|
||||||
| Alle (`BroadcastToAll`) | **jede** Verbindung, auch unangemeldete |
|
|
||||||
|
|
||||||
## Ereignisse
|
Der WebSocket-Hub unterteilt Verbindungen in drei Abstraktionsebenen:
|
||||||
|
|
||||||
| Ereignis | Auslöser | Kanal |
|
```
|
||||||
|---|---|---|
|
┌─────────────────────────────────────────────────────────────────┐
|
||||||
| `TASK_CREATED` | `POST /inbox` | Benutzer |
|
│ WebSocket Hub │
|
||||||
| `TASK_UPDATED` | `PATCH /thoughts/{id}` (Triage: Benutzer) | alle |
|
├─────────────────┬─────────────────────────────┬─────────────────┤
|
||||||
| `TASK_DELETED` | `DELETE /thoughts/{id}` | alle |
|
│ allClients │ userRooms │ rooms │
|
||||||
| `TASK_REORDERED` | Aufgaben umsortieren | alle |
|
│ (Alle aktiven │ (Pro Benutzer-ID) │ (Pro Liste/ │
|
||||||
| `TASK_LIST_UPDATED` / `TASK_LIST_DELETED` | Liste ändern, (un)teilen, löschen | alle |
|
│ Verbindungen) │ Cross-Device Sync für │ Space) │
|
||||||
| `DOC_CREATED`, `DOC_UPDATED`, `DOC_DELETED` | Notiz anlegen/ändern/löschen, Freigaben | berechtigte Benutzer |
|
│ │ Tasks, Triage & Workspace │ Geteilte Liste │
|
||||||
| `DOC_BLOCKS_PATCHED` | `PATCH /documents/{id}/blocks` (`docId`, `updatedBy`, `upserted`, `deletedIds`, `blockOrder`) | Raum `doc:<id>` und berechtigte Benutzer |
|
└────────┬────────┴──────────────┬──────────────┴────────┬────────┘
|
||||||
| `WORKSPACE_FOLDERS_UPDATED` | Ordner/Mounts ändern | Benutzer |
|
▼ ▼ ▼
|
||||||
| `LIST_CREATED`, `LIST_UPDATED`, `LIST_DELETED`, `LIST_SHARED`, `LIST_UNSHARED`, `LIST_CLEARED` | Listenverwaltung | Benutzer bzw. Raum der Liste |
|
Presence Stats TASK_CREATED ITEM_TOGGLED
|
||||||
| `ITEM_CREATED`, `ITEM_UPDATED`, `ITEM_TOGGLED`, `ITEM_DELETED`, `ITEM_REORDERED` | Listeneinträge | Raum der Liste |
|
DOC_LOCKED TASK_UPDATED ITEM_CREATED
|
||||||
| `USER_PRESENCE` | Verbindung auf-/abgebaut (`onlineCount`) | Raum |
|
DOC_UNLOCKED DOC_UPDATED LIST_UPDATED
|
||||||
| `SSE_CONNECTED` | Nur SSE, direkt nach Verbindung | Verbindung |
|
```
|
||||||
|
|
||||||
## Verhalten im Frontend
|
1. **`allClients` (Global):** Hält jede aktive Client-Verbindung. Ermöglicht Broadcasts systemweiter Ereignisse (z.B. globale Dokument-Sperrungen).
|
||||||
|
2. **`userRooms[userID]` (Benutzer-Räume):** Sendet Events an alle Geräte desselben Benutzers (z.B. Desktop und Smartphone). Erzeugt ein Webhook oder Quick Dump auf dem Smartphone einen Eintrag, taucht dieser zeitgleich auf dem Desktop auf.
|
||||||
|
3. **`rooms[listID]` (Kollaborations-Räume):** Multiplexing für geteilte Listen. Alle Mitglieder einer Liste empfangen Aktionen (wie Abhaken, Löschen, Umsortieren) in Echtzeit.
|
||||||
|
|
||||||
- Die globale Verbindung (ein Singleton) leitet jede Nachricht als Browser-Ereignis `mindsift:ws` weiter; Ansichten (`TasksView`, `WorkspaceView`, `SharedListsView`) hören darauf und laden bzw. patchen ihren Zustand.
|
---
|
||||||
- Nach einem Abbruch verbindet sich der Client mit Verzögerung neu.
|
|
||||||
- Weil Notizen nur vom Eigentümer geschrieben werden, dient `DOC_BLOCKS_PATCHED` vor allem dazu, Lesenden und weiteren Geräten des Eigentümers Änderungen zu zeigen. Es gibt keine Konfliktauflösung (letzter Schreiber gewinnt).
|
## 📨 3. Nachrichten-Format (Envelope)
|
||||||
|
|
||||||
|
Alle WebSocket-Nachrichten werden als JSON mit einheitlicher Hülle übertragen:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "ITEM_TOGGLED",
|
||||||
|
"listId": "lst_12345",
|
||||||
|
"payload": {
|
||||||
|
"itemId": "itm_987",
|
||||||
|
"isCompleted": true,
|
||||||
|
"completedBy": "usr_sandro",
|
||||||
|
"completedByName": "Sandro"
|
||||||
|
},
|
||||||
|
"timestamp": "2026-10-26T13:30:00Z"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔒 4. Dokument-Sperrsystem (Document Locking)
|
||||||
|
|
||||||
|
Um Schreibkonflikte bei Notizen im Workspace zu vermeiden, verwendet MindSift ein **serverseitiges Lease-Locking mit Heartbeat**:
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
actor UserA as Benutzer A
|
||||||
|
participant WS as WebSocket Hub
|
||||||
|
actor UserB as Benutzer B
|
||||||
|
|
||||||
|
UserA->>WS: LOCK_DOC (docId: "doc_123")
|
||||||
|
WS-->>UserA: Lock bestätigt (30s TTL)
|
||||||
|
WS->>UserB: DOC_LOCKED (docId: "doc_123", lockedBy: "Benutzer A")
|
||||||
|
Note over UserB: Editor gesperrt (Schreibschutz aktiv)
|
||||||
|
|
||||||
|
loop Alle 15 Sekunden
|
||||||
|
UserA->>WS: HEARTBEAT_DOC (docId: "doc_123")
|
||||||
|
WS-->>UserA: TTL um 30s verlängert
|
||||||
|
end
|
||||||
|
|
||||||
|
alt Reguläres Schließen
|
||||||
|
UserA->>WS: UNLOCK_DOC (docId: "doc_123")
|
||||||
|
WS->>UserB: DOC_UNLOCKED (docId: "doc_123")
|
||||||
|
Note over UserB: Editor wieder freigegeben
|
||||||
|
else Verbindungsabbruch / Tab geschlossen
|
||||||
|
Note over WS: Heartbeat bleibt aus (TTL läuft ab)
|
||||||
|
WS->>UserB: DOC_UNLOCKED (Automatisch nach Ablauf)
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
### Locking-Events
|
||||||
|
- **`LOCK_DOC` (Client ➔ Server):** Fordert eine 30-Sekunden-Sperre für ein Dokument an.
|
||||||
|
- **`HEARTBEAT_DOC` (Client ➔ Server):** Verlängert die Sperre alle 15 Sekunden, solange der Benutzer das Dokument geöffnet hat.
|
||||||
|
- **`UNLOCK_DOC` (Client ➔ Server):** Gibt die Sperre beim Verlassen des Dokuments frei.
|
||||||
|
- **`DOC_LOCKED` (Server ➔ Clients):** Informiert andere Benutzer, dass das Dokument schreibgeschützt ist.
|
||||||
|
- **`DOC_UNLOCKED` (Server ➔ Clients):** Hebt den Schreibschutz auf.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 5. Fallback-Strategie & Reconnect
|
||||||
|
|
||||||
|
In strikten Firmennetzwerken oder bei Proxy-Problemen (z.B. fehlende `Upgrade`-Header bei HTTP/1.1) kann eine WebSocket-Verbindung fehlschlagen:
|
||||||
|
|
||||||
|
1. **Exponentielles Backoff:** Das Frontend ([`frontend/src/lib/api.ts`](../../frontend/src/lib/api.ts)) versucht automatisch die Wiederverbindung nach 1s, 2s, 4s, 8s, bis maximal 30s.
|
||||||
|
2. **HTTP-Polling Fallback:** Geteilte Listen und Notizen aktivieren im Hintergrund ein periodisches Polling (5s Intervall), falls der WebSocket-Status nicht `CONNECTED` ist.
|
||||||
|
3. **Status-Indikator:** Ein dezenter grüner bzw. gelber Indikator oben rechts im Header zeigt dem Benutzer jederzeit den aktuellen Live-Verbindungsstatus an.
|
||||||
+128
-73
@@ -1,87 +1,142 @@
|
|||||||
# Architektur
|
# 🏛️ Systemarchitektur & Technologie-Stack
|
||||||
|
|
||||||
## Überblick
|
Dieses Dokument beschreibt die interne Architektur von MindSift, die Interaktion zwischen den Systemkomponenten, das Concurrency- und Thread-Safety-Modell sowie die Deployment-Strategie.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧩 1. Schichten-Architektur
|
||||||
|
|
||||||
|
MindSift ist als monolithische, hochperformante Single-Binary-Lösung konzipiert. Das Go-Backend liefert sowohl die REST- und WebSocket-Schnittstellen aus als auch die vorkompilierte React Single Page Application (SPA) als eingebettetes statisches Dateisystem (`embed.FS`).
|
||||||
|
|
||||||
```
|
```
|
||||||
Browser (React SPA, PWA-Manifest)
|
┌────────────────────────────────────────────────────────┐
|
||||||
│ REST /api/v1/* Authorization: Bearer <JWT | mindsift_sec_…>
|
│ Frontend (React 18) │
|
||||||
│ WebSocket /api/v1/ws Fallback: SSE /api/v1/events
|
│ Vite • TypeScript • Tailwind CSS • Lucide • Motion │
|
||||||
▼
|
└───────────────────────────┬────────────────────────────┘
|
||||||
Go-Server (chi) ── internal/api Handler, Middleware, Alarm-Ticker
|
│ HTTPS REST / WSS WebSocket
|
||||||
│ internal/ws Hub (Räume, Benutzer-Kanäle, SSE)
|
┌───────────────────────────▼────────────────────────────┐
|
||||||
│ internal/auth JWT, bcrypt, API-Key-Hash
|
│ Go Chi Routing Layer │
|
||||||
▼ internal/config
|
│ CORS • RealIP • Recoverer • Auth / Role Guard │
|
||||||
SQLite (modernc.org/sqlite, WAL) ── internal/storage
|
├───────────────────────────┬────────────────────────────┤
|
||||||
|
│ Business Engine │ Gorilla WebSocket │
|
||||||
|
│ Triage • Tasks • Alarms │ Rooms • Hub • Doc-Locking │
|
||||||
|
├───────────────────────────┴────────────────────────────┤
|
||||||
|
│ Storage Abstraction │
|
||||||
|
│ sqlite.go (modernc.org/sqlite pure Go, WAL-Mode) │
|
||||||
|
└───────────────────────────┬────────────────────────────┘
|
||||||
|
│
|
||||||
|
┌─────────────┴─────────────┐
|
||||||
|
▼ ▼
|
||||||
|
/data/mindsift.db /data/workspace/
|
||||||
|
(SQLite Datenbank) (Physische .md Dateien)
|
||||||
```
|
```
|
||||||
|
|
||||||
Das Frontend liegt per `go:embed` im Binary ([cmd/server/main.go](../cmd/server/main.go)). Unbekannte Pfade liefern `index.html` (SPA-Routing); `index.html`, `sw.js` und `manifest.json` werden mit `no-store` ausgeliefert.
|
---
|
||||||
|
|
||||||
## Stack
|
## 🛠️ 2. Technologie-Stack
|
||||||
|
|
||||||
| Schicht | Technik |
|
### Backend (Go 1.23)
|
||||||
|---|---|
|
- **HTTP Routing:** [`github.com/go-chi/chi/v5`](https://github.com/go-chi/chi) – Minimalistischer, idiomatisch schneller Router mit Middleware-Ketten.
|
||||||
| Backend | Go 1.23, `go-chi/chi` v5, `go-chi/cors`, `gorilla/websocket`, `golang-jwt/jwt` v5, `x/crypto/bcrypt` |
|
- **WebSocket Hub:** [`github.com/gorilla/websocket`](https://github.com/gorilla/websocket) – Verbindungs-Upgrade, Keep-Alive/Ping-Pong und Room-Multiplexing.
|
||||||
| Datenbank | SQLite über `modernc.org/sqlite` (reines Go, kein CGO), WAL, `foreign_keys=ON` |
|
- **Datenbank-Treiber:** [`modernc.org/sqlite`](https://gitlab.com/cznic/sqlite) – CGO-freier, rein in Go übersetzter SQLite-Treiber für einfache plattformübergreifende Kompilierung und Containerisierung ohne GCC-Toolchain.
|
||||||
| Frontend | React 18, TypeScript, Vite 5, Tailwind 3, framer-motion (Triage-Karten), lucide-react, prismjs (Code-Blöcke) |
|
- **Authentifizierung:** [`github.com/golang-jwt/jwt/v5`](https://github.com/golang-jwt/jwt) (HMAC-SHA256 Token) und [`golang.org/x/crypto/bcrypt`](https://pkg.go.dev/golang.org/x/crypto/bcrypt) für Passwort-Hashing.
|
||||||
| Auslieferung | Mehrstufiges Dockerfile (Node 22 → Go 1.23 → Alpine 3.21), Image `git.dsit.me/sandrodach/mindsift` |
|
|
||||||
|
|
||||||
## Verzeichnisse
|
### Frontend (React 18 SPA)
|
||||||
|
- **Build-Tool:** [Vite 5](https://vitejs.dev/) für schnelles Hot-Module-Replacement (HMR) und optimierte Production-Bundles.
|
||||||
|
- **Sprache:** TypeScript 5 mit strikter Typisierung.
|
||||||
|
- **Design & Layout:** [Tailwind CSS 3](https://tailwindcss.com/) in Verbindung mit dem MindSift Single-File CSS Theming System.
|
||||||
|
- **Icons & Animationen:** [Lucide React](https://lucide.dev/) und [Framer Motion](https://www.framer.com/motion/) für Gesten, Karten-Swipes und Übergänge.
|
||||||
|
|
||||||
| Pfad | Inhalt |
|
---
|
||||||
|---|---|
|
|
||||||
| `cmd/server/` | `main.go`, eingebettetes `dist/` |
|
|
||||||
| `internal/api/` | `server.go` (Routen, Handler, Alarm-Ticker, SMTP/Discord/Webhook-Versand) |
|
|
||||||
| `internal/storage/` | `sqlite.go` (Schema, Migrationen, gesamte Datenlogik) |
|
|
||||||
| `internal/domain/` | Strukturen (`models.go`), ID-Erzeugung, Tag-Extraktion |
|
|
||||||
| `internal/ws/` | `hub.go` |
|
|
||||||
| `internal/auth/` | Tokens und Passwörter |
|
|
||||||
| `internal/config/` | Umgebungsvariablen |
|
|
||||||
| `frontend/src/features/` | `triage`, `workspace`, `lists`, `teams`, `settings`, `capture`, `auth`, `help` |
|
|
||||||
| `frontend/src/lib/` | `api.ts` (REST-Client, Transport-Umschaltung WS/SSE), `types.ts`, `markdown.tsx`, `theme.ts` |
|
|
||||||
| `frontend/src/themes/` | CSS pro Theme |
|
|
||||||
|
|
||||||
## Start und Laufzeit
|
## 📁 3. Verzeichnisstruktur des Projekts
|
||||||
|
|
||||||
1. `config.Load()` liest die Umgebung (siehe unten).
|
|
||||||
2. `storage.NewStore()` öffnet SQLite (`busy_timeout`, WAL, max. 8 Verbindungen) und führt `migrate()` aus.
|
|
||||||
3. SMTP-Werte aus der Umgebung werden in `system_settings` übernommen, sofern dort noch nichts steht.
|
|
||||||
4. Mit Demo-Flag legt `EnsureDemoAccounts` die Konten `admin/admin` und `user/user` an.
|
|
||||||
5. `api.NewServer` startet den **Alarm-Ticker** (jede Minute) und baut den Router. Server-Timeouts: Lesen 15 s, Schreiben 30 s, Leerlauf 60 s. Beim Beenden wird sauber heruntergefahren.
|
|
||||||
|
|
||||||
## Konfiguration
|
|
||||||
|
|
||||||
| Variable | Standard | Bedeutung |
|
|
||||||
|---|---|---|
|
|
||||||
| `PORT` | `8080` | HTTP-Port |
|
|
||||||
| `DATA_DIR` | `./data` (Container: `/data`) | Verzeichnis der Datenbank |
|
|
||||||
| `DATABASE_URL` | leer | `sqlite:///pfad/datei.db` oder Pfad; ohne Angabe `DATA_DIR/mindsift.db`. Postgres-URLs werden **nicht** unterstützt (siehe Hinweis) |
|
|
||||||
| `JWT_SECRET` | festes Fallback (unsicher!) | Signaturschlüssel der Tokens; unbedingt setzen, siehe [FLAW-04](flaws.md) |
|
|
||||||
| `BASE_URL` | `http://localhost:<PORT>` | Basis-URL der Instanz |
|
|
||||||
| `ALLOW_REGISTRATION` | `false` | Startwert; die Einstellung im Admin-UI (`system_settings`) hat Vorrang |
|
|
||||||
| `LOG_LEVEL` / `DEBUG` | `info` / `false` | `debug`, `info`, `warn`, `error`; `DEBUG=true` erzwingt `debug` |
|
|
||||||
| `MINDA_DEMO` (auch `MINDSIFT_DEMO`, `DEMO_MODE`) | `false` | Demo-Konten anlegen |
|
|
||||||
| `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASS`, `SMTP_FROM`, `SMTP_TLS` | leer / `587` / `true` | Mailversand, auch im Admin-UI einstellbar |
|
|
||||||
|
|
||||||
Hinweis: `DATABASE_URL` mit `postgres…` führt dazu, dass der Standardpfad in `DATA_DIR` genutzt wird; Postgres ist nicht implementiert.
|
|
||||||
|
|
||||||
## Authentifizierung
|
|
||||||
|
|
||||||
- **Login** mit E-Mail, Benutzername (aus dem E-Mail-Präfix) oder `login`. Passwörter: bcrypt (`DefaultCost`).
|
|
||||||
- **JWT:** HS256, Laufzeit 30 Tage, Claims `userId`, `email`, `displayName`, `tokenVersion`, `jti`. Gültig nur, wenn Token nicht in `revoked_tokens` steht, das Konto aktiv ist und `tokenVersion` mit `users.token_version` übereinstimmt. `token_version` wird bei Passwortänderung, Rollenwechsel, Deaktivierung und „Alle Sitzungen beenden“ erhöht.
|
|
||||||
- **Logout** schreibt den Token-Hash in `revoked_tokens`.
|
|
||||||
- **API-Keys:** `mindsift_sec_<hex>`, gespeichert als SHA-256, nur das Präfix bleibt sichtbar. Der Key gilt als Bearer-Token oder in `X-API-Key` und authentifiziert als Besitzer ([FLAW-07](flaws.md)).
|
|
||||||
- **Registrierung:** nur mit Einladungscode oder wenn `allow_registration` aktiv ist. Das erste Konto entsteht über `/auth/setup` und wird Administrator.
|
|
||||||
|
|
||||||
## Hintergrundjob: Alarme
|
|
||||||
|
|
||||||
`startAlarmTicker` prüft jede Minute alle offenen, noch nicht gemeldeten Aufgaben mit Fälligkeit. Ist `due_date <= heute` (Serverzeit), sendet er über die Kanäle des Benutzers (`email`, `discord`, `webhook`) und setzt `alarm_sent`, sobald mindestens ein Kanal erfolgreich war. Details und Einschränkungen: [modules/tasks.md](modules/tasks.md), [FLAW-12](flaws.md).
|
|
||||||
|
|
||||||
## Build
|
|
||||||
|
|
||||||
```
|
```
|
||||||
Stage 1 node:22-alpine npm ci && npm run build → frontend/dist
|
MindSift/
|
||||||
Stage 2 golang:1.23 go vet, go test, go build → /app/mindsift (dist wird eingebettet)
|
├── cmd/
|
||||||
Stage 3 alpine:3.21 nur Binary, ca-certificates, tzdata
|
│ └── server/
|
||||||
|
│ └── main.go # Einstiegspunkt: Initialisierung, Config, Store, Start
|
||||||
|
├── internal/
|
||||||
|
│ ├── api/
|
||||||
|
│ │ ├── server.go # HTTP-Routen, Handler-Methoden, Middleware
|
||||||
|
│ │ └── server_test.go # Integrationstests für alle REST- und Ingest-Routen
|
||||||
|
│ ├── auth/
|
||||||
|
│ │ ├── auth.go # JWT Validierung, Token-Erstellung, Context-Helpers
|
||||||
|
│ │ └── apikey.go # API-Key Erzeugung (mindsift_sec_...) & SHA-256 Hashing
|
||||||
|
│ ├── config/
|
||||||
|
│ │ └── config.go # Environment-Variablen (PORT, DATA_DIR, JWT_SECRET, SMTP)
|
||||||
|
│ ├── domain/
|
||||||
|
│ │ └── models.go # Go-Structs für Thought, Document, List, User, Team etc.
|
||||||
|
│ ├── storage/
|
||||||
|
│ │ ├── sqlite.go # DB-Schema, CRUD-Operationen, Queries, Migrationen
|
||||||
|
│ │ └── storage_test.go # Unit-Tests für Speicheroperationen
|
||||||
|
│ └── ws/
|
||||||
|
│ └── hub.go # WebSocket Client, Room-Management, Locking-Mechanismus
|
||||||
|
├── frontend/
|
||||||
|
│ ├── src/
|
||||||
|
│ │ ├── components/ # Wiederverwendbare UI-Elemente (Modals, Avatar, Menüs)
|
||||||
|
│ │ ├── context/ # MobileActionContext (Mobile Bottom Bar State)
|
||||||
|
│ │ ├── features/
|
||||||
|
│ │ │ ├── auth/ # SetupWizard & Login
|
||||||
|
│ │ │ ├── capture/ # InstantCaptureBar (Schnelleingabe)
|
||||||
|
│ │ │ ├── help/ # Integrierte Benutzerdokumentation
|
||||||
|
│ │ │ ├── lists/ # Geteilte Listen & Einkauf
|
||||||
|
│ │ │ ├── settings/ # Benutzer-, Admin- & Theme-Einstellungen
|
||||||
|
│ │ │ ├── teams/ # Gruppen & Mitglieder-Management
|
||||||
|
│ │ │ ├── triage/ # Triage-Deck, Aufgabenliste, Kanban & TaskModal
|
||||||
|
│ │ │ └── workspace/ # Outliner-Editor, Datei-Explorer, Wiki & Rollup
|
||||||
|
│ │ ├── lib/ # api.ts (HTTP/WS Client), types.ts, theme.ts
|
||||||
|
│ │ ├── themes/ # Eigenständige Theme CSS-Dateien (dark, light, etc.)
|
||||||
|
│ │ ├── App.tsx # Root-Komponente, Navigation, Top/Bottom Bars
|
||||||
|
│ │ └── main.tsx # React DOM Bootstrap
|
||||||
|
│ ├── package.json
|
||||||
|
│ └── vite.config.ts
|
||||||
|
├── Doku/ # Dieses technische Wiki
|
||||||
|
├── Dockerfile # Multi-Stage Build Definition
|
||||||
|
└── compose.yaml # Docker Compose Vorlage für Produktivbetrieb
|
||||||
```
|
```
|
||||||
|
|
||||||
Die Tests laufen beim Image-Build (`go test -v ./...`); ein Fehler bricht den Build ab. Frontend-Tests existieren nicht ([FLAW-19](flaws.md)).
|
---
|
||||||
|
|
||||||
|
## ⚡ 4. Thread-Safety & Concurrency-Modell
|
||||||
|
|
||||||
|
Da SQLite Datei-basiert arbeitet und Go standardmäßig hochgradig nebenläufig (Multi-Threaded via Goroutines) operiert, sind folgende Schutzmaßnahmen implementiert:
|
||||||
|
|
||||||
|
### 1. SQLite Pragmas & WAL-Modus
|
||||||
|
Im Storage-Layer ([`internal/storage/sqlite.go`](../internal/storage/sqlite.go)) wird die Datenbankverbindung beim Start zwingend mit folgenden DSN-Pragmas konfiguriert:
|
||||||
|
```go
|
||||||
|
dsn := filepath.Join(dataDir, "mindsift.db") +
|
||||||
|
"?_pragma=busy_timeout(10000)&" +
|
||||||
|
"_pragma=journal_mode(WAL)&" +
|
||||||
|
"_pragma=synchronous(NORMAL)&" +
|
||||||
|
"_pragma=foreign_keys(1)"
|
||||||
|
```
|
||||||
|
- **`journal_mode(WAL)`:** Write-Ahead Logging erlaubt parallele Leser (`SELECT`), während ein Schreiber (`INSERT`/`UPDATE`) aktiv ist. Leser blockieren niemals Schreiber und Schreiber blockieren niemals Leser.
|
||||||
|
- **`busy_timeout(10000)`:** Sollte ein Schreibvorgang kurzzeitig blockiert sein, wartet SQLite bis zu 10.000 ms (10 Sekunden), bevor ein `SQLITE_BUSY` Fehler geworfen wird.
|
||||||
|
- **`foreign_keys(1)`:** Erzwingt referenzielle Integrität und automatische Kaskadierungs-Löschungen (`ON DELETE CASCADE`).
|
||||||
|
|
||||||
|
### 2. Connection Pool Begrenzung
|
||||||
|
SQLite unterstützt nur einen einzigen Schreib-Thread zur gleichen Zeit:
|
||||||
|
```go
|
||||||
|
db.SetMaxOpenConns(8)
|
||||||
|
db.SetMaxIdleConns(4)
|
||||||
|
db.SetConnMaxLifetime(time.Hour)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Cursor-Deadlock-Vermeidung
|
||||||
|
> **Kritische Backend-Regel:** Niemals verschachtelte Abfragen bei offenem `*sql.Rows`-Cursor ausführen!
|
||||||
|
In Go hält ein offener Cursor eine Verbindung aus dem Pool besetzt. Führt der Code innerhalb von `for rows.Next()` eine weitere Abfrage auf `s.db` aus, kann der Connection-Pool bei mehreren parallelen Benutzern innerhalb von Millisekunden einfrieren.
|
||||||
|
*Pattern:* Alle Zeilen werden sofort vollständig in ein Go-Slice gelesen, `rows.Close()` wird ausgeführt, und erst danach werden verknüpfte Entitäten geladen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🌐 5. Deployment & Container-Architektur
|
||||||
|
|
||||||
|
MindSift wird als schlanker, autarker Docker-Container ausgeliefert:
|
||||||
|
1. **Stage 1 (Frontend Build):** `node:20-alpine` kompiliert TypeScript und generiert statische Assets nach `frontend/dist/`.
|
||||||
|
2. **Stage 2 (Backend Build):** `golang:1.23-alpine` bettet `frontend/dist/` via `//go:embed` ein, führt Unit-Tests aus und kompiliert ein statisches Binary (`mindsift-server`).
|
||||||
|
3. **Stage 3 (Production Runtime):** `alpine:3.20` mit `ca-certificates` und `tzdata`. Das finale Image ist ca. 45 MB groß und benötigt keine externen Datenbankserver oder Abhängigkeiten.
|
||||||
|
|
||||||
|
Alle persistenten Daten befinden sich in einem einzigen Verzeichnis `/data`:
|
||||||
|
- `/data/mindsift.db` (SQLite Hauptdatenbank)
|
||||||
|
- `/data/workspace/` (Physische Markdown-Dateien der Workspace-Notizen)
|
||||||
+333
-68
@@ -1,83 +1,348 @@
|
|||||||
# Datenbank
|
# 🗄️ Datenbank-Design & SQLite Schema
|
||||||
|
|
||||||
SQLite-Datei `mindsift.db` (Standard: `$DATA_DIR/mindsift.db`), geöffnet mit `journal_mode=WAL`, `synchronous=NORMAL`, `foreign_keys=ON`, `busy_timeout=10000` und höchstens 8 Verbindungen. Das Schema entsteht in `Store.migrate()` ([sqlite.go](../internal/storage/sqlite.go)): zuerst `CREATE TABLE IF NOT EXISTS`, danach eine Liste idempotenter `ALTER TABLE`/`CREATE`-Anweisungen für ältere Datenbanken. IDs sind Text mit Präfix (`usr_…`, `th_…`, `tkl_…`, `lst_…`, `tls_…`, `blk_…`, `doc_…`).
|
MindSift verwendet als persistente Datenspeicherung eine lokale SQLite-Datenbank (`/data/mindsift.db`). Dieses Dokument beschreibt das relationale Datenmodell, Tabellenstrukturen, Indizes, Fremdschlüsselbeziehungen und das Migrationskonzept.
|
||||||
|
|
||||||
Die Datei `migrations/001_init.sql` wird vom Code **nicht** gelesen und ist veraltet ([FLAW-13](flaws.md)).
|
---
|
||||||
|
|
||||||
## Tabellen
|
## 📊 1. Entity-Relationship-Diagramm (ERD)
|
||||||
|
|
||||||
### Benutzer und Zugang
|
```mermaid
|
||||||
| Tabelle | Zweck | Wichtige Spalten |
|
erDiagram
|
||||||
|---|---|---|
|
users ||--o{ thoughts : "erstellt"
|
||||||
| `users` | Konten | `email` (eindeutig), `username`, `password_hash`, `display_name`, `role` (`admin`/`member`), `is_active`, `token_version`, `alarm_channels` (kommagetrennt), `alarm_email`, `discord_webhook_url`, `custom_webhook_url`, `notify_before_minutes`, `avatar_url` |
|
users ||--o{ documents : "besitzt"
|
||||||
| `user_invites` | Einladungscodes | `code`, `email`, `role`, `team_id`, `expires_at`, `used_by` |
|
users ||--o{ lists : "besitzt"
|
||||||
| `revoked_tokens` | Sperrliste ausgeloggter JWTs | `token_hash`, `expires_at` |
|
users ||--o{ task_lists : "besitzt"
|
||||||
| `api_keys` | Webhook-/API-Schlüssel | `key_prefix`, `key_hash` (SHA-256), `scopes` (nicht ausgewertet), `last_used_at` |
|
users ||--o{ api_keys : "besitzt"
|
||||||
| `system_settings` | Schlüssel/Wert für Instanz-Einstellungen | `sharing_mode`, `allow_registration`, `instance_name`, `smtp_*` |
|
users ||--o{ team_members : "ist Mitglied in"
|
||||||
|
|
||||||
### Gedanken und Aufgaben
|
teams ||--o{ team_members : "besteht aus"
|
||||||
| Tabelle | Zweck | Wichtige Spalten |
|
teams ||--o{ task_list_shares : "erhält Zugriff"
|
||||||
|---|---|---|
|
teams ||--o{ list_shares : "erhält Zugriff"
|
||||||
| `thoughts` | Gedanken **und** Aufgaben in einer Tabelle | `status` (`inbox`/`kept`/`converted`/`discarded`), `converted_type` (`task`/`document`/`list_item`/`document_block`), `converted_ref_id`, `priority`, `is_completed`, `due_date` (nur Datum), `task_list_id`, `kanban_status`, `notes`, `subtasks` (JSON), `tags` (JSON), `alarm_sent`, `sort_order`, `source` (`manual`, `voice`, `webhook` …) |
|
teams ||--o{ doc_team_shares : "erhält Zugriff"
|
||||||
| `task_lists` | Aufgabenlisten | `user_id` (Eigentümer), `team_id` (Altfeld), `title`, `icon`, `color`, `columns` (JSON, Kanban-Spalten) |
|
teams ||--o{ workspace_folder_shares : "erhält Zugriff"
|
||||||
| `task_list_shares` | Freigaben von Aufgabenlisten | `target_type` (`team`/`user`), `target_id`, **`permission`** (`editor`/`viewer`, Standard `editor`) |
|
|
||||||
|
|
||||||
Eine Aufgabe ist ein `thought` mit `status='kept'` oder `status='converted' AND converted_type='task'`. Aufgaben, die aus einem Notiz-Block entstehen, tragen `converted_type='document_block'` und `converted_ref_id='<docId>:<blockId>'`.
|
task_lists ||--o{ thoughts : "gruppiert"
|
||||||
|
task_lists ||--o{ task_list_shares : "wird geteilt mit"
|
||||||
|
|
||||||
### Workspace
|
lists ||--o{ list_items : "enthält"
|
||||||
| Tabelle | Zweck |
|
lists ||--o{ list_shares : "wird geteilt mit"
|
||||||
|---|---|
|
|
||||||
| `documents` | Notizen: `title`, `icon`, `folder_path`, `tags` (JSON), `is_archived`, `markdown_cache`, `shared_folder_id`, `sub_folder_path`, Altspalten `content`, `blocks_json` |
|
|
||||||
| `blocks` | Outliner-Blöcke: `document_id`, `type`, `content`, `level`, `position` (REAL), `checked`, `collapsed`, `lang` |
|
|
||||||
| `block_tags` | `#Hashtags` je Block (`tag`, `document_id`, `block_id`) |
|
|
||||||
| `tag_pages` | Freitext-Notiz je Benutzer und Tag |
|
|
||||||
| `doc_pins` | Favoriten je Benutzer |
|
|
||||||
| `doc_shares`, `doc_team_shares` | Notiz-Freigaben an Benutzer bzw. Gruppen (`permission` effektiv immer `read`) |
|
|
||||||
| `workspace_folders` | Explizit angelegte Ordnerpfade |
|
|
||||||
| `workspace_shared_folders` | Geteilte Ordner (Entität mit Eigentümer) |
|
|
||||||
| `workspace_folder_shares` | Freigaben geteilter Ordner |
|
|
||||||
| `workspace_folder_mounts` | Persönlicher Einhängepfad je Empfänger und geteiltem Ordner |
|
|
||||||
| `doc_user_folders` | Persönliche Ablage einer geteilten Einzelnotiz je Empfänger |
|
|
||||||
|
|
||||||
Blocktypen: `h1`, `h2`, `h3`, `paragraph`, `text`, `todo`, `bullet`, `code`, `callout`, `divider`, `table`, `progress`.
|
documents ||--o{ document_blocks : "besteht aus"
|
||||||
|
documents ||--o{ doc_shares : "geteilt mit Benutzern"
|
||||||
|
documents ||--o{ doc_team_shares : "geteilt mit Teams"
|
||||||
|
documents ||--o{ doc_user_folders : "eigene Platzierung"
|
||||||
|
documents ||--o{ doc_pins : "Favorit von"
|
||||||
|
|
||||||
### Listen
|
workspace_shared_folders ||--o{ workspace_folder_shares : "wird geteilt mit"
|
||||||
| Tabelle | Zweck |
|
workspace_shared_folders ||--o{ workspace_folder_mounts : "eingehängt bei"
|
||||||
|---|---|
|
workspace_shared_folders ||--o{ documents : "enthält"
|
||||||
| `lists` | Geteilte Listen: `title`, `icon`, `list_type` (`shopping`/`checklist`/`vacation`) |
|
|
||||||
| `list_shares` | Freigaben: `target_type`, `target_id`, `role` (`editor`/`viewer`) |
|
|
||||||
| `list_items` | Einträge: `content`, `category`, `quantity`, `is_completed`, `completed_by(_name)`, `sort_order` |
|
|
||||||
|
|
||||||
### Gruppen
|
|
||||||
| Tabelle | Zweck |
|
|
||||||
|---|---|
|
|
||||||
| `teams` | `name`, `description`, `org_id` (Standard `default`) |
|
|
||||||
| `team_members` | `team_id`, `user_id`, `role` (`admin`/`member`) |
|
|
||||||
| `organizations` | Rudimentär; wird vom UI nicht mehr benötigt ([FLAW-24](flaws.md)) |
|
|
||||||
|
|
||||||
## Beziehungen
|
|
||||||
|
|
||||||
```
|
|
||||||
users 1─n thoughts thoughts n─1 task_lists (task_list_id, lose)
|
|
||||||
users 1─n task_lists task_lists 1─n task_list_shares ─(team|user)→ teams/users
|
|
||||||
users 1─n documents 1─n blocks 1─n block_tags
|
|
||||||
documents n─n users via doc_shares / doc_team_shares (nur Lesen)
|
|
||||||
workspace_shared_folders 1─n workspace_folder_shares / workspace_folder_mounts
|
|
||||||
users 1─n lists 1─n list_items; lists 1─n list_shares
|
|
||||||
teams 1─n team_members n─1 users
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`thoughts.task_list_id` ist keine Fremdschlüsselbeziehung; beim Löschen einer Liste setzt der Code die Verweise auf `''`.
|
---
|
||||||
|
|
||||||
## Migrationen und Aufräumarbeiten beim Start
|
## 📑 2. Detaillierte Tabellen-Spezifikation
|
||||||
|
|
||||||
- Spalten/Tabellen/Indizes werden nachgezogen (`ALTER TABLE … ADD COLUMN`, Fehler werden ignoriert).
|
### 2.1 Benutzerverwaltung, System & Sicherheit
|
||||||
- Veraltete Tabellen werden gelöscht: `spaces`, `space_members`, `space_team_shares`, `document_crdt_state`, `document_crdt_updates`, `document_blocks`, `doc_block_tags`.
|
|
||||||
- `users.username` wird aus dem E-Mail-Präfix aufgefüllt.
|
|
||||||
- Alle Dokument-, Team- und Ordnerfreigaben werden auf `read` gesetzt (bei **jedem** Start, siehe [FLAW-17](flaws.md)).
|
|
||||||
- Standardwerte in `system_settings` (`INSERT OR IGNORE`): `sharing_mode=teams_only`, `allow_registration=false`, `instance_name=MindSift`, SMTP leer.
|
|
||||||
- Die Tabelle `teams` wird einmalig ohne Fremdschlüssel auf `organizations` neu aufgebaut.
|
|
||||||
|
|
||||||
## Sicherung
|
#### `users`
|
||||||
|
Verwaltet Konten, Rollen, Multi-Channel Alarmziele und Benutzerpräferenzen.
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "usr_..."
|
||||||
|
email TEXT UNIQUE NOT NULL, -- E-Mail-Adresse
|
||||||
|
username TEXT NOT NULL DEFAULT '', -- Eindeutiger Login-Name
|
||||||
|
password_hash TEXT NOT NULL, -- bcrypt Hash
|
||||||
|
display_name TEXT NOT NULL, -- Anzeigename
|
||||||
|
avatar_url TEXT NOT NULL DEFAULT '', -- Profilbild URL oder leer
|
||||||
|
role TEXT NOT NULL DEFAULT 'member', -- 'admin' | 'member'
|
||||||
|
is_active INTEGER NOT NULL DEFAULT 1, -- 1 = aktiv, 0 = gesperrt
|
||||||
|
alarm_channels TEXT NOT NULL DEFAULT 'discord', -- Kommagetrennt: 'email', 'discord', 'webhook'
|
||||||
|
alarm_email TEXT NOT NULL DEFAULT '', -- Ziel-E-Mail für Alarme
|
||||||
|
discord_webhook_url TEXT NOT NULL DEFAULT '', -- Discord Webhook URL
|
||||||
|
custom_webhook_url TEXT NOT NULL DEFAULT '', -- HTTP POST JSON Webhook URL
|
||||||
|
notify_before_minutes INTEGER NOT NULL DEFAULT 30, -- Vorwarnzeit in Minuten
|
||||||
|
created_at TEXT NOT NULL, -- ISO 8601 String
|
||||||
|
updated_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
|
||||||
|
```
|
||||||
|
|
||||||
Die gesamte Instanz besteht aus der Datei `mindsift.db` (plus `-wal`/`-shm` im laufenden Betrieb). Konsistent sichern per `sqlite3 mindsift.db ".backup 'backup.db'"` oder durch Stoppen des Containers und Kopieren des `data/`-Verzeichnisses. Benutzerexport: `GET /api/v1/export` (JSON mit Gedanken, Notizen, Listen, Aufgabenlisten).
|
#### `system_settings`
|
||||||
|
Globale Instanz-Konfiguration (Key-Value-Tabelle).
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS system_settings (
|
||||||
|
key TEXT PRIMARY KEY, -- 'sharing_mode', 'allow_registration', 'instance_name', 'smtp_...'
|
||||||
|
value TEXT NOT NULL
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `user_invites`
|
||||||
|
Einladungscodes für kontrollierte Benutzer-Registrierungen.
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS user_invites (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "inv_..."
|
||||||
|
code TEXT UNIQUE NOT NULL, -- Format "MS-XXXXXXXX"
|
||||||
|
email TEXT DEFAULT '', -- Optional: an bestimmte E-Mail gebunden
|
||||||
|
role TEXT NOT NULL DEFAULT 'member', -- Rolle des neuen Kontos ('member', 'admin')
|
||||||
|
created_by TEXT NOT NULL, -- Ersteller User-ID
|
||||||
|
used_by TEXT DEFAULT '', -- Eingelöste User-ID
|
||||||
|
expires_at TEXT NOT NULL, -- Gültig bis (ISO 8601)
|
||||||
|
created_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_user_invites_code ON user_invites(code);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `api_keys`
|
||||||
|
Persönliche API-Schlüssel für externe Skripte, Smarthome und Ingestion.
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS api_keys (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "key_..."
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
name TEXT NOT NULL, -- Bezeichnung (z.B. "Home Assistant")
|
||||||
|
key_prefix TEXT NOT NULL, -- Erste 12 Zeichen im Klartext für Anzeige
|
||||||
|
key_hash TEXT UNIQUE NOT NULL, -- SHA-256 Hash des kompletten Schlüssels
|
||||||
|
scopes TEXT NOT NULL DEFAULT 'ingest,read',
|
||||||
|
last_used_at TEXT NOT NULL DEFAULT '',
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2.2 Gruppen & Organisations-Teams
|
||||||
|
|
||||||
|
#### `organizations` & `teams` & `team_members`
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS organizations (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "org_..."
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
owner_id TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
FOREIGN KEY(owner_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS teams (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "tm_..."
|
||||||
|
org_id TEXT NOT NULL DEFAULT 'default',
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
description TEXT NOT NULL DEFAULT '',
|
||||||
|
created_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS team_members (
|
||||||
|
team_id TEXT NOT NULL,
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
role TEXT NOT NULL DEFAULT 'member', -- 'admin' | 'member'
|
||||||
|
joined_at TEXT NOT NULL,
|
||||||
|
PRIMARY KEY (team_id, user_id),
|
||||||
|
FOREIGN KEY(team_id) REFERENCES teams(id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2.3 Gedanken, Triage & Aufgaben
|
||||||
|
|
||||||
|
In MindSift nutzen Quick Dumps (Triage) und Aufgaben dieselbe Basistabelle **`thoughts`**. Ein Quick Dump ist ein Gedanke mit `status = 'inbox'`, der durch Triage in `status = 'kept'` oder `status = 'converted'` übergeht.
|
||||||
|
|
||||||
|
#### `thoughts`
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS thoughts (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "th_..."
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
content TEXT NOT NULL, -- Textinhalt inkl. Hashtags
|
||||||
|
tags TEXT NOT NULL DEFAULT '[]', -- JSON Array: ["smarthome", "keller"]
|
||||||
|
priority TEXT NOT NULL DEFAULT 'normal', -- 'low' | 'normal' | 'high' | 'urgent'
|
||||||
|
source TEXT NOT NULL DEFAULT 'manual', -- 'manual' | 'voice' | 'webhook'
|
||||||
|
status TEXT NOT NULL DEFAULT 'inbox', -- 'inbox' | 'kept' | 'discarded' | 'converted'
|
||||||
|
is_completed INTEGER NOT NULL DEFAULT 0, -- 0 = offen, 1 = erledigt
|
||||||
|
converted_type TEXT DEFAULT '', -- 'task' | 'document' | 'list_item'
|
||||||
|
converted_ref_id TEXT DEFAULT '', -- Verknüpfte ID (z.B. doc_id oder list_item_id)
|
||||||
|
due_date TEXT DEFAULT '', -- Fälligkeitsdatum "YYYY-MM-DD"
|
||||||
|
task_list_id TEXT NOT NULL DEFAULT '', -- Zugeordnete Aufgabenliste ("" = Standard)
|
||||||
|
kanban_status TEXT NOT NULL DEFAULT 'todo',-- 'todo' | 'in_progress' | 'done' | column.id
|
||||||
|
notes TEXT NOT NULL DEFAULT '', -- Zusätzliche Notizen / Beschreibung
|
||||||
|
subtasks TEXT NOT NULL DEFAULT '[]', -- JSON Array von SubTask: [{id, title, isCompleted}]
|
||||||
|
alarm_sent INTEGER NOT NULL DEFAULT 0, -- 1 = Alarm wurde bereits versendet
|
||||||
|
sort_order INTEGER NOT NULL DEFAULT 0, -- Manuelle Reorder-Sortierung
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
triaged_at TEXT DEFAULT '',
|
||||||
|
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_thoughts_user_status ON thoughts(user_id, status, created_at DESC);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_thoughts_list_sort ON thoughts(task_list_id, sort_order ASC, created_at DESC);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `task_lists` & `task_list_shares`
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS task_lists (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "tl_..."
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
icon TEXT NOT NULL DEFAULT '📋',
|
||||||
|
color TEXT NOT NULL DEFAULT '#3b82f6',
|
||||||
|
team_id TEXT NOT NULL DEFAULT '', -- Optional: an Team gebunden
|
||||||
|
columns TEXT NOT NULL DEFAULT '[]', -- JSON Array von Kanban-Spalten
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
updated_at TEXT NOT NULL,
|
||||||
|
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS task_list_shares (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
task_list_id TEXT NOT NULL,
|
||||||
|
target_type TEXT NOT NULL CHECK(target_type IN ('team', 'user')),
|
||||||
|
target_id TEXT NOT NULL, -- Team-ID oder User-ID
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
created_by TEXT NOT NULL,
|
||||||
|
UNIQUE(task_list_id, target_type, target_id),
|
||||||
|
FOREIGN KEY(task_list_id) REFERENCES task_lists(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2.4 Workspace: Dokumente, Blöcke & Geteilte Ordner
|
||||||
|
|
||||||
|
#### `documents` & `document_blocks` (Database-First Outliner)
|
||||||
|
Dokumente werden als Kopfdatensatz in `documents` gespeichert, während der Inhalt als feingranulare Blöcke in `document_blocks` verwaltet wird. Zusätzlich spiegelt MindSift die Daten synchron als physische `.md`-Datei auf Festplatte.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS documents (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "doc_..."
|
||||||
|
user_id TEXT NOT NULL, -- Eigentümer
|
||||||
|
title TEXT NOT NULL, -- Dokumenttitel
|
||||||
|
icon TEXT NOT NULL DEFAULT '📄', -- Emoji-Icon
|
||||||
|
content TEXT NOT NULL DEFAULT '', -- Markdown-Volltext (Spiegelung)
|
||||||
|
blocks_json TEXT NOT NULL DEFAULT '[]', -- Legacy JSON-Cache
|
||||||
|
tags TEXT NOT NULL DEFAULT '[]', -- JSON Array von Tags
|
||||||
|
folder_path TEXT NOT NULL DEFAULT '', -- Relativer Ordnerpfad des Eigentümers
|
||||||
|
shared_folder_id TEXT NOT NULL DEFAULT '', -- ID aus workspace_shared_folders (wenn in geteiltem Ordner)
|
||||||
|
sub_folder_path TEXT NOT NULL DEFAULT '', -- Relativer Unterordnerpfad innerhalb des geteilten Ordners
|
||||||
|
is_pinned INTEGER NOT NULL DEFAULT 0, -- Globaler Pin
|
||||||
|
is_archived INTEGER NOT NULL DEFAULT 0,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
updated_at TEXT NOT NULL,
|
||||||
|
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_documents_user ON documents(user_id, is_archived, updated_at DESC);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_documents_shared_folder ON documents(shared_folder_id);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS document_blocks (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "blk_..."
|
||||||
|
doc_id TEXT NOT NULL,
|
||||||
|
sort_order REAL NOT NULL DEFAULT 0, -- Fließkommazahl für konfliktfreies Einfügen
|
||||||
|
type TEXT NOT NULL DEFAULT 'bullet', -- 'bullet', 'todo', 'h1', 'h2', 'h3', 'code', 'quote', 'callout', 'divider'
|
||||||
|
content TEXT NOT NULL DEFAULT '', -- Textinhalt des Blocks
|
||||||
|
level INTEGER NOT NULL DEFAULT 0, -- Hierarchieebene (0 = Root, 1 = Kind...)
|
||||||
|
checked INTEGER NOT NULL DEFAULT 0, -- Für Checklisten (0 = offen, 1 = abgehakt)
|
||||||
|
collapsed INTEGER NOT NULL DEFAULT 0, -- Für eingeklappte Unterbäume
|
||||||
|
lang TEXT NOT NULL DEFAULT '', -- Programmiersprache für Codeblöcke
|
||||||
|
updated_at TEXT NOT NULL,
|
||||||
|
updated_by TEXT NOT NULL DEFAULT '',
|
||||||
|
FOREIGN KEY(doc_id) REFERENCES documents(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_document_blocks_doc_order ON document_blocks(doc_id, sort_order);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Entkoppelte Ordner-Freigabe (`workspace_shared_folders` & `workspace_folder_mounts`)
|
||||||
|
Ermöglicht das Teilen kompletter Ordnerstrukturen. Verschiebt ein Empfänger den geteilten Ordner in seiner Hierarchie, wird **nur sein Mount-Pfad** aktualisiert – die Quellstruktur beim Eigentümer und anderen Empfängern bleibt unberührt!
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS workspace_shared_folders (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "wsf_..."
|
||||||
|
owner_id TEXT NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
updated_at TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS workspace_folder_shares (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
folder_id TEXT NOT NULL,
|
||||||
|
target_type TEXT NOT NULL CHECK(target_type IN ('team', 'user')),
|
||||||
|
target_id TEXT NOT NULL,
|
||||||
|
permission TEXT NOT NULL CHECK(permission IN ('read', 'write')),
|
||||||
|
created_by TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
UNIQUE(folder_id, target_type, target_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS workspace_folder_mounts (
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
folder_id TEXT NOT NULL,
|
||||||
|
mount_path TEXT NOT NULL, -- Eigener lokaler Pfad des Benutzers (z.B. "Arbeit/Projekte/Team-Docs")
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
updated_at TEXT NOT NULL,
|
||||||
|
PRIMARY KEY(user_id, folder_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS doc_user_folders (
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
doc_id TEXT NOT NULL,
|
||||||
|
folder_path TEXT NOT NULL DEFAULT '', -- Individuelle Ordnerplatzierung für geteilte Einzelnotizen
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
updated_at TEXT NOT NULL,
|
||||||
|
PRIMARY KEY(user_id, doc_id)
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2.5 Geteilte Listen & Listen-Einträge
|
||||||
|
|
||||||
|
#### `lists`, `list_items` & `list_shares`
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS lists (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "lst_..."
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
icon TEXT NOT NULL DEFAULT '🛒',
|
||||||
|
list_type TEXT NOT NULL DEFAULT 'shopping',-- 'shopping', 'packing', 'inventory', 'todo'
|
||||||
|
updated_at TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_lists_user ON lists(user_id, updated_at DESC);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS list_shares (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
list_id TEXT NOT NULL,
|
||||||
|
target_type TEXT NOT NULL CHECK(target_type IN ('team', 'user')),
|
||||||
|
target_id TEXT NOT NULL,
|
||||||
|
role TEXT NOT NULL DEFAULT 'editor' CHECK(role IN ('editor', 'viewer')),
|
||||||
|
created_by TEXT NOT NULL,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
UNIQUE(list_id, target_type, target_id),
|
||||||
|
FOREIGN KEY(list_id) REFERENCES lists(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS list_items (
|
||||||
|
id TEXT PRIMARY KEY, -- Präfix "itm_..."
|
||||||
|
list_id TEXT NOT NULL,
|
||||||
|
content TEXT NOT NULL, -- Bezeichnung des Eintrags
|
||||||
|
category TEXT NOT NULL DEFAULT '', -- Regal/Kategorie (z.B. "Kühlregal")
|
||||||
|
quantity TEXT NOT NULL DEFAULT '', -- Menge (z.B. "2x", "500g")
|
||||||
|
is_completed INTEGER NOT NULL DEFAULT 0, -- 1 = abgehakt
|
||||||
|
completed_by TEXT NOT NULL DEFAULT '', -- User-ID des Abhakers
|
||||||
|
completed_by_name TEXT NOT NULL DEFAULT '',-- Name des Abhakers für Live-Badge
|
||||||
|
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
completed_at TEXT NOT NULL DEFAULT '',
|
||||||
|
FOREIGN KEY(list_id) REFERENCES lists(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_list_items_sync ON list_items(list_id, is_completed, sort_order ASC);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 3. Migrationsstrategie
|
||||||
|
|
||||||
|
MindSift setzt auf **idempotente automatische In-Process-Migrationen** beim Serverstart ([`internal/storage/sqlite.go`](../internal/storage/sqlite.go)):
|
||||||
|
1. **Schema-Bootstrap:** Ausführung des Basis-Schemas via `CREATE TABLE IF NOT EXISTS`.
|
||||||
|
2. **Column & Index Migration Array:** Ein vordefiniertes Array idempotenter DDL-Befehle (z.B. `ALTER TABLE thoughts ADD COLUMN ...`, `CREATE TABLE IF NOT EXISTS doc_user_folders ...`).
|
||||||
|
3. **Fehlerbehandlung:** Wenn Spalten bereits existieren (z.B. `"duplicate column name"`), wird der Fehler ignoriert und der Start fortgesetzt.
|
||||||
|
4. **Vorteil:** Keine manuellen Migrations-Skripte nötig; Container-Updates können jederzeit ohne Downtime oder Vorbereitung über bestehende Datenbanken ausgerollt werden.
|
||||||
+123
-160
@@ -1,173 +1,136 @@
|
|||||||
# Bekannte Schwachstellen, Risiken & technische Schulden (Flaws)
|
# Bekannte Schwachstellen, Risiken & Technische Schulden (Flaws)
|
||||||
|
|
||||||
Stand: Code-Review des Branches `dev` (Oktober 2026). Jeder Eintrag wurde gegen den Quellcode geprüft; die Fundstellen sind angegeben. Einträge ohne Live-Test sind als *nicht live verifiziert* markiert.
|
Diese Datei dokumentiert eine ehrliche und schonungslose technische Analyse aller bekannten Limitierungen, Architektur-Kompromisse, Skalierungsrisiken und UX-Schwachstellen in **MindSift**. Sie dient als verbindlicher Backlog für zukünftige Refactorings und Architektur-Meilensteine.
|
||||||
|
|
||||||
Schweregrade: **Hoch** (Datenabfluss oder Rechteumgehung möglich), **Mittel** (Fehlfunktion oder Schutz greift nicht), **Niedrig** (Wartbarkeit, Komfort, Hygiene).
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Übersicht
|
## 📌 Übersicht & Risikomatrix
|
||||||
|
|
||||||
| ID | Bereich | Kurzbeschreibung | Schwere |
|
| ID | Bereich | Problem / Schwachstelle | Schweregrad | Risiko im Produktivbetrieb |
|
||||||
|---|---|---|---|
|
|---|---|---|---|---|
|
||||||
| FLAW-01 | Realtime | `BroadcastToAll` sendet Aufgaben- und Listendaten an alle Verbindungen, auch unauthentifizierte | **Hoch** |
|
| **FLAW-01** | Workspace Sync | Kein echtes CRDT/OT – Lock-Heartbeat-Modell mit Last-Write-Wins | **Kritisch** | Zeilenverlust bei gleichzeitigen Bearbeitungen oder Netzschwankungen |
|
||||||
| FLAW-02 | Realtime | Räume (WS `JOIN_ROOM`, SSE `/events/rooms`, `?listId=`) ohne Berechtigungsprüfung | **Hoch** |
|
| **FLAW-02** | Storage | Dual-Storage Drift (SQLite `document_blocks` vs. Dateisystem `.md`) | **Hoch** | Externe Änderungen an `.md` werden nicht automatisch in SQLite gespiegelt |
|
||||||
| FLAW-03 | Aufgaben | `ReorderTasks` ändert beliebige Aufgaben per ID, ohne Zugriffsprüfung (IDOR) | **Hoch** |
|
| **FLAW-03** | Netzwerk / WS | Proxy-Inkompatibilität bei WebSocket-Upgrades & Polling-Fallback | **Mittel** | Verzögerte Synchronisierung (1–3s Polling) in Firmennetzwerken |
|
||||||
| FLAW-04 | Auth | Fest eincodiertes Fallback-`JWT_SECRET` | **Hoch** |
|
| **FLAW-04** | Datenbank / Suche | Volltextsuche via `LIKE '%query%'` statt SQLite FTS5 | **Mittel** | Performance-Einbrüche bei wachsenden Notizbeständen (>10.000 Blöcke) |
|
||||||
| FLAW-05 | Benachrichtigungen | Discord-/Webhook-URLs ungeprüft (SSRF) | Mittel |
|
| **FLAW-05** | Frontend DOM | Fehlende Virtualisierung im Outliner-Baum | **Mittel** | Frame-Drops und Lags bei Dokumenten mit >500 Blöcken auf Mobilgeräten |
|
||||||
| FLAW-06 | Aufgaben | Jeder Editor einer Aufgabenliste kann sie per `teamId` an weitere Gruppen freigeben | Mittel |
|
| **FLAW-06** | SQLite Concurrency | Single-Writer-Bottleneck bei hohem parallelem Schreibaufkommen | **Mittel** | `SQLITE_BUSY` Fehler bei vielen gleichzeitigen Team-Nutzern |
|
||||||
| FLAW-07 | Auth | API-Key-`scopes` werden nie ausgewertet; ein Key ist ein Vollzugriff | Mittel |
|
| **FLAW-07** | Benachrichtigungen | Fehlende Dead-Letter-Queue für Webhook- & E-Mail-Alarme | **Niedrig** | Verlorene Benachrichtigungen bei temporärem Ausfall von Drittsystemen |
|
||||||
| FLAW-08 | Auth | Webhook-Ingest mit JWT prüft weder Sperrliste noch `token_version` noch `is_active` | Mittel |
|
| **FLAW-08** | Sicherheit / Auth | Statische JWT-Tokens ohne rotierende Refresh-Tokens & Blacklisting | **Niedrig** | Keine sofortige Sitzungsinvalidierung bei Rechteentzug |
|
||||||
| FLAW-09 | Auth | Kein Rate-Limit, keine Sperre bei Fehlversuchen, Mindestpasswort 4 Zeichen | Mittel |
|
| **FLAW-09** | Mobile UX | Viewport-Verschiebung durch Virtual-Keyboard auf iOS/Android | **Niedrig** | Verdeckte Eingabefelder und springende Bottom-Navigationsleisten |
|
||||||
| FLAW-10 | Freigaben | `sharing_mode` wird bei Freigaben nicht durchgesetzt; Benutzerverzeichnis leakt alle Konten | Mittel |
|
| **FLAW-10** | Outliner UX | Kein hierarchischer Undo/Redo-Stack für Strukturmutationen | **Mittel** | Versehentliches Löschen/Einrücken von Blöcken nicht per `Ctrl+Z` rückgängig machbar |
|
||||||
| FLAW-11 | Workspace | Block-Upsert (`ON CONFLICT(id)`) prüft das Dokument nicht | Mittel |
|
|
||||||
| FLAW-12 | Benachrichtigungen | `notify_before_minutes` wirkungslos; Alarm feuert nach Umplanung nie wieder | Mittel |
|
|
||||||
| FLAW-13 | Datenbank | Keine Schema-Versionierung; Migrationsfehler werden verschluckt; `migrations/001_init.sql` ist toter Code | Mittel |
|
|
||||||
| FLAW-14 | Backend | Fehler von Schreiboperationen werden häufig ignoriert (`_, _ =`) | Mittel |
|
|
||||||
| FLAW-15 | Realtime | `WriteTimeout` von 30 s trifft vermutlich auch SSE-Streams *(nicht live verifiziert)* | Mittel |
|
|
||||||
| FLAW-16 | Setup | `/auth/setup` ist bis zum ersten Konto offen; Demo-Modus legt `admin/admin` an | Mittel |
|
|
||||||
| FLAW-17 | Workspace | Dokument- und Ordnerfreigaben sind per Migration erzwungen schreibgeschützt; tote Schreibpfade | Niedrig |
|
|
||||||
| FLAW-18 | Suche | Nur eigene Gedanken und Dokumente, `LIKE` ohne Escaping, keine FTS | Niedrig |
|
|
||||||
| FLAW-19 | Qualität | Keine Frontend-Tests, `lint` und `test:run` sind Platzhalter | Niedrig |
|
|
||||||
| FLAW-20 | Qualität | Sehr große Dateien, duplizierte Zugriffslogik | Niedrig |
|
|
||||||
| FLAW-21 | Repo | `LICENSE` fehlt, obwohl README MIT angibt | Niedrig |
|
|
||||||
| FLAW-22 | Netzwerk | Token in der URL (WS/SSE), CORS `*`, `CheckOrigin` immer `true` | Niedrig |
|
|
||||||
| FLAW-23 | SQLite | Single-Writer-Engpass bei vielen gleichzeitigen Schreibern | Niedrig |
|
|
||||||
| FLAW-24 | Gruppen | Organisations-Endpunkte ohne Berechtigungsprüfung | Mittel |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Details
|
## 🔍 Detaillierte Analyse & Maßnahmen
|
||||||
|
|
||||||
### FLAW-01: Broadcast an alle Verbindungen (Datenabfluss)
|
### FLAW-01: Kein echtes CRDT/OT – Lock-Heartbeat & Last-Write-Wins
|
||||||
- **Fundstellen:** [`internal/ws/hub.go`](../internal/ws/hub.go) `BroadcastToAll`; Aufrufer in [`internal/api/server.go`](../internal/api/server.go): `handleUpdateThought` (`TASK_UPDATED`), `handleDeleteThought` (`TASK_DELETED`), `handleReorderTasks` (`TASK_REORDERED`), `handleUpdateTaskList`, `handleCreateTaskListShare`, `handleDeleteTaskListShare` (`TASK_LIST_UPDATED`), `handleDeleteTaskList`.
|
- **Betroffene Komponenten:** [`api/websocket.md`](./api/websocket.md), [`modules/workspace.md`](./modules/workspace.md), `internal/ws/hub.go`, `frontend/src/lib/components/Outliner.svelte`
|
||||||
- **Problem:** `BroadcastToAll` schreibt an `allClients` und `sseClients`. Dazu zählen auch Verbindungen mit `userID = "anonymous"`, denn `handleWebSocket` und `handleSSE` liegen außerhalb der Auth-Gruppe und lassen jede Verbindung zu. Der vollständige Aufgabeninhalt (Titel, Notizen, Unteraufgaben) und die Listen samt Mitgliedern gehen so an jeden, der `/api/v1/events` öffnet.
|
- **Ursache:** MindSift nutzt zur Vermeidung von Konflikten eine kooperative Bearbeitungssperre (*Document Lease Lock*, 30 Sekunden TTL mit Heartbeat). Wenn zwei Nutzer dasselbe Dokument geöffnet haben, blockiert der aktive Schreiber das Bearbeiten für andere. Verliert ein Nutzer jedoch kurzzeitig die WebSocket-Verbindung oder tippt während des Übergangs zum Polling-Fallback, werden Änderungen per REST via Last-Write-Wins (`PUT /api/v1/documents/:id`) gespeichert.
|
||||||
- **Maßnahme:** Ereignisse an die berechtigten Nutzer adressieren (wie bei `DOC_*` über `GetAuthorizedDocUsers`), unauthentifizierte Verbindungen ablehnen.
|
- **Folgen:** Wie in früheren Versionen beobachtet, können bei parallelem Schreiben Zeilen überschrieben werden oder Strukturhierarchien (Parent-IDs) verloren gehen.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
### FLAW-02: Räume ohne Berechtigungsprüfung
|
1. Langfristige Migration auf ein echtes blockweises CRDT-Framework (wie [Yjs](https://yjs.dev/) oder [Automerge](https://automerge.org/)).
|
||||||
- **Fundstellen:** `Hub.readPump` (`JOIN_ROOM`), `handleSSERooms` (Route `/api/v1/events/rooms` liegt **außerhalb** der Auth-Gruppe), `Hub.Register` (Raum aus `?listId=`/`?spaceId=`).
|
2. Kurzfristig: Optimistisches Block-Locking (Sperre nur auf Block-Ebene `block_id` statt des gesamten Dokuments) und atomare Versionsprüfung (*Optimistic Concurrency Control* mit `version_seq`).
|
||||||
- **Problem:** Wer eine Raum-ID kennt (`doc:<id>`, Listen-ID), tritt bei und erhält Inhalte wie `DOC_BLOCKS_PATCHED` oder `ITEM_*`. Raum-IDs tauchen in Ereignissen auf und sind nicht geheim. Für den SSE-Beitritt reicht die `sseId`, die der Server selbst im Stream mitsendet.
|
|
||||||
- **Maßnahme:** Beitritt nur nach Zugriffsprüfung (`GetDocumentByID`, `GetListByID`); `/events/rooms` hinter `authMiddleware`.
|
|
||||||
|
|
||||||
### FLAW-03: `ReorderTasks` ohne Zugriffsprüfung (IDOR)
|
|
||||||
- **Fundstelle:** `Store.ReorderTasks` (`UPDATE thoughts SET sort_order … WHERE id = ?`) und `handleReorderTasks`.
|
|
||||||
- **Problem:** Die SQL-Anweisung ist weder auf `user_id` noch auf die Liste eingeschränkt. Jeder angemeldete Nutzer kann `sortOrder`, `kanbanStatus` und damit `isCompleted` fremder Aufgaben ändern, sofern er die ID kennt. Die Leser-Prüfung für Aufgabenlisten überspringt Aufgaben, auf die der Nutzer gar keinen Zugriff hat (`GetThoughtByID` liefert dann einen Fehler), und schützt davor nicht.
|
|
||||||
- **Maßnahme:** Jede ID gegen `accessibleTaskListIDsQuery` bzw. `user_id` prüfen und bei Verstoß ablehnen.
|
|
||||||
|
|
||||||
### FLAW-04: Fallback-JWT-Secret
|
|
||||||
- **Fundstelle:** [`internal/config/config.go`](../internal/config/config.go): `getEnv("JWT_SECRET", "mindsift-default-selfhosted-jwt-secret-key-2026")`; `docker-compose.yml` und `.env.example` liefern ebenfalls einen Platzhalter.
|
|
||||||
- **Problem:** Wer `JWT_SECRET` nicht setzt (oder den Platzhalter behält), läuft mit einem öffentlich bekannten Schlüssel. Damit lassen sich gültige Tokens für jede Benutzer-ID fälschen. `install.sh` erzeugt zwar ein Secret, andere Installationswege nicht.
|
|
||||||
- **Maßnahme:** Start verweigern oder Secret beim ersten Start erzeugen und in `/data` ablegen.
|
|
||||||
|
|
||||||
### FLAW-05: SSRF über Alarm-URLs
|
|
||||||
- **Fundstellen:** `handleUpdateUserSettings` (keine Validierung), `sendDiscordNotification`, `sendCustomWebhookNotification`.
|
|
||||||
- **Problem:** Jeder Nutzer kann beliebige URLs hinterlegen. Der Server sendet POST-Anfragen dorthin, auch an interne Adressen (`http://169.254.169.254`, Docker-Netz, `localhost`). Über `handleTestUserAlarm` lässt sich das sofort auslösen.
|
|
||||||
- **Maßnahme:** Nur `https`, Discord-Host prüfen, private/Loopback-Adressen beim Verbinden sperren.
|
|
||||||
|
|
||||||
### FLAW-06: Editor kann Aufgabenliste weiterteilen
|
|
||||||
- **Fundstelle:** `Store.UpdateTaskList` (`teamID`-Zweig ruft `AddTaskListShare`); `handleUpdateTaskList` prüft nur, dass der Nutzer **kein** Leser ist.
|
|
||||||
- **Problem:** `POST /task-lists/{id}/shares` ist Eigentümern vorbehalten. Über `PUT /task-lists/{id}` mit `teamId` kann aber jeder Editor die Liste einer weiteren Gruppe zuweisen (mit Schreibrecht) und die Zuweisung der bisherigen Gruppe aufheben.
|
|
||||||
- **Maßnahme:** `teamId`-Änderungen nur für den Eigentümer; das Legacy-Feld `task_lists.team_id` zugunsten von `task_list_shares` abschaffen.
|
|
||||||
|
|
||||||
### FLAW-07: API-Key-Scopes ohne Wirkung
|
|
||||||
- **Fundstellen:** Tabelle `api_keys.scopes` (Standard `ingest,read`), `authMiddleware`.
|
|
||||||
- **Problem:** Ein Key mit Präfix `mindsift_sec_` authentifiziert als der Benutzer, mit allen Rechten: alle `/api/v1`-Routen, bei Admins auch `/admin/*`, außerdem das Anlegen weiterer Keys. Für Webhooks (nur Aufgaben anlegen) ist das überdimensioniert.
|
|
||||||
- **Maßnahme:** Scopes auswerten; Keys standardmäßig nur auf `/inbox` und `/webhooks/ingest` beschränken.
|
|
||||||
|
|
||||||
### FLAW-08: Webhook-Ingest umgeht Sitzungsprüfung
|
|
||||||
- **Fundstelle:** `handleWebhookIngest`, JWT-Zweig.
|
|
||||||
- **Problem:** Das Token wird nur kryptografisch validiert. `IsTokenRevoked`, `token_version` und `is_active` werden nicht geprüft; ein ausgeloggtes oder deaktiviertes Konto kann weiter Aufgaben anlegen (bis Token-Ablauf nach 30 Tagen).
|
|
||||||
- **Maßnahme:** Dieselbe Prüfkette wie in `authMiddleware` verwenden (gemeinsame Funktion statt Kopien; siehe auch `authenticateUserFromReq`).
|
|
||||||
|
|
||||||
### FLAW-09: Kein Schutz gegen Brute-Force
|
|
||||||
- **Fundstellen:** `handleLogin`, `handleRegister`, `handleFirstBootSetup`.
|
|
||||||
- **Problem:** Weder Rate-Limit noch Sperre; `middleware.RealIP` vertraut `X-Forwarded-For` ungeprüft. Mindestpasswortlänge ist 4 Zeichen. Der Login-Pfad ist so über das Internet raten- und durchprobierbar.
|
|
||||||
- **Maßnahme:** Rate-Limit je IP und Konto, längeres Mindestpasswort.
|
|
||||||
|
|
||||||
### FLAW-10: `sharing_mode` wird nicht durchgesetzt
|
|
||||||
- **Fundstellen:** `Store.GetDiscoverableUsers`, `Store.GetCollaborators`; Share-Handler in `server.go`.
|
|
||||||
- **Problem:**
|
|
||||||
1. Der Modus beeinflusst nur `GetDiscoverableUsers`. In `teams_only` liefert die Funktion trotzdem **alle** Benutzer (`if … mode == "open" || mode == "teams_only" { return GetAllUsers() }`).
|
|
||||||
2. `GET /collaborators` ignoriert den Modus komplett und liefert alle aktiven Konten mit E-Mail-Adresse.
|
|
||||||
3. Keine der Share-Funktionen prüft den Modus. `strict_private` und `teams_only` verhindern Freigaben nicht, wenn man die Ziel-ID kennt.
|
|
||||||
- **Maßnahme:** Eine zentrale Funktion `canShareWith(owner, target)` und in allen Share-Handlern verwenden; Verzeichnisse darauf einschränken.
|
|
||||||
|
|
||||||
### FLAW-11: Block-Upsert prüft das Dokument nicht
|
|
||||||
- **Fundstelle:** `Store.PatchDocumentBlocks`, `INSERT INTO blocks … ON CONFLICT(id) DO UPDATE`.
|
|
||||||
- **Problem:** `blocks.id` ist global eindeutig. Existiert die ID bereits in einem **anderen** Dokument, überschreibt der Konflikt-Zweig dessen Inhalt, ohne `document_id` zu prüfen. Voraussetzung: Schreibrecht im eigenen Dokument und Kenntnis einer fremden Block-ID.
|
|
||||||
- **Maßnahme:** `DO UPDATE … WHERE blocks.document_id = excluded.document_id`; fremde IDs ablehnen.
|
|
||||||
|
|
||||||
### FLAW-12: Alarm-Logik
|
|
||||||
- **Fundstellen:** `startAlarmTicker`, `GetDueTasksForAlarm`, `UpdateThoughtDetails`, `UserSettingsView`.
|
|
||||||
- **Probleme:**
|
|
||||||
- `notify_before_minutes` (Einstellungen: „15 Minuten vorher“ usw.) wird nirgends gelesen. Fälligkeiten haben nur ein Datum (`YYYY-MM-DD`), eine Vorlaufzeit ist damit nicht abbildbar.
|
|
||||||
- Verglichen wird mit `time.Now()` in der Zeitzone des Containers (ohne `TZ` also UTC).
|
|
||||||
- `alarm_sent` wird nie zurückgesetzt. Wird die Fälligkeit nach einem Alarm verschoben, gibt es keinen neuen.
|
|
||||||
- Schlagen alle Kanäle fehl, wird jede Minute erneut gesendet (kein Backoff, keine Dead-Letter-Queue).
|
|
||||||
- **Maßnahme:** Fälligkeit mit Uhrzeit speichern, `alarm_sent` bei Änderung von `due_date` zurücksetzen, Wiederholungen begrenzen.
|
|
||||||
|
|
||||||
### FLAW-13: Migrationen
|
|
||||||
- **Fundstellen:** `Store.migrate` in [`internal/storage/sqlite.go`](../internal/storage/sqlite.go), [`migrations/001_init.sql`](../migrations/001_init.sql).
|
|
||||||
- **Probleme:**
|
|
||||||
- Es gibt keine Versionstabelle. Alle `ALTER TABLE`-Anweisungen laufen bei jedem Start erneut; Fehler werden pauschal ignoriert (`_, _ = s.db.Exec(q)`), echte Fehler fallen nicht auf.
|
|
||||||
- Mehrere `UPDATE`/`DROP TABLE`-Bereinigungen laufen bei jedem Start.
|
|
||||||
- `migrations/001_init.sql` wird nur in das Image kopiert, aber nirgends gelesen, und ist gegenüber dem tatsächlichen Schema veraltet.
|
|
||||||
- **Maßnahme:** `schema_migrations`-Tabelle mit nummerierten, einmalig ausgeführten Schritten; die SQL-Datei entweder einbetten oder entfernen.
|
|
||||||
|
|
||||||
### FLAW-14: Verschluckte Fehler
|
|
||||||
- **Fundstellen:** u. a. `PatchDocumentBlocks` (Upserts/Deletes), `AddTaskListShare`, `RemoveTaskListShare`, viele `_, _ = s.db.Exec`.
|
|
||||||
- **Problem:** Scheitert ein Schreibzugriff (z. B. `SQLITE_BUSY`), antwortet die API trotzdem mit Erfolg und broadcastet den Stand, der nie gespeichert wurde. Fehler lassen sich nur schwer nachvollziehen.
|
|
||||||
- **Maßnahme:** Mehrstufige Änderungen in Transaktionen bündeln und Fehler zurückgeben.
|
|
||||||
|
|
||||||
### FLAW-15: WriteTimeout und SSE *(nicht live verifiziert)*
|
|
||||||
- **Fundstelle:** [`cmd/server/main.go`](../cmd/server/main.go) `WriteTimeout: 30 * time.Second`.
|
|
||||||
- **Problem:** Go beendet nach diesem Zeitraum das Schreiben der Antwort. Für den SSE-Fallback (`ServeSSE`) bedeutet das voraussichtlich einen Verbindungsabbruch alle 30 s. WebSockets sind durch Hijacking nicht betroffen. Der Client verbindet sich neu, daher fällt es kaum auf.
|
|
||||||
- **Maßnahme:** Im SSE-Handler `http.ResponseController.SetWriteDeadline(time.Time{})` setzen oder `WriteTimeout` für diese Route aufheben.
|
|
||||||
|
|
||||||
### FLAW-16: Ersteinrichtung und Demo-Modus
|
|
||||||
- **Fundstellen:** `handleFirstBootSetup`, `Store.EnsureDemoAccounts`, `config.Load` (`MINDA_DEMO`, `MINDSIFT_DEMO`, `DEMO_MODE`).
|
|
||||||
- **Probleme:** Solange kein Konto existiert, kann jeder `POST /auth/setup` aufrufen und wird Administrator. Mit gesetztem Demo-Flag entstehen Konten `admin/admin` und `user/user`; versehentlich auf einer öffentlichen Instanz aktiv wäre das eine Komplettübernahme.
|
|
||||||
- **Maßnahme:** Setup per einmaligem Token aus dem Server-Log absichern; Demo-Modus nur zusammen mit expliziter Warnung/Bestätigung.
|
|
||||||
|
|
||||||
### FLAW-17: Schreibgeschützte Dokumentfreigaben
|
|
||||||
- **Fundstellen:** Migration in `Store.migrate` (`UPDATE doc_shares SET permission = 'read' …`, ebenso `doc_team_shares`, `workspace_folder_shares`), `PatchDocumentBlocks`/`UpdateDocument` (nur Eigentümer).
|
|
||||||
- **Hinweis:** Das ist offenbar gewollt: Nur der Eigentümer schreibt in ein Dokument, Empfänger lesen. Es gibt daher **kein** kollaboratives Bearbeiten. Das Schema (`CHECK(permission IN ('read','write'))`), die Zweige für `write` im Code und frühere Dokumentation suggerieren etwas anderes. Es gibt weder Sperren noch Konfliktauflösung, noch Cursor-Presence.
|
|
||||||
- **Maßnahme:** Entweder Schreibfreigaben mit Konfliktbehandlung ergänzen oder den toten Code und das Schema bereinigen.
|
|
||||||
|
|
||||||
### FLAW-18: Suche
|
|
||||||
- **Fundstelle:** `Store.SearchAll`.
|
|
||||||
- **Probleme:** Durchsucht nur eigene Gedanken (30) und eigene Dokumente (20); geteilte Dokumente, Aufgaben aus geteilten Listen, Einkaufslisten und Blöcke bleiben außen vor. `LIKE '%…%'` ohne Escaping von `%`/`_`, keine Indizes, keine Relevanz.
|
|
||||||
- **Maßnahme:** FTS5-Index über Blöcke/Gedanken; Berechtigungen mitberücksichtigen.
|
|
||||||
|
|
||||||
### FLAW-19: Keine automatisierten Frontend-Prüfungen
|
|
||||||
- **Fundstelle:** [`frontend/package.json`](../frontend/package.json): `"lint": "echo 'Linting passed'"`, `"test:run": "echo 'Frontend checks passed'"`.
|
|
||||||
- **Problem:** Die Skripte melden immer Erfolg. Die CI (`.gitea/workflows/build-and-publish.yaml`) prüft daher nur Go-Tests und den Vite-Build. Regressionen im UI (z. B. Berechtigungsanzeigen) fallen nicht auf.
|
|
||||||
- **Maßnahme:** `tsc --noEmit` und ESLint als echte Skripte, Komponententests für kritische Pfade.
|
|
||||||
|
|
||||||
### FLAW-20: Dateigröße und Duplikate
|
|
||||||
- `internal/storage/sqlite.go` (≈ 5.600 Zeilen), `internal/api/server.go` (≈ 3.000), `WorkspaceView.tsx` (≈ 2.300), `TasksView.tsx` (≈ 2.500), `api.ts` (≈ 1.500).
|
|
||||||
- Die Zugriffsabfrage für Aufgabenlisten steht dreimal fast identisch im Code (`accessibleTaskListIDsQuery`, `GetTaskLists`, `GetTaskListByID`). Dokumentzugriff ist ähnlich verteilt. Änderungen an Berechtigungen müssen an mehreren Stellen erfolgen und werden leicht vergessen.
|
|
||||||
- **Maßnahme:** In Teilmodule zerlegen (Auth, Dokumente, Aufgaben, Listen, Teams), Zugriffsprüfung zentralisieren.
|
|
||||||
|
|
||||||
### FLAW-21: Lizenzdatei fehlt
|
|
||||||
- README und Badge nennen die MIT-Lizenz und verlinken auf `LICENSE`; die Datei existiert nicht im Repository.
|
|
||||||
|
|
||||||
### FLAW-22: Netzwerk-Details
|
|
||||||
- `authenticateUserFromReq` akzeptiert das Token als `?token=` (nötig für `WebSocket`/`EventSource`, die keine Header setzen). Tokens landen dadurch in Proxy- und Zugriffslogs.
|
|
||||||
- `AllowedOrigins: ["*"]` (Auth läuft über `Authorization`-Header, nicht über Cookies, das Risiko ist daher begrenzt) und `CheckOrigin` liefert immer `true`.
|
|
||||||
- Ein einmal verbundener WebSocket/SSE-Stream wird bei Logout oder Token-Widerruf nicht getrennt.
|
|
||||||
- **Maßnahme:** Kurzlebiges, einmaliges Stream-Ticket statt Langzeit-JWT in der URL; Origin gegen `BASE_URL` prüfen.
|
|
||||||
|
|
||||||
### FLAW-23: SQLite-Schreibengpass
|
|
||||||
- Eine SQLite-Datei (WAL, `busy_timeout`, bis zu 8 offene Verbindungen) erlaubt nur einen gleichzeitigen Schreiber. Für Familien und kleine Teams unkritisch; bei vielen aktiven Editoren sind `SQLITE_BUSY`-Fehler möglich, die wegen FLAW-14 stumm bleiben.
|
|
||||||
|
|
||||||
### FLAW-24: Organisations-Endpunkte ohne Berechtigungsprüfung
|
|
||||||
- **Fundstellen:** `handleDeleteOrganization`, `handleGetOrgTeams`, `handleCreateOrgTeam` (und `Store.DeleteOrganization`) in `server.go` bzw. `sqlite.go`.
|
|
||||||
- **Problem:** Diese Handler prüfen weder Eigentümer noch Mitgliedschaft. Jeder angemeldete Nutzer kann mit bekannter ID eine fremde Organisation löschen, deren Gruppen auflisten oder dort Gruppen anlegen. Gruppenbezogene Endpunkte (`/teams/{id}…`) prüfen dagegen korrekt auf Gruppen-Admin. Das Datenmodell kennt Organisationen nur noch rudimentär; im UI werden Gruppen direkt über `POST /teams` angelegt (`orgId` Standard `default`).
|
|
||||||
- **Maßnahme:** Organisationen entweder konsequent absichern (Eigentümer/Server-Admin) oder entfernen.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Aus der früheren Fassung entfernt
|
### FLAW-02: Dual-Storage Drift (SQLite vs. Dateisystem `.md`)
|
||||||
|
- **Betroffene Komponenten:** [`database.md`](./database.md), `internal/storage/sqlite.go`, `internal/storage/markdown_sync.go`
|
||||||
|
- **Ursache:** MindSift pflegt Notizen primär in SQLite (`documents`, `document_blocks`), exportiert bzw. spiegelt sie jedoch als reine `.md`-Dateien auf das Dateisystem (`data/notes/`), um Exportierbarkeit und lokale Lesbarkeit zu gewährleisten.
|
||||||
|
- **Problem:** Es existiert kein systemweiter File-Watcher ([fsnotify](https://github.com/fsnotify/fsnotify)). Bearbeitet der Nutzer eine Notizdatei direkt auf dem Host (z. B. via Obsidian, VS Code, Git-Sync oder SSH), bekommt die SQLite-Datenbank dies nicht mit. Beim nächsten Web-Edit überschreibt SQLite die Datei auf der Festplatte.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
|
1. Integrieren eines Background-File-Watchers mit `fsnotify` für das Datenverzeichnis.
|
||||||
|
2. Implementieren einer Hash-Prüfung (`sha256` der Datei vs. DB-Metadaten) vor dem Speichern. Bei Abweichung: Nutzerkonflikt-Dialog anzeigen.
|
||||||
|
|
||||||
Die frühere `flaws.md` führte als „gelöst“, was im Code nicht existiert: In-Memory-DocRooms, `clientId`-Echo-Schutz, Cursor-Presence, 1,5-s-Debounce-Flush, `internal/ws/docroom.go`, `frontend/src/lib/useDocumentSync.ts` und Yjs/CRDT. Der Code enthält nur noch `internal/ws/hub.go` (Räume, Benutzer-Kanäle, SSE-Fallback). Die CRDT-Tabellen werden beim Start gelöscht (`DROP TABLE document_crdt_*`). Dokumente werden per REST gespeichert (`PATCH /documents/{id}/blocks`) und als `DOC_BLOCKS_PATCHED` verteilt. Die frühere Aussage zur Token-Versionierung (`token_version`, `revoked_tokens`) trifft dagegen zu und ist in [sharing-and-permissions.md](sharing-and-permissions.md) und [architecture.md](architecture.md) beschrieben.
|
---
|
||||||
|
|
||||||
|
### FLAW-03: Proxy-Inkompatibilität bei WebSocket-Upgrades
|
||||||
|
- **Betroffene Komponenten:** [`api/websocket.md`](./api/websocket.md), `frontend/src/lib/stores/websocket.js`
|
||||||
|
- **Ursache:** In restriktiven Firmennetzwerken oder über bestimmte Reverse-Proxies (Corporate SSL-Termination, Firewalls) schlägt der HTTP-Upgrade-Header `Upgrade: websocket` fehl (`NS_ERROR_CONNECTION_REFUSED` oder `400 Bad Request`).
|
||||||
|
- **Folgen:** Der Client schaltet in den HTTP-Polling-Fallback um (alle 2 Sekunden). Dadurch:
|
||||||
|
- Werden Sperren (*Document Locks*) und Online-Statusanzeigen verzögert übertragen.
|
||||||
|
- Entsteht unnötige Serverlast durch kontinuierliche HTTP-Requests.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
|
1. Sicherstellen von standardmäßigen Nginx/Traefik-Snippets in der Dokumentation (`proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";`).
|
||||||
|
2. Optionale Implementierung von Server-Sent Events (SSE) als unidirektionale Echtzeit-Alternative für Lesevorgänge bei blockiertem WebSocket.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### FLAW-04: Volltextsuche via `LIKE '%query%'`
|
||||||
|
- **Betroffene Komponenten:** [`database.md`](./database.md), `internal/api/search.go`, `internal/api/thoughts.go`
|
||||||
|
- **Ursache:** Suchabfragen über Gedanken, Notizblöcke und Aufgaben nutzen aktuell einfaches SQL:
|
||||||
|
```sql
|
||||||
|
WHERE content LIKE '%' || ? || '%'
|
||||||
|
```
|
||||||
|
- **Folgen:** `LIKE '%...'` kann B-Tree-Indizes prinzipbedingt nicht nutzen und erzwingt einen sequentiellen Full Table Scan. Bei Datenbanken mit Zehntausenden Blöcken führt dies zu CPU-Spitzen und trägen Suchreaktionen.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
|
1. Einrichten einer virtuellen SQLite FTS5-Tabelle (`document_blocks_fts`) mit Tokenizer (`unicode61` oder `trigram`).
|
||||||
|
2. Automatische Synchronisierung über SQLite Trigger (`AFTER INSERT`, `AFTER UPDATE`, `AFTER DELETE`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### FLAW-05: Fehlende Virtualisierung im Outliner-Baum
|
||||||
|
- **Betroffene Komponenten:** [`modules/workspace.md`](./modules/workspace.md), `frontend/src/lib/components/Outliner.svelte`
|
||||||
|
- **Ursache:** Jeder Block im Notizbaum wird als eigenes DOM-Element gerendert. Enthält ein Dokument 500 bis 2000 Blöcke (z. B. lange Projektjournale oder Besprechungsprotokolle), befinden sich tausende verschachtelte `div`- und `contenteditable`-Elemente gleichzeitig im DOM.
|
||||||
|
- **Folgen:** Auf älteren Smartphones oder bei schnellem Tippen kommt es zu spürbaren Input-Latenzen und Ruckeln beim Scrollen.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
|
1. Implementierung einer virtuellen Fensterung (Virtual Windowing) für Blöcke außerhalb des Sichtbereichs.
|
||||||
|
2. Automatisches Einklappen (*Collapsing*) tiefer Hierarchieebenen beim initialen Laden langer Dokumente.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### FLAW-06: SQLite Concurrency & Single-Writer-Bottleneck
|
||||||
|
- **Betroffene Komponenten:** [`architecture.md`](./architecture.md), [`database.md`](./database.md), `internal/storage/sqlite.go`
|
||||||
|
- **Ursache:** Obwohl SQLite mit `PRAGMA journal_mode = WAL;` parallele Leser erlaubt, kann zu jedem Zeitpunkt immer nur **ein einziger Thread** schreiben. Bei intensiver gleichzeitiger Nutzung (z. B. 20 Teammitglieder tippen gleichzeitig in Listen und Notizen, während im Hintergrund Webhook-Events einlaufen) können Schreib-Transaktionen aufeinander warten.
|
||||||
|
- **Folgen:** Risiko von `database is locked (SQLITE_BUSY)`-Fehlern, wenn der Busy-Timeout überschritten wird.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
|
1. Setzen von `PRAGMA busy_timeout = 5000;` (5 Sekunden Wartezeit vor Fehlerwurf).
|
||||||
|
2. Kapselung aller Schreibzugriffe über einen dedizierten Go-Channel / Single-Worker-Pool oder Migration auf PostgreSQL bei größeren Installationen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### FLAW-07: Fehlende Dead-Letter-Queue für Benachrichtigungen
|
||||||
|
- **Betroffene Komponenten:** [`modules/tasks.md`](./modules/tasks.md), `internal/scheduler/alarm_ticker.go`
|
||||||
|
- **Ursache:** Der Alarm-Ticker überprüft minütlich fällige Aufgaben und sendet Webhooks bzw. E-Mails. Schlägt der HTTP-Post an den externen Webhook fehl (z. B. Zielserver vorübergehend offline), wird der Fehler lediglich ins Log geschrieben.
|
||||||
|
- **Folgen:** Der Alarm wird nicht erneut versucht und die Benachrichtigung geht dauerhaft verloren.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
|
1. Einführung einer Tabelle `notification_outbox` mit Spalten `retry_count`, `next_retry_at`, `status`.
|
||||||
|
2. Exponentieller Backoff (1m, 5m, 15m, 1h) und Status-Markierung (*failed*, *delivered*).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### FLAW-08: Statische JWT-Tokens ohne Blacklisting
|
||||||
|
- **Betroffene Komponenten:** [`architecture.md`](./architecture.md), `internal/api/auth.go`
|
||||||
|
- **Ursache:** Nach dem Login wird ein JWT ausgestellt, das clientseitig im `localStorage` gespeichert wird. Der Server prüft lediglich die kryptografische Signatur des Tokens, führt aber keine serverseitige Sitzungsliste.
|
||||||
|
- **Folgen:** Wird einem Benutzer die Berechtigung entzogen oder ändert er sein Passwort, bleibt ein bereits ausgestellter Token bis zu seinem Ablaufdatum (z. B. 7 Tage) gültig.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
|
1. Einführung einer `revoked_tokens`-Tabelle oder einer `token_version`-Spalte in der `users`-Tabelle.
|
||||||
|
2. Implementierung von kurzlebigen Access-Tokens (15 Min.) in Verbindung mit rotierenden Refresh-Tokens in `httpOnly`-Cookies.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### FLAW-09: Mobile Viewport-Verschiebung durch Virtual-Keyboard
|
||||||
|
- **Betroffene Komponenten:** `frontend/src/routes/+layout.svelte`, `frontend/src/lib/components/BottomNav.svelte`
|
||||||
|
- **Ursache:** Öffnet sich auf iOS Safari oder Android Chrome die Bildschirmtastatur, ändert der Browser die Höhe des sichtbaren Viewports dynamisch. Feste CSS-Attribute wie `height: 100vh` oder `fixed bottom-0` führen dazu, dass Eingabefelder unter die Tastatur rutschen oder die Navigationsleiste den Bildschirm verdeckt.
|
||||||
|
- **Folgen:** In der mobilen Triage- und Aufgabenansicht muss der Nutzer manuell scrollen, um die Speichern-Buttons zu erreichen.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
|
1. Nutzung der modernen `window.visualViewport`-API in Svelte.
|
||||||
|
2. Dynamisches Setzen einer CSS-Variable `--vvh` (`visualViewport.height`) zur präzisen Anpassung von Modals und Bottom-Sheets.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### FLAW-10: Kein hierarchischer Undo/Redo-Stack im Outliner
|
||||||
|
- **Betroffene Komponenten:** [`modules/workspace.md`](./modules/workspace.md), `frontend/src/lib/components/Outliner.svelte`
|
||||||
|
- **Ursache:** Standardmäßiges Browser-`Ctrl+Z` funktioniert nur innerhalb eines einzelnen aktiven Textfelds (`contenteditable`). Strukturelle Aktionen – wie das Verschieben von Blöcken via Drag & Drop, Einrücken (`Tab`), Ausrücken (`Shift+Tab`) oder das Löschen ganzer Unterbäume – sind im Standard-Browser-Undo-Stack nicht enthalten.
|
||||||
|
- **Folgen:** Verschiebt ein Nutzer versehentlich einen Block samt 10 Unterpunkten, kann dies nicht mit `Ctrl+Z` rückgängig gemacht werden.
|
||||||
|
- **Empfohlene Lösung:**
|
||||||
|
1. Implementierung eines expliziten In-Memory Command-Stacks im Frontend (Command-Pattern: `execute()` / `undo()`).
|
||||||
|
2. Aufzeichnung aller Block-Mutationen (Insert, Indent, Move, Delete) mit Revert-Payloads.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧭 Verwandte Dokumente
|
||||||
|
- 🏗️ [Gesamtarchitektur](architecture.md)
|
||||||
|
- 💾 [Datenbank-Design & Tabellenschemata](database.md)
|
||||||
|
- 🔌 [WebSocket & Live-Protokoll](api/websocket.md)
|
||||||
|
- 🧠 [Workspace-Modul (Outliner)](modules/workspace.md)
|
||||||
|
- 🛡️ [Rechte & Freigabesystem](sharing-and-permissions.md)
|
||||||
+57
-14
@@ -1,19 +1,62 @@
|
|||||||
# Modul: Geteilte Listen
|
# 🛒 Kernmodul 4: Geteilte Listen & Kollaboration
|
||||||
|
|
||||||
Einkaufs-, Pack- und Checklisten für gemeinsames Arbeiten. Code: [SharedListsView.tsx](../../frontend/src/features/lists/SharedListsView.tsx); Backend: `*List*`-Handler in [server.go](../../internal/api/server.go), `Store.CreateList` und Verwandte.
|
Das Modul für geteilte Listen ([`SharedListsView.tsx`](../../frontend/src/features/lists/SharedListsView.tsx)) ist auf **Echtzeit-Kollaboration im Alltag** ausgelegt (z.B. gemeinsamer Wocheneinkauf im Supermarkt, Packlisten für Reisen, Inventarlisten oder schnelle Checklisten).
|
||||||
|
|
||||||
## Datenmodell
|
---
|
||||||
|
|
||||||
- `lists`: Eigentümer, `title`, `icon`, `list_type` (`shopping`, `checklist`, `vacation`).
|
## 🛍️ 1. Listen-Typen & Kategorien
|
||||||
- `list_items`: `content`, `category`, `quantity`, `is_completed`, `completed_by(_name)`, `sort_order`.
|
|
||||||
- `list_shares`: Ziel (Benutzer oder Gruppe) und Rolle `editor` oder `viewer`.
|
|
||||||
|
|
||||||
## Funktionen
|
Jede Liste besitzt einen Typ, ein Icon und eine Farb-Codierung:
|
||||||
|
|
||||||
- **Kategorien per Hashtag:** `Hafermilch #Kühlregal` landet in der Kategorie „Kühlregal“. Kategorien werden alphabetisch als Abschnitte angezeigt; die Eingabe schlägt vorhandene Hashtags vor.
|
| Listen-Typ | Icon | Einsatzzweck | Typische Kategorien |
|
||||||
- **Menge:** Feld `quantity` (z. B. `2x`, `500g`).
|
| :--- | :--- | :--- | :--- |
|
||||||
- **Drag & Drop** ordnet Einträge um; in eine andere Kategorie gezogen, wird der Hashtag im Text angepasst (`items/reorder` mit `category` und `content`).
|
| `shopping` | 🛒 | Supermarkt- & Lebensmitteleinkauf | Obst & Gemüse, Kühlregal, Vorrat, Drogerie |
|
||||||
- **Abhaken** speichert, wer und wann; Erledigte stehen in einem eigenen Bereich und lassen sich per „Erledigte entfernen“ löschen (`clear-completed`).
|
| `packing` | 🎒 | Urlaubs- & Reise-Packlisten | Kleidung, Elektronik, Dokumente, Kosmetik |
|
||||||
- **Freigabe** über den Dialog `UnifiedShareModal` (Bearbeiten oder Nur Lesen). Ein Leser sieht Änderungen live, ändert aber nichts.
|
| `inventory` | 📦 | Vorratskammer, Keller, Homelab-Hardware | Regal 1, Gefrierschrank, Server-Rack |
|
||||||
- **Live-Sync:** Ereignisse `ITEM_*` und `LIST_*` im Raum der Liste ([websocket.md](../api/websocket.md)). Abhaken erscheint bei allen Beteiligten sofort.
|
| `todo` | 📝 | Einfache Gruppen-Checklisten | Heute, Später, Ideen |
|
||||||
- Aus der Triage lassen sich Gedanken direkt als Eintrag in eine Liste übernehmen.
|
|
||||||
|
### Automatische Kategorisierung & Mengenangaben
|
||||||
|
- Einträge können mit einer Mengenangabe (z.B. `3x`, `500g`, `1 Kasten`) versehen werden.
|
||||||
|
- Die intelligente Eingabe erkennt Einheiten automatisch oder trennt Mengen über Eingabefelder.
|
||||||
|
- Einträge werden übersichtlich nach Kategorien gruppiert. Jede Kategorie kann zur besseren Übersicht eingeklappt werden.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚡ 2. Echtzeit-Abhaken (Multi-User Live Sync)
|
||||||
|
|
||||||
|
Wenn mehrere Familienmitglieder oder Teammitglieder gleichzeitig im Supermarkt unterwegs sind, synchronisiert MindSift jeden Schritt in Echtzeit über WebSockets:
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
actor Alice as Alice (im Markt)
|
||||||
|
participant WS as WebSocket Hub
|
||||||
|
actor Bob as Bob (zu Hause)
|
||||||
|
|
||||||
|
Alice->>WS: PATCH /items/123 (isCompleted: true)
|
||||||
|
WS->>Bob: Event: ITEM_TOGGLED (itemId: "123", completedBy: "Alice")
|
||||||
|
Note over Bob: Eintrag wird sofort durchgestrichen<br/>Grünes Badge "von Alice" erscheint
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Transparenz:** Beim Abhaken speichert MindSift `completed_by_name`. Ein dezentes grünes Pillen-Badge zeigt an, wer den Artikel eingepackt hat.
|
||||||
|
- **Erledigte Einträge:** Abgehakte Artikel wandern nach unten in einen einklappbaren Bereich „Erledigt".
|
||||||
|
- **Liste leeren:** Ein Klick auf „Erledigte entfernen" löscht alle abgehakten Einträge (`LIST_CLEARED`) für alle Teilnehmer.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🖐️ 3. Drag & Drop Umsortierung
|
||||||
|
|
||||||
|
Innerhalb einer Liste können Einträge frei per Drag & Drop sortiert werden:
|
||||||
|
1. **Innerhalb einer Kategorie:** Ändert die Reihenfolge (`sort_order`).
|
||||||
|
2. **Kategorie-Übergreifend:** Zieht der Benutzer einen Eintrag in eine andere Kategorie (z.B. von „Kühlregal" nach „Obst & Gemüse"), aktualisiert das Frontend optimistisch die Kategorie und sendet das Update ans Backend.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 👥 4. Freigaben & Berechtigungen
|
||||||
|
|
||||||
|
Listen können über den einheitlichen Freigabe-Dialog ([`UnifiedShareModal.tsx`](../../frontend/src/components/UnifiedShareModal.tsx)) geteilt werden:
|
||||||
|
- **Freigabe für Teams:** Alle aktuellen und zukünftigen Mitglieder der gewählten Gruppe erhalten automatisch Zugriff.
|
||||||
|
- **Freigabe für Einzelbenutzer:** Gezielter Zugriff für einzelne Personen.
|
||||||
|
- **Rollen:**
|
||||||
|
- `editor`: Darf Einträge hinzufügen, bearbeiten, abhaken und löschen.
|
||||||
|
- `viewer`: Nur Lesezugriff (Einträge ansehen, aber nicht verändern).
|
||||||
+74
-26
@@ -1,38 +1,86 @@
|
|||||||
# Modul: Aufgaben, Kanban & Alarme
|
# 📋 Kernmodul 2: Aufgaben & Kanban-System
|
||||||
|
|
||||||
Code: [TasksView.tsx](../../frontend/src/features/triage/TasksView.tsx), [TaskDetailModal.tsx](../../frontend/src/features/triage/TaskDetailModal.tsx), [ManageColumnsModal.tsx](../../frontend/src/features/triage/ManageColumnsModal.tsx); Backend: `handleUpdateThought`, `handleReorderTasks`, `*TaskList*`-Handler, `startAlarmTicker`.
|
Das Aufgaben-Modul ([`TasksView.tsx`](../../frontend/src/features/triage/TasksView.tsx)) bietet eine flexible Aufgabenverwaltung mit frei konfigurierbaren Listen, Kanban-Boards, Subtask-Checklisten und einem automatisierten Multi-Channel Alarm-System.
|
||||||
|
|
||||||
## Datenmodell
|
---
|
||||||
|
|
||||||
Eine Aufgabe ist ein `thought` ([database.md](../database.md)) mit `kanbanStatus`, `priority` (`low`/`normal`/`high`/`urgent`), `dueDate` (nur Datum), `notes` (Markdown), `subtasks` (`[{id, title, isCompleted}]`), `tags`, `taskListId` und `sortOrder`. Aufgaben ohne Liste sind persönlich.
|
## 🗂️ 1. Datenmodell & Listen-Hierarchie
|
||||||
|
|
||||||
## Ansichten
|
Aufgaben basieren technisch auf der Tabelle **`thoughts`** in SQLite. Ein Eintrag gilt als Aufgabe, wenn `status = 'kept'` oder `(status = 'converted' AND converted_type = 'task')` zutrifft.
|
||||||
|
|
||||||
- **Liste** mit Filtern (offen, erledigt, Papierkorb), Gruppierung (z. B. nach Status oder Fälligkeit), Sortierung und Hashtag-Filter.
|
```
|
||||||
- **Kanban:** Spalten pro Liste frei konfigurierbar (Name, Farbe, „Erledigt“-Spalte). Standard: *Zu erledigen*, *In Bearbeitung*, *Wartet auf andere*, *Erledigt*. Eine Karte in eine „Erledigt“-Spalte zu ziehen setzt `isCompleted`.
|
Benutzer (users)
|
||||||
- Drag & Drop sortiert in der Liste und zwischen Spalten; ein Klick öffnet das Detail-Fenster (Titel, Status, Priorität, Fälligkeit mit Schnellwahl, Liste, Hashtags, Unteraufgaben mit Fortschrittsbalken, Notizen).
|
└── Aufgabenlisten (task_lists)
|
||||||
- Aufgaben lassen sich in eine Notiz umwandeln („Als Notiz vertiefen“). Aufgaben aus Notiz-Checkboxen (`enhanced-task`) bleiben verknüpft: Abhaken wirkt in beide Richtungen (`SyncDocBlockAndTask`), „In Notiz öffnen“ springt zum Block.
|
├── Eigene Listen (z.B. "Privat", "Homelab")
|
||||||
|
└── Mit Teams geteilte Listen (task_list_shares)
|
||||||
|
└── Aufgaben (thoughts)
|
||||||
|
├── Kanban-Status (todo, in_progress, done)
|
||||||
|
├── Priorität (low, normal, high, urgent)
|
||||||
|
├── Fälligkeitsdatum (dueDate)
|
||||||
|
├── Notizen (notes)
|
||||||
|
└── Subtasks (JSON Array von Teilaufgaben)
|
||||||
|
```
|
||||||
|
|
||||||
## Aufgabenlisten und Freigabe
|
### Listen-Sharing & Avatar-Stack
|
||||||
|
Aufgabenlisten können für Gruppen/Teams freigegeben werden. Ein Avatar-Stack im Listen-Header und in der Tab-Leiste visualisiert alle Mitglieder, die Zugriff auf die jeweilige Liste haben.
|
||||||
|
|
||||||
- Jede Liste hat Eigentümer, Titel, Symbol, Farbe und eigene Kanban-Spalten.
|
---
|
||||||
- Freigabe an Gruppen oder Benutzer über den Dialog `UnifiedShareModal` (Stufe pro Freigabe):
|
|
||||||
- **Bearbeiter:** darf Aufgaben anlegen, ändern, abhaken, verschieben, löschen sowie Liste umbenennen und Spalten ändern.
|
|
||||||
- **Leser:** sieht alles, kann nichts ändern. Der Server antwortet mit `403`; die Oberfläche blendet Eingaben aus und zeigt „Nur Lesen“.
|
|
||||||
- Gruppenmitglieder mit mehreren Wegen erhalten die höchste Stufe. Nur der Eigentümer legt Freigaben an oder entfernt sie und kann die Liste löschen.
|
|
||||||
- Umsetzung: `Store.GetTaskListPermission` liefert `owner`/`editor`/`viewer`/`""`; `ensureTaskListWritable` schützt Schreibpfade.
|
|
||||||
- Bekannte Lücken: [FLAW-03](../flaws.md) (Umsortieren per ID), [FLAW-06](../flaws.md) (Editor kann weiterteilen).
|
|
||||||
|
|
||||||
## Alarme
|
## 🖥️ 2. Ansichten: Liste vs. Kanban-Board
|
||||||
|
|
||||||
Der Ticker läuft jede Minute ([architecture.md](../architecture.md)). Für offene Aufgaben mit `due_date <= heute` und `alarm_sent = 0` sendet er an die Kanäle des Aufgaben-**Eigentümers**:
|
Der Benutzer kann jederzeit nahtlos zwischen zwei Ansichten umschalten:
|
||||||
|
|
||||||
| Kanal | Ziel | Konfiguration |
|
### 1. Kompakte Listenansicht
|
||||||
|---|---|---|
|
- Optimiert für schnelles Abarbeiten und Tastatursteuerung.
|
||||||
| E-Mail | `alarmEmail` (sonst Konto-Adresse) | SMTP aus Admin-Einstellungen oder Umgebung (Port 465 mit TLS wird direkt unterstützt, sonst STARTTLS über `smtp.SendMail`) |
|
- Zeigt Checkbox, Titel, Prioritäts-Badge, Herkunfts-Pille (`Webhook`, `Diktat`), Fälligkeitsdatum und Subtask-Zähler (`2/5`).
|
||||||
| Discord | Webhook-URL | Benutzereinstellungen |
|
- 1-Klick-Prioritäts-Wechsel: Klick auf ein Badge rotiert durch die Prioritäten.
|
||||||
| Webhook | beliebige URL (JSON: `event`, `title`, `notes`, `dueDate`, `priority`, `timestamp`) | Benutzereinstellungen |
|
|
||||||
|
|
||||||
Danach wird `alarm_sent = 1` gesetzt, sobald mindestens ein Kanal erfolgreich war.
|
### 2. Kanban-Board (Drag & Drop)
|
||||||
|
- Standardmäßig 3 Spalten: **Zu erledigen** (`todo`), **In Arbeit** (`in_progress`) und **Erledigt** (`done`).
|
||||||
|
- **Freie Spalten-Konfiguration:** Über das Spalten-Menü können Spalten umbenannt, farblich markiert oder neue Spalten hinzugefügt werden.
|
||||||
|
- **Drag & Drop:** Aufgaben können per HTML5 Drag & Drop zwischen Spalten verschoben werden. Das Backend speichert die relative Position (`sort_order`) und den neuen `kanban_status` automatisch.
|
||||||
|
|
||||||
Einschränkungen ([FLAW-12](../flaws.md)): Fälligkeiten haben keine Uhrzeit, `notifyBeforeMinutes` wird ignoriert, die Serverzeit gilt, und ein verschobener Termin löst nicht erneut aus. URLs werden nicht geprüft ([FLAW-05](../flaws.md)).
|
---
|
||||||
|
|
||||||
|
## 🎯 3. Prioritäten & Subtasks
|
||||||
|
|
||||||
|
### 4-Stufen-Prioritätensystem
|
||||||
|
Aufgaben unterstützen vier einheitliche Prioritätsstufen:
|
||||||
|
- **Niedrig (`low`):** Dezent grau hinterlegt.
|
||||||
|
- **Normal (`normal`):** Akzentfarbe.
|
||||||
|
- **Wichtig (`high`):** Gelb hervorgehoben mit Warndreieck (`⚠️ Wichtig`).
|
||||||
|
- **Dringend (`urgent`):** Rot pulsierend mit Flammen-Icon (`🔥 Dringend`).
|
||||||
|
|
||||||
|
### Subtasks (Teilaufgaben)
|
||||||
|
Jede Aufgabe kann eine hierarchische Checkliste von Subtasks enthalten:
|
||||||
|
- Gespeichert als JSON in der Spalte `subtasks`.
|
||||||
|
- Fortschrittsanzeige im Kartenkopf (z.B. `3/5 erledigt`).
|
||||||
|
- Einzelnes Abhaken synchronisiert direkt in die Datenbank.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⏰ 4. Multi-Channel Alarm-Scheduler
|
||||||
|
|
||||||
|
MindSift enthält einen serverseitigen Hintergrund-Ticker in Go ([`internal/api/server.go`](../../internal/api/server.go)), der fällige Aufgaben proaktiv an externe Kanäle meldet.
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TD
|
||||||
|
Ticker["Go Background Ticker (alle 30s)"] --> Query["SELECT thoughts WHERE due_date <= now + Vorwarnzeit AND alarm_sent = 0"]
|
||||||
|
Query --> CheckChannels{"Welche Kanäle sind beim User aktiv?"}
|
||||||
|
|
||||||
|
CheckChannels -->|email| SendSMTP["E-Mail via SMTP versenden"]
|
||||||
|
CheckChannels -->|discord| SendDiscord["Discord Webhook POST"]
|
||||||
|
CheckChannels -->|webhook| SendCustom["Custom HTTP POST Webhook"]
|
||||||
|
|
||||||
|
SendSMTP --> MarkSent["UPDATE thoughts SET alarm_sent = 1"]
|
||||||
|
SendDiscord --> MarkSent
|
||||||
|
SendCustom --> MarkSent
|
||||||
|
```
|
||||||
|
|
||||||
|
### Alarm-Konfiguration
|
||||||
|
1. **Vorwarnzeit:** Einstellbar in Minuten (z.B. 15, 30, 60 Minuten vor Fälligkeit).
|
||||||
|
2. **Kanal-Multi-Select:** Benutzer können beliebig viele Kanäle parallel aktivieren:
|
||||||
|
- **E-Mail:** Versand über den in den Admin-Einstellungen hinterlegten SMTP-Server.
|
||||||
|
- **Discord:** Benachrichtigung mit formatierter Embed-Karte in einen Discord-Kanal.
|
||||||
|
- **Eigener Webhook:** Beliebige HTTP POST JSON Endpunkte (z.B. Gotify, Ntfy, Home Assistant).
|
||||||
|
3. **Schutz vor Doppel-Alarmen:** Sobald ein Alarm abgesetzt wurde, wird `alarm_sent = 1` gesetzt. Wird das Datum der Aufgabe später geändert, setzt der Server `alarm_sent = 0` automatisch zurück.
|
||||||
+77
-25
@@ -1,36 +1,88 @@
|
|||||||
# Modul: Schnellerfassung & Triage
|
# 📥 Kernmodul 1: Triage & Quick-Dump Engine
|
||||||
|
|
||||||
Ziel: Gedanken in Sekunden festhalten und später in Ruhe sortieren. Code: [InstantCaptureBar.tsx](../../frontend/src/features/capture/InstantCaptureBar.tsx), [TriageDeck.tsx](../../frontend/src/features/triage/TriageDeck.tsx), Backend `handleCaptureInbox`, `handleTriageAction` und `Store.UpdateThoughtTriage`.
|
Das Triage-Modul von MindSift basiert auf dem *Getting Things Done (GTD)*-Prinzip. Es trennt die **Erfassung von Gedanken** strikt von der **Entscheidung, was damit geschehen soll**.
|
||||||
|
|
||||||
## Erfassung
|
---
|
||||||
|
|
||||||
- Die Eingabeleiste sitzt im Header; `C` oder `/` fokussiert sie (außer beim Tippen in einem Feld).
|
## 💡 1. Das 2-Phasen-Konzept
|
||||||
- Ziel (`target`): **Posteingang** (`inbox`, Standard), **Direkt-Aufgabe** (`task`), **Listeneintrag** (`list_item`, mit Zielliste) oder **Direkt-Notiz** (`document`).
|
|
||||||
- Mehrzeilige Eingabe wird unterstützt. Spracheingabe nutzt die Web Speech API des Browsers; Quelle `voice` fügt den Tag `#diktat` an.
|
|
||||||
- Quelle `webhook` (per API-Key/Webhook) fügt den Tag `#webhook` an. Hashtags im Text werden als Tags extrahiert (`domain.ExtractTags`).
|
|
||||||
- Per API: `POST /inbox` und `POST /webhooks/ingest` (siehe [rest.md](../api/rest.md)).
|
|
||||||
|
|
||||||
## Triage-Deck
|
1. **Phase 1: Schnelles Erfassen (Instant Dump)**
|
||||||
|
Ein Gedanke, ein Anruf, eine Idee oder ein Server-Alarm wird ohne Reibung erfasst. Der Benutzer muss in diesem Moment weder ein Projekt auswählen, noch Fälligkeitsdaten eingeben oder Ordner durchsuchen.
|
||||||
|
2. **Phase 2: Fokussierte Triage (Inbox Zero)**
|
||||||
|
Zu einem späteren Zeitpunkt (z.B. morgens oder beim Feierabend) sichtet der Benutzer den Stapel im Triage-Deck Karte für Karte und trifft für jeden Eintrag eine eindeutige Entscheidung.
|
||||||
|
|
||||||
Der Posteingang (`status = inbox`) wird Karte für Karte abgearbeitet.
|
---
|
||||||
|
|
||||||
| Aktion | Desktop | Mobil | Ergebnis |
|
## 🔄 2. Triage State Machine
|
||||||
|---|---|---|---|
|
|
||||||
| Verwerfen | `H` oder `←` | Wischen links | `status = discarded` (Papierkorb) |
|
|
||||||
| Zur Aufgabe | `L` oder `→` | Wischen rechts | `kept`/`converted` als Aufgabe |
|
|
||||||
| Aufgabe mit Termin | `T` | Aktionsmenü | wie oben, mit Fälligkeit |
|
|
||||||
| In Notiz wandeln | `D` | Aktionsmenü | neues Dokument, Gedanke wird `converted` (`document`) |
|
|
||||||
| Später | Leertaste | Aktionsmenü | Karte ans Stapelende |
|
|
||||||
| Menü schließen | `Esc` | – | – |
|
|
||||||
|
|
||||||
Die Umwandlung in eine Notiz übernimmt Titel, Erledigt-Status, Notizen, Unteraufgaben sowie Fälligkeit und Priorität als eingerückte Blöcke. Eine Umwandlung in einen Listeneintrag legt einen Eintrag in der gewählten Liste an und benachrichtigt deren Teilnehmer.
|
```mermaid
|
||||||
|
stateDiagram-v2
|
||||||
|
[*] --> Capture: Gedanke erfasst (Desktop / Mobile / Webhook)
|
||||||
|
|
||||||
## Zustände eines Gedankens
|
Capture --> Inbox: Standard (status: 'inbox')
|
||||||
|
Capture --> Task: Direkt als Aufgabe (target: 'task')
|
||||||
|
Capture --> Document: Direkt als Notiz (target: 'document')
|
||||||
|
Capture --> ListItem: Direkt auf Liste (target: 'list_item')
|
||||||
|
|
||||||
```
|
state Inbox {
|
||||||
inbox ──keep──▶ kept ──convert──▶ converted (task | document | list_item)
|
[*] --> ActiveCard: Oben auf Stapel
|
||||||
│ │
|
ActiveCard --> Skipped: Leertaste / Später (Ans Ende)
|
||||||
└─discard─▶ discarded ──restore──▶ inbox (Papierkorb leeren: DELETE /thoughts/discarded/purge)
|
Skipped --> ActiveCard
|
||||||
|
}
|
||||||
|
|
||||||
|
ActiveCard --> Discarded: Swipe links / H (Wegwerfen)
|
||||||
|
ActiveCard --> Task: Swipe rechts / L (Als Aufgabe)
|
||||||
|
ActiveCard --> TaskDated: T (Mit Fälligkeitsdatum)
|
||||||
|
ActiveCard --> Document: D (In Notiz umwandeln)
|
||||||
|
ActiveCard --> ListItem: Auf Liste schieben
|
||||||
|
|
||||||
|
Discarded --> Trash: status: 'discarded'
|
||||||
|
Task --> TasksModule: status: 'kept', converted: 'task'
|
||||||
|
TaskDated --> TasksModule: status: 'kept', converted: 'task', dueDate
|
||||||
|
Document --> WorkspaceModule: status: 'converted', converted: 'document'
|
||||||
|
ListItem --> ListsModule: status: 'converted', converted: 'list_item'
|
||||||
```
|
```
|
||||||
|
|
||||||
Ein Gedanke mit `status = kept` zählt bereits als Aufgabe und erscheint in der Aufgabenansicht.
|
---
|
||||||
|
|
||||||
|
## 🖐️ 3. Steuerung & Gesten (Mobile vs. Desktop)
|
||||||
|
|
||||||
|
### Desktop-Bedienung (Tastatur-First)
|
||||||
|
- `C` oder `/`: Fokussiert sofort die Eingabeleiste oben im Header.
|
||||||
|
- `Enter`: Speichert den Gedanken sofort im Deck.
|
||||||
|
- `←` oder `H`: Aktive Karte wegwerfen (`discard`).
|
||||||
|
- `→` oder `L`: Aktive Karte sofort zur Aufgabe machen (`task`).
|
||||||
|
- `T`: Datumsauswahl für Termin-Aufgabe öffnen.
|
||||||
|
- `D`: Aktive Karte in eine vollwertige Workspace-Notiz umwandeln.
|
||||||
|
- `Leertaste`: Karte überspringen und ans Ende des Stapels schieben („Später").
|
||||||
|
|
||||||
|
### Mobile Bedienung (Touch & Swipe)
|
||||||
|
- **Mittlerer Plus-Button (`+`):** Öffnet das design-angeglichene Bottom-Sheet mit Spracheingabe, 4 Prioritäts-Buttons (`Niedrig`, `Normal`, `Wichtig`, `Dringend`) und Fälligkeitsdatum.
|
||||||
|
- **Wischgeste nach links (Swipe Left):** Roter Indikator erscheint, Karte wird verworfen.
|
||||||
|
- **Wischgeste nach rechts (Swipe Right):** Grüner Indikator erscheint, Karte wird sofort zur Aufgabe.
|
||||||
|
- **Long-Press (Langes Drücken auf Karte):** Öffnet das Schnell-Aktions-Menü (Auf Liste, Mit Termin, Als Notiz, Später).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎙️ 4. Spracheingabe (Speech-to-Text)
|
||||||
|
|
||||||
|
In der Desktop-Schnelleingabeleiste ([`InstantCaptureBar.tsx`](../../frontend/src/features/capture/InstantCaptureBar.tsx)) sowie im mobilen Triage-Modal ([`App.tsx`](../../frontend/src/App.tsx)) ist ein nativer Browser-Sprachassistent integriert:
|
||||||
|
- Verwendet die standardisierte `SpeechRecognition` bzw. `webkitSpeechRecognition` API.
|
||||||
|
- Erkennt Sprache auf Deutsch (`lang: 'de-DE'`).
|
||||||
|
- Live-Transkription: Gesprochener Text wird in Echtzeit in das Textfeld eingefügt.
|
||||||
|
- Haptisches Feedback: Vibrieren beim Starten und Stoppen der Aufnahme.
|
||||||
|
- Markiert erfasste Gedanken automatisch mit dem Herkunfts-Attribut `source: 'voice'` (Diktat-Badge).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚡ 5. Webhook-Ingestion & Smarthome-Pille
|
||||||
|
|
||||||
|
MindSift kann externe Alarme (Home Assistant, Zigbee2MQTT, n8n, Proxmox, Monitoring) automatisch ins Triage-Deck einspeisen:
|
||||||
|
|
||||||
|
### Herkunftserkennung
|
||||||
|
1. Wird ein Gedanke über `/api/v1/inbox` mit `X-API-Key` oder über `/api/v1/webhooks/ingest` eingeliefert, setzt das Backend automatisch `source = "webhook"`.
|
||||||
|
2. Im Frontend visualisiert die Triage-Karte eine dezente Webhook-Pille (`<Webhook className="w-3 h-3 text-accent" /> Webhook`).
|
||||||
|
3. Diese Kennzeichnung bleibt auch erhalten, wenn die Karte später zu einer Aufgabe umgewandelt wird.
|
||||||
|
|
||||||
|
### Live-WebSocket Update
|
||||||
|
Nach erfolgreichem Ingest sendet der Server sofort ein `TASK_CREATED` Event über den WebSocket-Hub. Das geöffnete Triage-Deck fügt die neue Alarm-Karte sofort oben in den Stapel ein – ohne dass der Benutzer die Seite neu laden muss.
|
||||||
+71
-28
@@ -1,39 +1,82 @@
|
|||||||
# Modul: Workspace (Outliner-Notizen)
|
# 📝 Kernmodul 3: Workspace Outliner-Engine, Wiki-Links & Disk-Sync
|
||||||
|
|
||||||
Code: [WorkspaceView.tsx](../../frontend/src/features/workspace/WorkspaceView.tsx) (Explorer, Tags, To-Do-Rollup), [DocumentEditor.tsx](../../frontend/src/features/workspace/DocumentEditor.tsx), [OutlinerTree.tsx](../../frontend/src/features/workspace/OutlinerTree.tsx), [OutlinerBlock.tsx](../../frontend/src/features/workspace/OutlinerBlock.tsx), [CodeBlockItem.tsx](../../frontend/src/features/workspace/CodeBlockItem.tsx), [LinkModal.tsx](../../frontend/src/features/workspace/LinkModal.tsx); Backend: Dokument-, Ordner- und Tag-Handler, `Store.PatchDocumentBlocks`.
|
Der MindSift Workspace ([`WorkspaceView.tsx`](../../frontend/src/features/workspace/WorkspaceView.tsx)) kombiniert ein **hierarchisches Bullet-Point Notizsystem (inspiriert von Logseq)** mit einem **persönlichen Markdown-Wiki** und einem **globalen To-Do Rollup Dashboard**.
|
||||||
|
|
||||||
## Datenhaltung
|
---
|
||||||
|
|
||||||
- Eine Notiz ist ein Datensatz in `documents` plus geordnete Zeilen in `blocks` (`position` als Kommazahl, `level` für die Einrückung). Alles liegt in SQLite; es gibt keine Dateien auf der Platte.
|
## 🌳 1. Die Logseq-Outliner-Engine
|
||||||
- Bei jeder Änderung wird `documents.markdown_cache` neu erzeugt; `block_tags` wird aus `#Hashtags` der Blöcke neu aufgebaut.
|
|
||||||
- Der Export als `.md` erfolgt im Browser (Button im Editor, Blob-Download).
|
|
||||||
- Blocktypen: Überschriften `h1`–`h3`, `paragraph`/`text`, `bullet`, `todo`, `code`, `callout`, `divider`, `table`, `progress`.
|
|
||||||
|
|
||||||
## Editor
|
Im Gegensatz zu klassischen Fließtext-Editoren basiert der MindSift Workspace auf **Blöcken** (`document_blocks` in SQLite). Jeder Block ist ein gedanklicher Knotenpunkt mit einer flexiblen Einrückungsebene (`level: 0, 1, 2, ...`).
|
||||||
|
|
||||||
- **Outliner:** `Enter` neuer Block, `Tab`/`Shift+Tab` ein-/ausrücken, `Shift+Enter` weicher Umbruch, Blöcke ein-/ausklappen.
|
```
|
||||||
- **Zoom (Hoisting):** Klick auf den Bullet fokussiert den Ast; die Breadcrumb-Leiste führt zurück.
|
• Projekt MindSift v2.0 (level 0)
|
||||||
- **Drag & Drop** verschiebt Blöcke samt Unterästen; auf einen anderen Block gezogen, wird der Block zum Unterpunkt.
|
• Architektur-Entscheidung (level 1)
|
||||||
- **Slash-Befehle:** `/todo`, `/link`, `/h1`, `/h2`, `/h3`, `/code`, `/callout`, `/divider` (Liste in `OutlinerBlock.tsx`).
|
- [x] Database-First Blocks implementieren (level 2)
|
||||||
- **Links:** `[[Notiztitel]]`, Markdown-Links `[Titel](url)` und reine URLs werden als Token dargestellt; `LinkModal` hilft beim Verknüpfen von Notizen.
|
- [ ] Performance Benchmark mit 10.000 Blöcken (level 2)
|
||||||
- **Einfügen:** Mehrzeiliger Text wird anhand von Markdown-Präfixen und Einrückung in Blöcke zerlegt; Überschriften gruppieren darunterliegenden Text und Code.
|
• Notizen aus dem Dev-Meeting (level 1)
|
||||||
- **Speichern:** Der Editor speichert 800 ms nach der letzten Eingabe das gesamte Dokument (`PUT /documents/{id}`). Der schlanke Block-Endpunkt `PATCH /documents/{id}/blocks` wird derzeit vom To-Do-Rollup beim Abhaken genutzt.
|
> Wichtig: Keine verschachtelten SQLite Queries ausführen! (level 2)
|
||||||
|
```
|
||||||
|
|
||||||
## Explorer, Tags, To-Dos
|
### Tastatur-Navigation & Shortcuts
|
||||||
|
- `Enter`: Erstellt einen neuen Block auf derselben Hierarchieebene.
|
||||||
|
- `Tab`: Rückt den aktuellen Block ein (wird Kindknoten des vorherigen Blocks).
|
||||||
|
- `Shift + Tab`: Rückt den Block um eine Ebene aus (verringert die Tiefe).
|
||||||
|
- `Shift + Enter`: Weicher Zeilenumbruch innerhalb desselben Blocks (z.B. für mehrzeilige Notizen oder Code).
|
||||||
|
- `Backspace` (auf leerem Block): Rückt den Block aus oder löscht ihn, wenn er auf Level 0 ist.
|
||||||
|
- `/` (Slash-Commands): Öffnet das Umwandlungsmenü (`/todo`, `/h1`, `/h2`, `/h3`, `/code`, `/callout`, `/quote`, `/divider`).
|
||||||
|
|
||||||
- Ordnerbaum mit Favoriten (`doc_pins`), Verschieben per Drag & Drop (`/documents/{id}/move`, `/folders/move`).
|
### Zoom-In Hoisting (Fokus-Modus)
|
||||||
- **Tags:** Alle `#Hashtags` werden aggregiert (`/workspace/tags`). Eine Tag-Seite zeigt alle Fundstellen gruppiert nach Notiz und kann eine eigene Freitext-Notiz tragen (`tag_pages`).
|
Klickt der Benutzer auf den Bullet-Dot (`•`) eines Blocks, blendet der Editor alle übergeordneten und benachbarten Blöcke aus und zoomt **ausschließlich in diesen Ast** hinein.
|
||||||
- **To-Do-Rollup:** Die Ansicht „To-Dos“ sammelt alle `todo`-Blöcke aller Notizen, filterbar nach Ordner. Abhaken im Rollup ändert den Block in der Notiz.
|
- Eine dezente Breadcrumb-Leiste oben zeigt den Pfad an (z.B. `Workspace / Projekte / MindSift / Architektur`).
|
||||||
- **Enhanced Tasks:** Ein `todo`-Block lässt sich als verknüpfte Aufgabe führen (`/documents/{id}/blocks/{blockId}/enhanced-task`); Erledigt-Status bleibt zwischen Notiz und Aufgabenansicht synchron.
|
- Ein Klick auf ein beliebiges Breadcrumb-Element zoomt sofort auf die jeweilige Ebene zurück.
|
||||||
|
|
||||||
## Freigabe
|
### Drag & Drop von Blöcken
|
||||||
|
Der Bullet-Dot dient gleichzeitig als Drag-Anfasser. Wird ein Block verschoben, erkennt die Engine automatisch alle untergeordneten Kind-Blöcke (`isDescendantBlock`) und verschiebt den **kompletten Unterbaum** an die neue Zielposition.
|
||||||
|
|
||||||
- Einzelne Notizen und ganze **geteilte Ordner** lassen sich an Benutzer oder Gruppen geben. Empfänger haben **nur Leserechte**; nur der Eigentümer schreibt ([sharing-and-permissions.md](../sharing-and-permissions.md), [FLAW-17](../flaws.md)).
|
---
|
||||||
- Empfänger ordnen geteilte Notizen und Ordner in ihrem eigenen Baum ein (`doc_user_folders`, `workspace_folder_mounts`), ohne dass der Eigentümer etwas davon merkt.
|
|
||||||
- Änderungen erreichen offene Fenster über `DOC_BLOCKS_PATCHED`/`DOC_UPDATED` ([websocket.md](../api/websocket.md)).
|
|
||||||
|
|
||||||
## Grenzen
|
## 🔗 2. Wiki-Links (`[[Link]]`) & Hashtags
|
||||||
|
|
||||||
- Keine gleichzeitige Mehrbenutzerbearbeitung, keine Cursor-Anzeige, keine Versionshistorie.
|
1. **Interne Wiki-Links:**
|
||||||
- Keine Virtualisierung langer Dokumente; sehr große Notizen können auf Mobilgeräten träge werden *(nicht gemessen)*.
|
- Text in doppelten eckigen Klammern (z.B. `[[Reiseplanung 2026]]`) wird automatisch als klickbarer Link gerendert.
|
||||||
- Suche (`/search`) erfasst nur Titel und Inhalt eigener Notizen ([FLAW-18](../flaws.md)).
|
- Ein Klick darauf durchsucht die Notizen des Benutzers und öffnet das Ziel-Dokument direkt im Editor.
|
||||||
|
2. **Hashtags (`#tag`):**
|
||||||
|
- Hashtags im Fließtext werden automatisch indiziert (`doc_block_tags`-Tabelle).
|
||||||
|
- In der linken Leiste listet der Tag-Explorer alle verwendeten Schlagworte auf. Klick auf ein Tag filtert alle Dokumente und Blöcke, die dieses Tag enthalten.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💾 3. Dual-Storage: Database-First & Disk-Mirroring
|
||||||
|
|
||||||
|
MindSift löst das Dilemma zwischen schneller relationaler Abfrage und portabler Dateispeicherung durch ein **synchrones Dual-Storage-Modell**:
|
||||||
|
|
||||||
|
```
|
||||||
|
Client (Block-Editor)
|
||||||
|
│ PATCH /api/v1/documents/:id/blocks
|
||||||
|
▼
|
||||||
|
Backend Engine
|
||||||
|
┌──────────────────────────────────────────────┐
|
||||||
|
│ 1. Transaktion in SQLite (document_blocks) │
|
||||||
|
│ -> Sort-Order, Content, Level, Checked │
|
||||||
|
│ 2. Volltext-Generierung (Markdown-String) │
|
||||||
|
│ 3. Schreiben auf Disk (/data/workspace/...) │
|
||||||
|
└──────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
1. **Präzision & Geschwindigkeit (SQLite):**
|
||||||
|
- Jeder Block besitzt eine eindeutige ID (`blk_...`) und eine Gleitkomma-Reihenfolge (`sort_order REAL`).
|
||||||
|
- Schnelle Status-Updates (z.B. Checkbox abhaken) schreiben nur genau eine Zeile in die Datenbank.
|
||||||
|
2. **Datensouveränität & Portabilität (Disk-Mirror):**
|
||||||
|
- Zeitgleich spiegelt der Server das Dokument als Standard-`.md`-Datei unter `/data/workspace/<user_id>/<ordner>/<dateiname>.md`.
|
||||||
|
- Einrückungen werden nach dem 2-Leerzeichen-Standard (` - [ ] `) formatiert.
|
||||||
|
- Administratoren können das Verzeichnis jederzeit mit externen Werkzeugen (Obsidian, Logseq, Git, rsync) sichern.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 4. Globaler To-Do Rollup Dashboard
|
||||||
|
|
||||||
|
Über den Tab **„Globale To-Dos"** bietet der Workspace eine aggregierte Übersicht aller im gesamten Wiki verteilten Aufgaben:
|
||||||
|
- Scannt in Echtzeit alle unvollendeten `- [ ] ` Checkboxen über alle Ordner und Notizen hinweg.
|
||||||
|
- Übersichtliche Gruppierung nach **Ordner ➔ Dokument ➔ Aufgabe**.
|
||||||
|
- **Ordner-Filter:** Klick auf einen Ordner isoliert nur dessen Aufgaben für fokussiertes Arbeiten.
|
||||||
|
- **2-Wege-Live-Sync:** Wird eine Checkbox im Rollup abgehakt, wird der Block in SQLite sofort auf `checked = 1` aktualisiert und die physische `.md`-Datei synchronisiert.
|
||||||
@@ -1,229 +0,0 @@
|
|||||||
# 🛡️ Reverse-Proxy & WebServer-Konfigurationshandbuch
|
|
||||||
|
|
||||||
Dieses Dokument beschreibt die empfohlene Konfiguration von Reverse-Proxies und Ingress-Controllern für MindSift. MindSift nutzt eine **hybride Realtime-Architektur** bestehend aus bidirektionalen **WebSockets** und einem automatischen **Server-Sent Events (SSE) Fallback**, um selbst in restriktivsten Firmennetzwerken, hinter strikten Firewalls oder bei Deep-Packet-Inspection unterbrechungsfreie Live-Synchronisation zu gewährleisten.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## ⚡ Wichtige Anforderungen auf einen Blick
|
|
||||||
|
|
||||||
| Protokoll | Standard-Port | Benötigte Header & Einstellungen | Zweck |
|
|
||||||
| :--- | :--- | :--- | :--- |
|
|
||||||
| **WebSockets** | 443 (WSS) / 80 (WS) | `Upgrade $http_upgrade`<br>`Connection "Upgrade"`<br>`proxy_read_timeout 3600s` | Bidirektionale Live-Updates (Aufgaben, Listen, Notizen) |
|
|
||||||
| **Server-Sent Events (SSE)** | 443 (HTTPS) / 80 (HTTP) | `X-Accel-Buffering: no`<br>`proxy_buffering off`<br>`proxy_cache off` | Fallback bei blockiertem WebSocket-Upgrade |
|
|
||||||
| **REST API & Uploads** | 443 (HTTPS) / 80 (HTTP) | `client_max_body_size 64M` | Notizen, Import/Export (JSON) |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 1. Nginx
|
|
||||||
|
|
||||||
Eine typische `nginx.conf` bzw. Site-Konfiguration unter `/etc/nginx/sites-available/mindsift`:
|
|
||||||
|
|
||||||
```nginx
|
|
||||||
# Map für sauberes Connection-Handling bei WebSocket-Upgrades
|
|
||||||
map $http_upgrade $connection_upgrade {
|
|
||||||
default upgrade;
|
|
||||||
'' close;
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name mindsift.example.com;
|
|
||||||
return 301 https://$host$request_uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 443 ssl http2;
|
|
||||||
server_name mindsift.example.com;
|
|
||||||
|
|
||||||
ssl_certificate /etc/letsencrypt/live/mindsift.example.com/fullchain.pem;
|
|
||||||
ssl_certificate_key /etc/letsencrypt/live/mindsift.example.com/privkey.pem;
|
|
||||||
|
|
||||||
# Maximale Payload-Größe für große Notizen und Exporte
|
|
||||||
client_max_body_size 64M;
|
|
||||||
|
|
||||||
# MindSift Frontend & REST API
|
|
||||||
location / {
|
|
||||||
proxy_pass http://127.0.0.1:8080;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
# 1. WebSocket Endpunkte (/api/v1/ws)
|
|
||||||
location /api/v1/ws {
|
|
||||||
proxy_pass http://127.0.0.1:8080;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
|
|
||||||
# Upgrade-Header zwingend erforderlich
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection $connection_upgrade;
|
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
|
|
||||||
# Verhindert vorzeitigen Verbindungsabbruch durch Proxy-Inaktivitäts-Timeout
|
|
||||||
proxy_read_timeout 3600s;
|
|
||||||
proxy_send_timeout 3600s;
|
|
||||||
}
|
|
||||||
|
|
||||||
# 2. Server-Sent Events Fallback (/api/v1/events & /api/v1/sync/)
|
|
||||||
location ~ ^/api/v1/(events|sync/) {
|
|
||||||
proxy_pass http://127.0.0.1:8080;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
|
|
||||||
# Pufferung zwingend deaktivieren für sofortiges Event-Streaming
|
|
||||||
proxy_buffering off;
|
|
||||||
proxy_cache off;
|
|
||||||
proxy_set_header X-Accel-Buffering no;
|
|
||||||
|
|
||||||
proxy_set_header Connection '';
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
|
|
||||||
proxy_read_timeout 86400s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 2. Traefik (Docker Compose / Ingress)
|
|
||||||
|
|
||||||
Bei Verwendung von Traefik Version 2/3 müssen keine expliziten WebSocket-Upgrades deklariert werden, da Traefik diese transparent durchleitet. Für Server-Sent Events und Timeouts empfehlen sich Middleware-Definitionen:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
mindsift:
|
|
||||||
image: ghcr.io/sandrodach/mindsift:latest
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
- PORT=8080
|
|
||||||
- DB_PATH=/app/data/mindsift.db
|
|
||||||
volumes:
|
|
||||||
- ./data:/app/data
|
|
||||||
labels:
|
|
||||||
- "traefik.enable=true"
|
|
||||||
- "traefik.http.routers.mindsift.rule=Host(`mindsift.example.com`)"
|
|
||||||
- "traefik.http.routers.mindsift.entrypoints=websecure"
|
|
||||||
- "traefik.http.routers.mindsift.tls.certresolver=letsencrypt"
|
|
||||||
- "traefik.http.services.mindsift.loadbalancer.server.port=8080"
|
|
||||||
|
|
||||||
# Verhindert Pufferung und hält persistente SSE-Streams am Leben
|
|
||||||
- "traefik.http.middlewares.mindsift-buffering.buffering.maxRequestBodyBytes=67108864"
|
|
||||||
- "traefik.http.routers.mindsift.middlewares=mindsift-buffering"
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 3. Caddy Server (Caddyfile)
|
|
||||||
|
|
||||||
Caddy unterstützt WebSockets und HTTP/2 Server-Sent Events von Haus aus vollständig ("out-of-the-box"):
|
|
||||||
|
|
||||||
```caddyfile
|
|
||||||
mindsift.example.com {
|
|
||||||
encode gzip zstd
|
|
||||||
|
|
||||||
# Event-Stream (SSE) ohne Pufferung weiterleiten
|
|
||||||
reverse_proxy 127.0.0.1:8080 {
|
|
||||||
# Streaming für SSE optimieren
|
|
||||||
flush_interval -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 4. Cloudflare Proxy (Orange Cloud)
|
|
||||||
|
|
||||||
Wird MindSift hinter dem Cloudflare CDN betrieben:
|
|
||||||
1. **WebSockets aktivieren:**
|
|
||||||
- Navigiere in das Cloudflare Dashboard: **Network** > **WebSockets** > Schalter auf **ON** stellen.
|
|
||||||
2. **Cloudflare Rocket Loader / Auto Minify:**
|
|
||||||
- Deaktiviere "Rocket Loader" für MindSift, da asynchrone Skripteingriffe den Start der Single-Page-App stören können.
|
|
||||||
3. **Cloudflare WAF / Bot Fight Mode:**
|
|
||||||
- Stelle sicher, dass `GET /api/v1/events` und `GET /api/v1/ws*` nicht von "Challenge"-Seiten blockiert werden.
|
|
||||||
4. **SSE-Unterstützung:**
|
|
||||||
- Cloudflare unterstützt Server-Sent Events nativ über HTTP/2 und HTTP/3. Dank der vom MindSift-Backend gesetzten Header `X-Accel-Buffering: no` und `Cache-Control: no-cache` streamt Cloudflare Echtzeit-Events verzögerungsfrei an die Clients.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 5. Apache 2.4 (`mod_proxy_wstunnel`)
|
|
||||||
|
|
||||||
Unter Debian/Ubuntu:
|
|
||||||
```bash
|
|
||||||
sudo a2enmod proxy proxy_http proxy_wstunnel headers
|
|
||||||
sudo systemctl restart apache2
|
|
||||||
```
|
|
||||||
|
|
||||||
VirtualHost-Konfiguration (`/etc/apache2/sites-available/mindsift.conf`):
|
|
||||||
|
|
||||||
```apache
|
|
||||||
<VirtualHost *:443>
|
|
||||||
ServerName mindsift.example.com
|
|
||||||
SSLEngine on
|
|
||||||
SSLCertificateFile /etc/letsencrypt/live/mindsift.example.com/fullchain.pem
|
|
||||||
SSLCertificateKeyFile /etc/letsencrypt/live/mindsift.example.com/privkey.pem
|
|
||||||
|
|
||||||
# 1. WebSocket Tunneling
|
|
||||||
RewriteEngine On
|
|
||||||
RewriteCond %{HTTP:Upgrade} =websocket [NC]
|
|
||||||
RewriteRule /(.*) ws://127.0.0.1:8080/$1 [P,L]
|
|
||||||
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
|
|
||||||
RewriteRule /(.*) http://127.0.0.1:8080/$1 [P,L]
|
|
||||||
|
|
||||||
# 2. SSE Response Flushing
|
|
||||||
<Location "/api/v1/events">
|
|
||||||
ProxyPass "http://127.0.0.1:8080/api/v1/events" flushpackets=on
|
|
||||||
ProxyPassReverse "http://127.0.0.1:8080/api/v1/events"
|
|
||||||
</Location>
|
|
||||||
|
|
||||||
ProxyPass / http://127.0.0.1:8080/
|
|
||||||
ProxyPassReverse / http://127.0.0.1:8080/
|
|
||||||
</VirtualHost>
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🔍 Diagnose & Verifikation
|
|
||||||
|
|
||||||
Mit den folgenden Befehlen lässt sich die Erreichbarkeit und Streaming-Funktion prüfen:
|
|
||||||
|
|
||||||
### 1. Server-Sent Events Test (Standard-HTTPS)
|
|
||||||
```bash
|
|
||||||
curl -N -H "Accept: text/event-stream" -H "Authorization: Bearer <DEIN_TOKEN>" https://mindsift.example.com/api/v1/events
|
|
||||||
```
|
|
||||||
*Erwartete Ausgabe:*
|
|
||||||
```text
|
|
||||||
: connected (transport: sse, id: sse_...)
|
|
||||||
data: {"event":"SSE_CONNECTED","payload":{"sseId":"sse_...","transport":"sse"},"timestamp":"..."}
|
|
||||||
: ping
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. WebSocket Handshake Test
|
|
||||||
```bash
|
|
||||||
curl -i -N \
|
|
||||||
-H "Connection: Upgrade" \
|
|
||||||
-H "Upgrade: websocket" \
|
|
||||||
-H "Host: mindsift.example.com" \
|
|
||||||
-H "Origin: https://mindsift.example.com" \
|
|
||||||
-H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
|
|
||||||
-H "Sec-WebSocket-Version: 13" \
|
|
||||||
https://mindsift.example.com/api/v1/ws?token=<DEIN_TOKEN>
|
|
||||||
```
|
|
||||||
*Erwartete Antwort:* `101 Switching Protocols`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🧭 Verwandte Dokumente
|
|
||||||
- 🔌 [WebSocket & Live-Protokoll](api/websocket.md)
|
|
||||||
- 🏗️ [Gesamtarchitektur](architecture.md)
|
|
||||||
- 🚨 [Bekannte Schwachstellen & Flaws](flaws.md)
|
|
||||||
@@ -1,55 +1,93 @@
|
|||||||
# Teilen & Berechtigungen
|
# 👥 Synchrones Teilen & Berechtigungskonzept
|
||||||
|
|
||||||
## Rollen
|
MindSift bietet ein mehrstufiges Kollaborations- und Freigabesystem. Es gewährleistet strikte Datensouveränität und Privatsphäre, ermöglicht aber gleichzeitig reibungslose Zusammenarbeit in Teams, Familien oder Unternehmen.
|
||||||
|
|
||||||
| Ebene | Werte | Bedeutung |
|
---
|
||||||
|---|---|---|
|
|
||||||
| Server | `admin`, `member` | Admins verwalten Benutzer, Einladungen und Einstellungen (`/admin/*`). |
|
|
||||||
| Gruppe | `admin`, `member` | Gruppen-Admins ändern/löschen die Gruppe und verwalten Mitglieder. Wer eine Gruppe anlegt, wird Admin. |
|
|
||||||
| Ressource | siehe unten | Eigentümer, Bearbeiter, Leser. |
|
|
||||||
|
|
||||||
## Berechtigungen je Ressource
|
## 🛡️ 1. Globale Rollen & System-Isolation
|
||||||
|
|
||||||
| Ressource | Eigentümer | Bearbeiter | Leser | Freigabe an |
|
### Globale Rollen
|
||||||
|---|---|---|---|---|
|
- **Server-Admin (`role = 'admin'`):** Vollzugriff auf System-Einstellungen, E-Mail-Konfiguration (SMTP), Benutzerverwaltung, Einladungscodes und System-Statistiken.
|
||||||
| **Aufgabenliste** (`task_list_shares.permission`) | alles, löschen, (un)teilen | Aufgaben anlegen/ändern/abhaken/verschieben/löschen, Liste umbenennen, Spalten ändern | nur ansehen | Benutzer, Gruppen |
|
- **Mitglied (`role = 'member'`):** Regulärer Benutzer; arbeitet in seinen eigenen Notizen, Aufgaben und freigegebenen Teams.
|
||||||
| **Geteilte Liste** (`list_shares.role`) | alles, löschen, (un)teilen | Einträge anlegen/ändern/abhaken/löschen | nur ansehen | Benutzer, Gruppen |
|
|
||||||
| **Notiz** (`doc_shares`, `doc_team_shares`) | schreiben | – | nur lesen | Benutzer, Gruppen |
|
|
||||||
| **Geteilter Ordner** (`workspace_folder_shares`) | schreiben | – | nur lesen | Benutzer, Gruppen |
|
|
||||||
|
|
||||||
- **Notizen und Ordner sind absichtlich schreibgeschützt für Empfänger.** Das erzwingt eine Migration beim Start (`permission = 'read'`); Schreibpfade im Code sind tot ([FLAW-17](flaws.md)).
|
### System-Isolations-Modi (`sharing_mode`)
|
||||||
- Bei Aufgabenlisten und Listen gilt: Hat jemand mehrere Zugriffswege (direkt und über Gruppen), zählt die **höchste** Stufe.
|
Der Server-Admin legt global fest, wie Benutzer miteinander interagieren dürfen:
|
||||||
- Für Gruppen gilt die Freigabe für alle aktuellen und künftigen Mitglieder.
|
|
||||||
- Aufgabenlisten besitzen zusätzlich das Altfeld `team_id`: Mitglieder dieser Gruppe haben ohne Freigabezeile Bearbeiterrechte. Eine Gruppenfreigabe über den Dialog setzt `team_id`, falls es noch leer ist.
|
|
||||||
|
|
||||||
## Aufgabenlisten teilen (Details)
|
```
|
||||||
|
┌────────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ System-Isolations-Modi │
|
||||||
|
├──────────────────────┬─────────────────────────┬───────────────────────┤
|
||||||
|
│ strict_private │ teams_only │ open │
|
||||||
|
│ (Strikt Isoliert) │ (Teams & Gruppen) │ (Offene Instanz) │
|
||||||
|
│ │ [EMPFOHLENER STANDARD]│ │
|
||||||
|
├──────────────────────┼─────────────────────────┼───────────────────────┤
|
||||||
|
│ Kein Adressbuch │ Adressbuch zeigt nur │ Alle Benutzer sehen │
|
||||||
|
│ Keine Freigaben │ gemeinsame Teammit- │ alle anderen Konten │
|
||||||
|
│ Autarke Einzel-Instanz│ glieder │ im System │
|
||||||
|
└──────────────────────┴─────────────────────────┴───────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
1. Eigentümer öffnet „Teilen“ an der Liste, wählt Gruppe oder Benutzer und die Stufe **Bearbeiten** oder **Nur Lesen**.
|
1. **`strict_private`:** Vollständige Abschottung. Benutzer wissen nicht voneinander. Keine Freigaben möglich.
|
||||||
2. `POST /task-lists/{id}/shares` speichert `permission`; erneutes Hinzufügen desselben Ziels ändert die Stufe.
|
2. **`teams_only` (Standard):** Kollaboration ist strikt an Gruppen gebunden. Ein Benutzer kann Objekte nur mit Personen teilen, die mindestens in einer gemeinsamen Gruppe/Team mit ihm sind.
|
||||||
3. `GET /task-lists` liefert je Liste `permission` (`owner`/`editor`/`viewer`). Das Frontend blendet für `viewer` alle Eingabemöglichkeiten aus und zeigt „Nur Lesen“.
|
3. **`open`:** Geeignet für Familien oder kleine Firmen. Jeder Benutzer kann für jeden anderen Benutzer Objekte freigeben.
|
||||||
4. Der Server prüft unabhängig davon jeden Schreibzugriff (`403`, `storage.ErrTaskListReadOnly`).
|
|
||||||
|
|
||||||
Bestehende Freigaben aus der Zeit vor dieser Stufe wurden mit `editor` migriert, behalten also ihr Verhalten.
|
---
|
||||||
|
|
||||||
## Isolations-Modi (`system_settings.sharing_mode`)
|
## 🏢 2. Gruppen & Teams (`teams` & `team_members`)
|
||||||
|
|
||||||
Werte: `strict_private`, `teams_only` (Standard), `open`. Gedacht ist:
|
Gruppen strukturieren Benutzer (z.B. „Familie", „Entwicklung", „Marketing"):
|
||||||
|
- **Gruppen-Admin:** Darf Mitglieder einladen, Rollen ändern oder die Gruppe löschen.
|
||||||
|
- **Gruppen-Mitglied:** Hat Zugriff auf alle mit der Gruppe geteilten Ressourcen (Ordner, Aufgabenlisten, Einkaufslisten, Notizen).
|
||||||
|
|
||||||
| Modus | Zweck |
|
Wird eine Ressource für eine Gruppe freigegeben, erhalten **alle aktuellen und zukünftigen Mitglieder** der Gruppe automatisch Zugriff, ohne dass Einzelberechtigungen gepflegt werden müssen.
|
||||||
|---|---|
|
|
||||||
| `strict_private` | Keine Sichtbarkeit zwischen Benutzern |
|
|
||||||
| `teams_only` | Freigaben nur zwischen Mitgliedern gemeinsamer Gruppen |
|
|
||||||
| `open` | Jeder kann für jeden freigeben |
|
|
||||||
|
|
||||||
**Tatsächlich** wird der Modus nur in `GetDiscoverableUsers` ausgewertet, und dort liefert `teams_only` bereits alle Benutzer. `GET /collaborators` ignoriert den Modus, und keine Freigabe-Funktion prüft ihn. Die Einstellung hat derzeit also kaum Wirkung ([FLAW-10](flaws.md)).
|
---
|
||||||
|
|
||||||
## Entkoppelte Ablage geteilter Notizen und Ordner
|
## 📁 3. Entkoppelte Ordner-Freigabe (Decoupled Folder Mounts)
|
||||||
|
|
||||||
- **Geteilte Ordner:** Der Ordner existiert einmal (`workspace_shared_folders`); jeder Empfänger hat seinen eigenen Einhängepfad (`workspace_folder_mounts.mount_path`). Verschiebt ein Empfänger den Ordner, ändert sich nur sein Pfad. Der Unterpfad innerhalb des Ordners (`documents.sub_folder_path`) gilt für alle.
|
### Das traditionelle Problem
|
||||||
- **Einzelne Notizen:** Jeder Empfänger kann eine geteilte Notiz in einen eigenen Ordner legen (`doc_user_folders`); die Notiz des Eigentümers bleibt unberührt.
|
In herkömmlichen Cloud-Systemen (wie Google Drive oder Nextcloud) führt das Verschieben eines geteilten Ordners oft dazu, dass er auch bei allen anderen Teilnehmern den Platz wechselt. Verschiebt ein Kollege den Ordner in sein Unterverzeichnis „Archiv", verschwindet er beim Ersteller aus dem Sichtfeld.
|
||||||
|
|
||||||
## Sitzungen und Zugriff
|
### Die MindSift-Lösung: Unabhängige Einhängepunkte (Mounts)
|
||||||
|
MindSift entkoppelt die physische Ordner-Identität von der persönlichen Ordner-Hierarchie des Benutzers:
|
||||||
|
|
||||||
- Tokens werden bei Passwortänderung, Rollenwechsel, Deaktivierung und „Alle Sitzungen beenden“ ungültig (`token_version`); ausgeloggte Tokens landen in `revoked_tokens`.
|
```
|
||||||
- Registrierung nur per Einladungscode oder, wenn vom Admin freigeschaltet, offen. Das erste Konto wird immer Administrator.
|
Eigentümer (Alice):
|
||||||
- Bekannte Lücken in der Zugriffskontrolle: [FLAW-01](flaws.md), [FLAW-02](flaws.md), [FLAW-03](flaws.md), [FLAW-06](flaws.md), [FLAW-07](flaws.md), [FLAW-08](flaws.md), [FLAW-24](flaws.md).
|
Ordner: "Kundenprojekte"
|
||||||
|
└── Geteilter Ordner: "Projekt Phoenix" (wsf_123)
|
||||||
|
├── spec.md
|
||||||
|
└── roadmap.md
|
||||||
|
|
||||||
|
Empfänger (Bob):
|
||||||
|
Ordner: "Meine Aufgaben"
|
||||||
|
└── "Wichtiges"
|
||||||
|
└── Einhängepunkt: "Projekt Phoenix" (wsf_123 eingehängt via mount_path)
|
||||||
|
├── spec.md
|
||||||
|
└── roadmap.md
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Wie es technisch funktioniert:
|
||||||
|
1. Der geteilte Ordner existiert als Entität in `workspace_shared_folders`.
|
||||||
|
2. Beim Eigentümer liegt der Ordner unter seinem Pfad.
|
||||||
|
3. Jeder Empfänger erhält in `workspace_folder_mounts` seinen **eigenen lokalen `mount_path`**.
|
||||||
|
4. **Unabhängiges Verschieben:** Schiebt Bob den Ordner an eine andere Stelle in seinem Dateibaum, wird **ausschließlich sein persönlicher `mount_path`** aktualisiert. Alice und andere Teammitglieder bemerken davon nichts.
|
||||||
|
5. **Inhaltliche Synchronisation:** Verschiebt, erstellt oder bearbeitet jemand eine Notiz *innerhalb* des geteilten Ordners, wird der relative Unterpfad (`sub_folder_path`) synchronisiert, sodass alle dieselbe interne Dokumentstruktur sehen.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📄 4. Entkoppelte Notizen-Freigabe (`doc_user_folders`)
|
||||||
|
|
||||||
|
Dasselbe Prinzip gilt für einzeln geteilte Dokumente:
|
||||||
|
- Erhält Benutzer Bob eine einzelne Notiz von Alice freigegeben, kann Bob diese Notiz in jeden beliebigen seiner eigenen Ordner einsortieren.
|
||||||
|
- Seine persönliche Zuordnung wird in der Tabelle `doc_user_folders` (`user_id`, `doc_id`, `folder_path`) gespeichert.
|
||||||
|
- Die Original-Notiz von Alice verbleibt an ihrem ursprünglichen Platz.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 5. Geteilte Aufgaben- & Einkaufslisten
|
||||||
|
|
||||||
|
- **Aufgabenlisten (`task_list_shares`):** Freigabe für Teams oder Einzelbenutzer mit Lese- oder Schreibrechten.
|
||||||
|
- **Geteilte Listen (`list_shares`):**
|
||||||
|
- Rolle `editor`: Einträge hinzufügen, ändern, abhaken und löschen.
|
||||||
|
- Rolle `viewer`: Nur Lesezugriff (Echtzeit-Ansicht).
|
||||||
|
- **Einheitlicher Freigabe-Dialog:** [`UnifiedShareModal.tsx`](../../frontend/src/components/UnifiedShareModal.tsx) bündelt alle Freigabeoptionen (Teams, Benutzer, Berechtigungsstufen) in einer konsistenten Benutzeroberfläche.
|
||||||
+8
-8
@@ -6,7 +6,7 @@ MindSift implementiert ein radikal einfaches, modulares Theming-System. Anstatt
|
|||||||
|
|
||||||
## 💡 1. Philosophie: 1 Datei = 1 komplettes Theme
|
## 💡 1. Philosophie: 1 Datei = 1 komplettes Theme
|
||||||
|
|
||||||
Jedes Theme liegt im Verzeichnis [`frontend/src/themes/`](../frontend/src/themes/) und definiert alle visuellen Eigenschaften über standardisierte CSS-Variablen.
|
Jedes Theme liegt im Verzeichnis [`frontend/src/themes/`](../../frontend/src/themes/) und definiert alle visuellen Eigenschaften über standardisierte CSS-Variablen.
|
||||||
|
|
||||||
### Trennung von Struktur und Design
|
### Trennung von Struktur und Design
|
||||||
- **React-Komponenten** definieren ausschließlich semantische Klassen (wie `.panel-surface`, `.input-field`, `.btn-primary`, `text-main`, `bg-canvas`).
|
- **React-Komponenten** definieren ausschließlich semantische Klassen (wie `.panel-surface`, `.input-field`, `.btn-primary`, `text-main`, `bg-canvas`).
|
||||||
@@ -78,17 +78,17 @@ Jede Theme-Datei gliedert sich in sechs exakt definierte Bereiche:
|
|||||||
|
|
||||||
| Theme-ID | Datei | Stil & Charakter | Standard-Geometrie |
|
| Theme-ID | Datei | Stil & Charakter | Standard-Geometrie |
|
||||||
| :--- | :--- | :--- | :--- |
|
| :--- | :--- | :--- | :--- |
|
||||||
| `dark` | [`theme-dark.css`](../frontend/src/themes/theme-dark.css) | Standard Dark Slate / Monochrom | Streng eckig (`0px` Cards, `2px` Buttons) |
|
| `dark` | [`theme-dark.css`](../../frontend/src/themes/theme-dark.css) | Standard Dark Slate / Monochrom | Streng eckig (`0px` Cards, `2px` Buttons) |
|
||||||
| `light` | [`theme-light.css`](../frontend/src/themes/theme-light.css) | Daylight Clean White / Minimalistisch | Modern dezent (`4px` Cards, `4px` Buttons) |
|
| `light` | [`theme-light.css`](../../frontend/src/themes/theme-light.css) | Daylight Clean White / Minimalistisch | Modern dezent (`4px` Cards, `4px` Buttons) |
|
||||||
| `high-contrast` | [`theme-high-contrast.css`](../frontend/src/themes/theme-high-contrast.css) | Reines Schwarz/Weiß mit AAA-Kontrast | Streng eckig (`0px`, kräftige Rahmen) |
|
| `high-contrast` | [`theme-high-contrast.css`](../../frontend/src/themes/theme-high-contrast.css) | Reines Schwarz/Weiß mit AAA-Kontrast | Streng eckig (`0px`, kräftige Rahmen) |
|
||||||
| `soft` | [`theme-soft.css`](../frontend/src/themes/theme-soft.css) | Warmes Soft Slate mit Indigo-Akzent | Weich gerundet (`12px` Cards, `8px` Buttons) |
|
| `soft` | [`theme-soft.css`](../../frontend/src/themes/theme-soft.css) | Warmes Soft Slate mit Indigo-Akzent | Weich gerundet (`12px` Cards, `8px` Buttons) |
|
||||||
| *Template* | [`theme-template.css`](../frontend/src/themes/theme-template.css) | Vollständig dokumentierte Kopiervorlage | Frei anpassbar |
|
| *Template* | [`theme-template.css`](../../frontend/src/themes/theme-template.css) | Vollständig dokumentierte Kopiervorlage | Frei anpassbar |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔌 4. Tailwind-Bridge & Semantische Klassen
|
## 🔌 4. Tailwind-Bridge & Semantische Klassen
|
||||||
|
|
||||||
In [`frontend/src/index.css`](../frontend/src/index.css) und `tailwind.config.js` sind die semantischen Utility-Klassen definiert, die sich automatisch an das gewählte Theme anpassen:
|
In [`frontend/src/index.css`](../../frontend/src/index.css) und `tailwind.config.js` sind die semantischen Utility-Klassen definiert, die sich automatisch an das gewählte Theme anpassen:
|
||||||
|
|
||||||
- `.panel-surface`: Wendet `--bg-panel`, `--border-color` und `--radius-card` an.
|
- `.panel-surface`: Wendet `--bg-panel`, `--border-color` und `--radius-card` an.
|
||||||
- `.input-field`: Wendet `--bg-input`, `--border-color`, `--radius-input` und `--text-main` an.
|
- `.input-field`: Wendet `--bg-input`, `--border-color`, `--radius-input` und `--text-main` an.
|
||||||
@@ -105,5 +105,5 @@ Um ein neues Theme (z.B. „Nordic Blue" oder „Cyberpunk") hinzuzufügen:
|
|||||||
1. Kopiere `frontend/src/themes/theme-template.css` nach `frontend/src/themes/theme-meintheme.css`.
|
1. Kopiere `frontend/src/themes/theme-template.css` nach `frontend/src/themes/theme-meintheme.css`.
|
||||||
2. Ändere den Selektor `:root[data-theme="template"]` in `:root[data-theme="meintheme"]`.
|
2. Ändere den Selektor `:root[data-theme="template"]` in `:root[data-theme="meintheme"]`.
|
||||||
3. Passe Farben und Rundungen nach Belieben an.
|
3. Passe Farben und Rundungen nach Belieben an.
|
||||||
4. Importiere die CSS-Datei in [`frontend/src/lib/theme.ts`](../frontend/src/lib/theme.ts) und trage das Theme im `AVAILABLE_THEMES`-Array ein.
|
4. Importiere die CSS-Datei in [`frontend/src/lib/theme.ts`](../../frontend/src/lib/theme.ts) und trage das Theme im `AVAILABLE_THEMES`-Array ein.
|
||||||
5. Das neue Theme steht sofort in den Kontoeinstellungen und im Profil-Dropdown zur Verfügung!
|
5. Das neue Theme steht sofort in den Kontoeinstellungen und im Profil-Dropdown zur Verfügung!
|
||||||
@@ -5,194 +5,235 @@
|
|||||||
|
|
||||||
[](#)
|
[](#)
|
||||||
[](#-schnellstart)
|
[](#-schnellstart)
|
||||||
[](#-deine-daten-gehören-dir)
|
[](#)
|
||||||
|
[](LICENSE)
|
||||||
|
|
||||||
**MindSift** ist eine selbst gehostete Schaltstelle für spontane Gedanken, Aufgaben mit Kanban-Board, hierarchische Outliner-Notizen und gemeinsame Listen. Alles läuft als ein einzelner Container mit eingebetteter SQLite-Datenbank, auf deinem eigenen Server.
|
**MindSift** ist deine zentrale, kompromisslos schnelle Schaltstelle für spontane Gedanken, strukturierte Aufgaben mit Kanban-Board, hierarchische Outliner-Notizen mit Zoom-Fokus und gemeinsame Echtzeit-Listen — ablenkungsfrei gestaltet, lokal als Standard-Markdown gespeichert und zu 100 % unter deiner eigenen Kontrolle.
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="screenshots/Triage_desktop.png" alt="MindSift Triage Desktop" width="85%" />
|
<img src="screenshots/Triage_desktop.png" alt="MindSift Triage Desktop" width="85%" style="border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.3);" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
[Philosophie](#-die-philosophie) • [Funktionen](#-funktionen) • [Schnellstart](#-schnellstart) • [Betrieb](#-betrieb--konfiguration) • [Entwicklung](#-entwicklung) • [Dokumentation](#-dokumentation)
|
[Philosophie](#-die-philosophie) • [Funktionen](#-was-mindsift-auszeichnet) • [Schnellstart](#-schnellstart) • [Für wen?](#-für-wen-ist-mindsift-gemacht)
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 💡 Die Philosophie
|
## 💡 Die Philosophie: *Erst raus aus dem Kopf – später sortieren*
|
||||||
|
|
||||||
Die meisten Notiz- und Aufgaben-Apps verlangen Struktur im falschen Moment: Wenn dir ein Gedanke kommt, willst du keinen Ordner suchen und keine Felder ausfüllen. MindSift trennt deshalb **Erfassen** und **Organisieren**:
|
Klassische Produktivitäts- und Notiz-Apps scheitern im Alltag oft an derselben Hürde: **Sie verlangen Struktur im falschen Moment.**
|
||||||
|
Wenn dir mitten im Gespräch, unterwegs auf dem Smartphone oder kurz vor Feierabend ein wichtiger Gedanke kommt, willst du keinen Ordner suchen, keine Datenbankfelder ausfüllen und keine starren Formulare bedienen. Du willst den Gedanken in drei Sekunden festhalten – und sicher sein, dass er verlässlich da ist, wenn du Zeit hast.
|
||||||
|
|
||||||
1. **Abladen:** In die Eingabeleiste tippen, `Enter`, fertig. Wer will, weist den Gedanken gleich einer Aufgabe, Liste oder Notiz zu.
|
**MindSift trennt das Erfassen radikal vom Organisieren:**
|
||||||
2. **Sichten (Triage):** Später gehst du den Stapel Karte für Karte durch: verwerfen, zur Aufgabe machen, in eine Notiz oder Liste verwandeln.
|
|
||||||
3. **Vertiefen:** Aus losen Ideen werden Aufgaben mit Unteraufgaben, vernetzte Outliner-Notizen oder geteilte Listen für Familie und Team.
|
1. **Sofort abladen (Quick Dump):** In die globale Eingabeleiste tippen, `Enter` drücken, Kopf wieder frei. Du kannst Gedanken aber auch direkt beim Eintippen gezielt einer Aufgabenliste, Einkaufsliste oder Notiz zuweisen.
|
||||||
|
2. **Spielerisch sichten (Triage):** In ruhigen Momenten sichtest du deinen Stapel Karte für Karte – am Desktop per Tastaturkürzel oder auf dem Smartphone per Wischgeste. Mit einer Taste nach links verwerfen, auf „Später“ vertagen oder direkt in eine Aufgabe, Notiz oder Liste umwandeln.
|
||||||
|
3. **Strukturiert vertiefen:** Aus losen Ideen werden vernetzte Outliner-Dokumente, hierarchische Unteraufgaben im Kanban-Board oder geteilte Listen für Familie, WG und Team.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## ✨ Funktionen
|
## ✨ Was MindSift auszeichnet
|
||||||
|
|
||||||
### ⚡ Schnellerfassung & Triage
|
### ⚡ Quick-Dump & Triage-Deck (Das 3-Sekunden-Prinzip)
|
||||||
|
|
||||||
* Eingabeleiste im Kopf der App, jederzeit mit `C` oder `/` fokussierbar; auch per Spracheingabe (Browser-Funktion).
|
* **Blitz-Erfassung:** Die Schnelleingabeleiste sitzt prominent im Header – jederzeit blitzschnell per Mausklick oder Tastendruck (`C` oder `/`) fokussierbar.
|
||||||
* Ziel beim Erfassen wählbar: Posteingang, Aufgabe, Listeneintrag oder Notiz.
|
* **Tastatur-Triage am Desktop:**
|
||||||
* **Triage-Deck:** `H`/`←` verwerfen, `L`/`→` zur Aufgabe, `T` Aufgabe mit Termin, `D` in Notiz verwandeln, Leertaste = später. Auf dem Smartphone per Wischgeste.
|
* `H` oder `←`: Wegwerfen / Erledigt
|
||||||
* Papierkorb mit Wiederherstellen.
|
* `L` oder `→`: Sofort zur Aufgabe machen
|
||||||
|
* `T`: Termin-Aufgabe mit Fälligkeitsdatum
|
||||||
|
* `D`: In Workspace-Notiz umwandeln
|
||||||
|
* `Leertaste`: Später (ans Ende des Stapels schieben)
|
||||||
|
* **Mobile-First & Touch-optimiert:** Unterwegs kannst du Gedanken per Wischgeste (Swipe nach links zum Verwerfen, Swipe nach rechts zum Behalten) sortieren.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="screenshots/Mobile_Triage.png" alt="MindSift Mobile Triage" width="280px" />
|
<img src="screenshots/Mobile_Triage.png" alt="MindSift Mobile Triage" width="280px" style="border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,0.25);" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
### ✅ Aufgaben & Kanban
|
---
|
||||||
|
|
||||||
* Listen- und Kanban-Ansicht, Spalten pro Aufgabenliste frei konfigurierbar.
|
### 📝 Workspace: Der hierarchische Outliner mit Zoom-Fokus
|
||||||
* Prioritäten, Fälligkeitsdatum, Hashtags, Unteraufgaben mit Fortschrittsbalken, Markdown-Notizen.
|
|
||||||
* Filter, Gruppierung und Sortierung; Drag & Drop in Liste und Board.
|
Der MindSift-Workspace vereint die Übersicht eines klassischen Dokumenten-Explorers mit der Leichtigkeit eines hierarchischen Outliners (inspiriert von Logseq und Roam).
|
||||||
* **Aufgabenlisten teilen** mit Benutzern oder Gruppen, wahlweise als **Bearbeiter** oder **nur lesend**.
|
|
||||||
* **Alarme** bei Fälligkeit per E-Mail, Discord oder eigenem Webhook.
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="screenshots/aufgaben_desktop.png" alt="MindSift Aufgaben und Kanban-Board" width="90%" />
|
<img src="screenshots/workspace_desktop.png" alt="MindSift Workspace Outliner" width="90%" style="border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.3);" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
### 📝 Workspace: Outliner-Notizen
|
* **Jeder Gedanke ein Bullet-Point:**
|
||||||
|
* `Enter`: Neuer Bullet-Point auf derselben Ebene
|
||||||
|
* `Tab` / `Shift + Tab`: Unterordnen (einrücken) und ausrücken
|
||||||
|
* `Shift + Enter`: Weicher Zeilenumbruch innerhalb desselben Blocks
|
||||||
|
* **🔍 Fokus-Modus & Zoom-in (Hoisting):**
|
||||||
|
* Klicke auf einen Bullet-Punkt (`•`), um **isoliert in diesen Ast hineinzuzoomen**.
|
||||||
|
* Der gewählte Punkt wird zur prominenten Überschrift, sodass du dich ohne jede Ablenkung auf genau dieses Thema konzentrieren kannst.
|
||||||
|
* Eine klickbare Breadcrumb-Leiste oben zeigt deinen aktuellen Pfad und führt dich mit einem Klick zurück in übergeordnete Ebenen oder ins Hauptdokument.
|
||||||
|
* **Intuitives Drag & Drop für Bullet-Points:**
|
||||||
|
* Verschiebe Absätze und ganze Gedankenbäume mühelos mit der Maus.
|
||||||
|
* **Unterpunkte per Drop erstellen:** Ziehst du einen Bullet-Point direkt auf einen anderen Aufzählungspunkt, wird er automatisch als Unter-Bullet eingerückt. Eingeklappte Eltern-Punkte klappen beim Hineinlegen automatisch auf.
|
||||||
|
* Untergeordnete Unterpunkte werden beim Ziehen automatisch als zusammenhängender Ast mitbewegt.
|
||||||
|
* **Echtzeit-Schreib-Lock (Kollisionsschutz):**
|
||||||
|
* Sobald du einen Bullet-Point per Drag & Drop greifst oder anfängst zu tippen, wird sofort ein Schreib-Lock für das Dokument aktiviert.
|
||||||
|
* Andere Nutzer sehen live, wer das Dokument gerade bearbeitet, und Kollisionen bei gleichzeitigen Änderungen werden zuverlässig verhindert.
|
||||||
|
* **Slash-Befehle (`/`):** Tippe einfach `/` für `/todo`, `/h1`, `/h2`, `/h3`, `/code`, `/callout` oder `/divider`.
|
||||||
|
* **Vernetzung & Hashtags:** Verlinke Notizen untereinander mit Wiki-Links (`[[Notiztitel]]`) und tagge Gedanken mit `#Hashtags`.
|
||||||
|
* **Explorer mit Ordnern & Favoriten:** Organisiere Dokumente hierarchisch in Ordnern, verschiebe Notizen per Drag & Drop und hefte deine wichtigsten Dokumente als Favoriten ganz oben an.
|
||||||
|
* **100 % Standard-Markdown:** Jedes Dokument wird lokal unter `./data/workspace/...` als saubere `.md`-Datei mit 2-Leerzeichen-Einrückung abgelegt – jederzeit lesbar und kompatibel mit Obsidian, Logseq oder VS Code.
|
||||||
|
|
||||||
* Jeder Gedanke ein Bullet: `Enter`, `Tab`/`Shift+Tab`, Ein-/Ausklappen, Drag & Drop ganzer Äste.
|
---
|
||||||
* **Zoom-Fokus** per Klick auf den Bullet, Breadcrumbs zum Zurücknavigieren.
|
|
||||||
* Blocktypen und Slash-Befehle: `/todo`, `/link`, `/h1`–`/h3`, `/code` (mit Syntax-Hervorhebung), `/callout`, `/divider`.
|
### ✅ Aufgabenlisten & Kanban-Board
|
||||||
* Wiki-Links `[[Notiz]]`, Links und `#Hashtags`; Tag-Seiten bündeln alle Fundstellen.
|
|
||||||
* Ordner, Favoriten, **To-Do-Rollup** über alle Notizen und Export einer Notiz als `.md`.
|
Behalte offene Aufgaben, Projekte und Termine im Blick – wahlweise als strukturierte Liste oder als visuelles Kanban-Board.
|
||||||
* Einfügen von mehrzeiligem Markdown wird in Blöcke zerlegt.
|
|
||||||
* **Teilen:** Notizen und ganze Ordner lassen sich Benutzern oder Gruppen **zum Lesen** freigeben. Empfänger sortieren sie in ihren eigenen Baum ein.
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="screenshots/workspace_desktop.png" alt="MindSift Workspace Outliner" width="90%" />
|
<img src="screenshots/aufgaben_desktop.png" alt="MindSift Aufgaben und Kanban-Board" width="90%" style="border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.3);" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
### 🛒 Geteilte Listen
|
* **Flexible Ansichten (Liste & Kanban):** Wechsle mit einem Klick zwischen kompakter Listenansicht und dem interaktiven Kanban-Board (*Zu erledigen*, *In Arbeit*, *Wartend*, *Erledigt*).
|
||||||
|
* **Unteraufgaben (Subtasks):**
|
||||||
|
* Gliedere komplexe Aufgaben in beliebig viele Teilaufgaben.
|
||||||
|
* Ein visueller Fortschrittsbalken und eine Prozentanzeige zeigen dir auf einen Blick, wie weit die Aufgabe gediehen ist.
|
||||||
|
* **Freies Drag & Drop:**
|
||||||
|
* Sortiere Aufgaben vertikal in deiner bevorzugten Reihenfolge.
|
||||||
|
* Im Kanban-Board verschiebst du Karten per Drag & Drop direkt zwischen Status-Spalten oder ordnest sie innerhalb einer Spalte um.
|
||||||
|
* Kein mühsames Suchen nach Greifern: Klicke und ziehe eine Aufgabe einfach direkt mit der Maus – ein kurzer Klick ohne Ziehen öffnet das Detail-Modal zum Bearbeiten.
|
||||||
|
* **Prioritäten & Termine:** Hebe dringende oder wichtige Aufgaben mit Farbcodes und Icons hervor (🔥 Dringend, ⚠️ Wichtig). Setze Fälligkeitsdaten und filtere nach Hashtags.
|
||||||
|
* **Geteilte Aufgabenlisten:** Erstelle separate Listen für Beruf, Homelab oder Familie und teile sie gezielt mit Gruppen, Teams oder einzelnen Nutzern.
|
||||||
|
|
||||||
* Einkaufs-, Pack- und Checklisten mit Kategorien per Hashtag (`Hafermilch #Kühlregal`), Mengenangaben und Drag & Drop zwischen Kategorien.
|
---
|
||||||
* Freigabe an Benutzer und Gruppen (Bearbeiter oder Leser); abgehakte Einträge erscheinen bei allen in Echtzeit.
|
|
||||||
|
### 🛒 Geteilte Listen (Einkauf & Checklisten)
|
||||||
|
|
||||||
|
Ob Wochenmarkt, Baumarkt oder Urlaubs-Packliste – erstelle geteilte Listen, die für gemeinsames Arbeiten in Echtzeit optimiert sind.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="screenshots/Listen_desktop.png" alt="MindSift Geteilte Listen" width="90%" />
|
<img src="screenshots/Listen_desktop.png" alt="MindSift Geteilte Listen" width="90%" style="border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.3);" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
### 🏢 Benutzer, Gruppen, Administration
|
* **Automatische Hashtag-Kategorien:**
|
||||||
|
* Tagge Artikel einfach mit einem Hashtag (z. B. `Hafermilch #Kühlregal` oder `Bananen #Obst`).
|
||||||
|
* MindSift sortiert die Kategorien automatisch alphabetisch und zeigt sie in übersichtlichen Sektionen mit Kacheln an.
|
||||||
|
* **Hashtag-Autovervollständigung:** Bereits beim Tippen eines `#` schlägt dir die Eingabe existierende Hashtags vor (case-insensitive) – mit Tastaturnavigation und Sofort-Übernahme per `Enter`.
|
||||||
|
* **Mengenangaben & Schnell-Eingabe:** Erfasse Mengen (`2x`, `500g`) direkt im Eingabefeld.
|
||||||
|
* **Drag & Drop zwischen Kategorien:** Ziehe Einträge mit der Maus nach oben oder unten oder schiebe sie direkt in einen anderen Hashtag-Bereich – der Hashtag im Text wird automatisch aktualisiert.
|
||||||
|
* **Gemeinsam teilen mit Gruppen & Teams:**
|
||||||
|
* Über das einheitliche Teilen-Modal kannst du jede Liste mit deinen Teams, Arbeitsgruppen oder Einzelpersonen freigeben.
|
||||||
|
* Avatare und Freigabe-Badges im Header zeigen dir transparent, wer Zugriff hat.
|
||||||
|
* **Echtzeit-WebSocket-Synchronisation:** Wird ein Artikel im Supermarkt abgehakt, hakt er sich bei allen Beteiligten im selben Augenblick live ab.
|
||||||
|
* **Eckiges Abhaken & Aufräumen:** Erledigte Punkte wandern in einen separaten Bereich und können mit einem Klick aufgeräumt werden.
|
||||||
|
|
||||||
* Geführte Ersteinrichtung, Rollen *Admin* und *Mitglied*, Einladungscodes, optional offene Registrierung.
|
---
|
||||||
* Gruppen mit Gruppen-Admins für Freigaben.
|
|
||||||
* Admin-Bereich: Benutzer, Einladungen, Instanzname, SMTP, Freigabe-Modus.
|
|
||||||
* Vier Themes (Dark, Light, High-Contrast, Soft), installierbar als PWA.
|
|
||||||
|
|
||||||
### 🔌 Integrationen
|
### 📋 Globale To-Dos: Das automatische Notizen-Rollup
|
||||||
|
|
||||||
* **Webhook / API-Key:** `POST /api/v1/webhooks/ingest` legt Aufgaben aus Smarthome, Skripten oder Automationen an.
|
* **Automatische Erfassung:** MindSift durchsucht alle Workspace-Notizen und sammelt sämtliche Checkboxen (`- [ ]`) in einem zentralen Rollup-Dashboard.
|
||||||
* Persönliche API-Keys, Datenexport als JSON.
|
* **Ordner-Filter:** Isoliere Aufgaben bestimmter Projekte mit einem Klick.
|
||||||
|
* **2-Wege-Echtzeit-Sync:** Hakst du ein To-Do im Rollup ab, wird die physische Markdown-Datei auf der Festplatte augenblicklich als `- [x]` aktualisiert.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 🏢 Benutzer, Gruppen & Administration
|
||||||
|
|
||||||
|
* **Geführte Ersteinrichtung:** Beim ersten Start führt dich ein Assistent durch die Einrichtung deines Administrator-Kontos.
|
||||||
|
* **Eigenständiger Gruppen-Bereich:** Verwalte eigene Gruppen und Teams direkt über das Benutzer-Menü oben rechts.
|
||||||
|
* **Gruppen-Administration:** Wer eine Gruppe anlegt oder zum Gruppen-Admin ernannt wird, hat die volle Kontrolle über die Mitglieder dieser Gruppe.
|
||||||
|
* **Server-Sicherheit:** Schalte die öffentliche Registrierung ab und lade neue Mitglieder kontrolliert per Einladungscode ein.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🚀 Schnellstart
|
## 🚀 Schnellstart
|
||||||
|
|
||||||
MindSift läuft als einzelner Container mit Webserver, API, Datenbank und Frontend.
|
MindSift läuft als leichtgewichtiger, einzelner Container und bringt Webserver, API, SQLite-Datenbank und Frontend direkt mit.
|
||||||
|
|
||||||
### Option 1: Installationsskript
|
### Option 1: Der 1-Zeiler (Empfohlen)
|
||||||
|
|
||||||
|
Führe diesen Befehl im Terminal deines Servers aus. Er erstellt das Verzeichnis, lädt die Konfiguration, generiert ein sicheres JWT-Geheimnis und startet den Container:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://git.dsit.me/sandrodach/MindSift/raw/branch/dev/install.sh | bash
|
curl -fsSL https://git.dsit.me/sandrodach/MindSift/raw/branch/dev/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
Das Skript legt ein Verzeichnis an, lädt `docker-compose.yml` und `.env.example`, erzeugt ein `JWT_SECRET` und startet den Container.
|
---
|
||||||
|
|
||||||
### Option 2: Docker Compose
|
### Option 2: Schneller Start mit zwei `curl`-Befehlen
|
||||||
|
|
||||||
|
Falls du die Dateien direkt ohne Skript herunterladen möchtest:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
mkdir -p mindsift && cd mindsift
|
mkdir -p mindsift && cd mindsift
|
||||||
curl -fsSL https://git.dsit.me/sandrodach/MindSift/raw/branch/dev/docker-compose.yml -o docker-compose.yml
|
curl -fsSL https://git.dsit.me/sandrodach/MindSift/raw/branch/dev/docker-compose.yml -o docker-compose.yml
|
||||||
curl -fsSL https://git.dsit.me/sandrodach/MindSift/raw/branch/dev/.env.example -o .env
|
curl -fsSL https://git.dsit.me/sandrodach/MindSift/raw/branch/dev/.env.example -o .env
|
||||||
# In .env: JWT_SECRET durch einen langen Zufallswert ersetzen!
|
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
Minimal:
|
---
|
||||||
|
|
||||||
|
### Option 3: Manuelle `docker-compose.yml`
|
||||||
|
|
||||||
|
Erstelle eine Datei namens `docker-compose.yml`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
mindsift:
|
mindsift:
|
||||||
image: git.dsit.me/sandrodach/mindsift:dev
|
image: git.dsit.me/sandrodach/mindsift:dev
|
||||||
|
container_name: mindsift
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports: ["8080:8080"]
|
ports:
|
||||||
volumes: ["./data:/data"]
|
- "8080:8080"
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
environment:
|
environment:
|
||||||
- JWT_SECRET=hier-ein-langer-zufaelliger-wert
|
- PORT=8080
|
||||||
- BASE_URL=https://mindsift.example.com
|
- DATA_DIR=/data
|
||||||
|
- JWT_SECRET=hier-ein-langes-sicheres-zufalls-geheimnis-eintragen
|
||||||
|
- ALLOW_REGISTRATION=false
|
||||||
|
# Optional: Mailserver für E-Mail-Alarme (auch im Admin-UI einstellbar)
|
||||||
|
- SMTP_HOST=
|
||||||
|
- SMTP_PORT=587
|
||||||
|
- SMTP_USER=
|
||||||
|
- SMTP_PASS=
|
||||||
|
- SMTP_FROM=
|
||||||
|
- SMTP_TLS=true
|
||||||
```
|
```
|
||||||
|
|
||||||
### Ersteinrichtung
|
Starte den Container:
|
||||||
|
|
||||||
Rufe `http://localhost:8080` auf. Beim ersten Start führt ein Assistent durch das Anlegen des Administrator-Kontos.
|
|
||||||
|
|
||||||
> ⚠️ **Setze `JWT_SECRET`.** Ohne Angabe nutzt der Server einen öffentlich bekannten Standardwert, mit dem sich Anmelde-Tokens fälschen lassen. Rufe die Instanz außerdem direkt nach dem Start auf, damit kein Fremder das erste Konto anlegt.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## ⚙️ Betrieb & Konfiguration
|
|
||||||
|
|
||||||
| Variable | Standard | Zweck |
|
|
||||||
|---|---|---|
|
|
||||||
| `PORT` | `8080` | HTTP-Port |
|
|
||||||
| `DATA_DIR` | `/data` (Container) | Ablage der Datenbank `mindsift.db` |
|
|
||||||
| `JWT_SECRET` | unsicherer Standard | **Pflicht in Produktion**, Signaturschlüssel |
|
|
||||||
| `BASE_URL` | `http://localhost:8080` | Öffentliche URL |
|
|
||||||
| `ALLOW_REGISTRATION` | `false` | Offene Registrierung (im Admin-UI änderbar) |
|
|
||||||
| `LOG_LEVEL` / `DEBUG` | `info` / `false` | Logging |
|
|
||||||
| `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASS`, `SMTP_FROM`, `SMTP_TLS` | leer | E-Mail-Alarme (auch im Admin-UI) |
|
|
||||||
| `MINDA_DEMO` | `false` | Legt Demo-Konten `admin/admin`, `user/user` an. **Nie auf öffentlichen Servern!** |
|
|
||||||
|
|
||||||
* **Reverse-Proxy:** WebSocket-Upgrade und ungepufferte SSE-Streams müssen durchgereicht werden. Beispiele für Nginx, Traefik, Caddy und Cloudflare: [Doku/reverse-proxy.md](Doku/reverse-proxy.md).
|
|
||||||
* **Datensicherung:** Alle Daten liegen in `data/mindsift.db` (+ `-wal`/`-shm`). Sichere sie mit `sqlite3 mindsift.db ".backup 'backup.db'"` oder bei gestopptem Container. Zusätzlich gibt es einen JSON-Export pro Benutzer.
|
|
||||||
* **Updates:** Neues Image ziehen und Container neu starten (`docker compose pull && docker compose up -d`). Das Schema wird beim Start automatisch angepasst.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🛠 Entwicklung
|
|
||||||
|
|
||||||
Voraussetzungen: Go 1.23, Node 22.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Backend: Vet und Tests
|
docker compose up -d
|
||||||
go vet ./... && go test ./...
|
|
||||||
|
|
||||||
# Frontend
|
|
||||||
cd frontend
|
|
||||||
npm ci
|
|
||||||
npm run dev # Vite-Entwicklungsserver
|
|
||||||
npx tsc --noEmit # Typprüfung
|
|
||||||
npm run build # Produktions-Build
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Für das Binary wird das gebaute Frontend nach `cmd/server/dist` kopiert (`go:embed`); das mehrstufige `Dockerfile` erledigt das und führt Vet und Tests beim Image-Build aus.
|
|
||||||
|
|
||||||
**Stack:** Go (chi, gorilla/websocket, JWT, modernc SQLite) · React 18, TypeScript, Vite, Tailwind.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📚 Dokumentation
|
### 🌐 Ersteinrichtung aufrufen
|
||||||
|
|
||||||
Die technische Doku liegt unter [Doku/](Doku/README.md): Architektur, Datenbank, REST- und Echtzeit-API, Module, Freigaben und Berechtigungen, Themes. Bekannte Schwachstellen und offene Punkte stehen in [Doku/flaws.md](Doku/flaws.md).
|
Öffne deinen Browser unter **`http://localhost:8080`** (bzw. die IP deines Servers).
|
||||||
|
MindSift erkennt den Erststart automatisch und führt dich durch den Einrichtungs-Assistenten zum Erstellen des Administrator-Kontos.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 👥 Für wen ist MindSift gemacht?
|
||||||
|
|
||||||
|
* **Für Macher & Wissensarbeiter**, die tagsüber dutzende Gedanken, Links und Aufgaben festhalten müssen, ohne aus dem Arbeitsfluss gerissen zu werden.
|
||||||
|
* **Für Outliner-Fans**, die die Flexibilität von Logseq schätzen, aber ihre Notizen in einer klaren Ordnerstruktur auf dem eigenen Server haben wollen.
|
||||||
|
* **Für Familien & WGs**, die gemeinsame Einkaufs- und Packlisten ohne Werbe-Apps und fremde Clouds synchronisieren möchten.
|
||||||
|
* **Für Homelab- & Self-Hosting-Begeisterte**, die volle Datenhoheit, saubere Markdown-Dateien und automatisierte Webhooks auf eigener Hardware schätzen.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔒 Deine Daten gehören dir
|
## 🔒 Deine Daten gehören dir
|
||||||
|
|
||||||
* Selbst gehostet, keine Telemetrie, keine Fremddienste. Ausgehende Verbindungen gibt es nur zu den Alarm-Zielen, die du selbst einrichtest (SMTP, Discord, Webhook).
|
* **100 % Self-Hosted:** Keine fremden Cloud-Dienste, keine Telemetrie, kein Tracking.
|
||||||
* Alle Inhalte liegen in einer einzigen SQLite-Datei; Notizen lassen sich als Markdown exportieren, alle Daten eines Benutzers als JSON.
|
* **Kein Vendor-Lock-in:** Alle Notizen liegen als lesbare `.md`-Dateien im Ordner `./data/workspace`. Backups können jederzeit exportiert werden.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📄 Lizenz
|
## 📄 Lizenz
|
||||||
|
|
||||||
Im Repository liegt derzeit keine `LICENSE`-Datei; die Lizenz ist damit nicht festgelegt.
|
Veröffentlicht unter der **MIT-Lizenz** – siehe [LICENSE](LICENSE).
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<sub>Gebaut für Klarheit, Geschwindigkeit und digitale Souveränität.</sub>
|
<sub>Gebaut für maximale Klarheit, Geschwindigkeit und digitale Souveränität.</sub>
|
||||||
</div>
|
</div>
|
||||||
+12
-31
@@ -4,8 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"embed"
|
"embed"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log/slog"
|
"log"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -24,16 +23,11 @@ var embeddedDist embed.FS
|
|||||||
func main() {
|
func main() {
|
||||||
cfg := config.Load()
|
cfg := config.Load()
|
||||||
|
|
||||||
level := cfg.SlogLevel()
|
log.Printf("🧠 Starting MindSift Server on port %s (DB: %s)", cfg.Port, cfg.DatabasePath)
|
||||||
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
|
||||||
slog.SetDefault(logger)
|
|
||||||
|
|
||||||
slog.Info("MindSift Server starting", "port", cfg.Port, "log_level", level.String())
|
|
||||||
|
|
||||||
store, err := storage.NewStore(cfg.DatabasePath)
|
store, err := storage.NewStore(cfg.DatabasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to initialize storage", "error", err)
|
log.Fatalf("Failed to initialize storage: %v", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
defer store.Close()
|
defer store.Close()
|
||||||
|
|
||||||
@@ -41,11 +35,11 @@ func main() {
|
|||||||
store.SeedSMTPDefaultsFromEnv(cfg.SMTPHost, cfg.SMTPPort, cfg.SMTPUser, cfg.SMTPPass, cfg.SMTPFrom, cfg.SMTPTLS)
|
store.SeedSMTPDefaultsFromEnv(cfg.SMTPHost, cfg.SMTPPort, cfg.SMTPUser, cfg.SMTPPass, cfg.SMTPFrom, cfg.SMTPTLS)
|
||||||
|
|
||||||
if cfg.DemoMode {
|
if cfg.DemoMode {
|
||||||
slog.Info("🧪 Demo-Modus aktiv (MINDA_DEMO=true): Richte Demo-Benutzer admin/admin und user/user ein...")
|
log.Printf("🧪 Demo-Modus aktiv (MINDA_DEMO=true): Richte Demo-Benutzer admin/admin und user/user ein...")
|
||||||
if err := store.EnsureDemoAccounts(); err != nil {
|
if err := store.EnsureDemoAccounts(); err != nil {
|
||||||
slog.Warn("⚠️ Fehler beim Anlegen der Demo-Accounts", "error", err)
|
log.Printf("⚠️ Fehler beim Anlegen der Demo-Accounts: %v", err)
|
||||||
} else {
|
} else {
|
||||||
slog.Info("✅ Demo-Accounts bereit: admin / admin (Admin-Rolle) und user / user (Standard-Rolle)")
|
log.Printf("✅ Demo-Accounts bereit: admin / admin (Admin-Rolle) und user / user (Standard-Rolle)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,31 +47,23 @@ func main() {
|
|||||||
|
|
||||||
staticFS, err := fs.Sub(embeddedDist, "dist")
|
staticFS, err := fs.Sub(embeddedDist, "dist")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to mount embedded dist filesystem", "error", err)
|
log.Fatalf("Failed to mount embedded dist filesystem: %v", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srv := api.NewServer(cfg, store, wsHub, staticFS)
|
srv := api.NewServer(cfg, store, wsHub, staticFS)
|
||||||
|
|
||||||
serverCtx, serverCancel := context.WithCancel(context.Background())
|
|
||||||
defer serverCancel()
|
|
||||||
|
|
||||||
httpServer := &http.Server{
|
httpServer := &http.Server{
|
||||||
Addr: ":" + cfg.Port,
|
Addr: ":" + cfg.Port,
|
||||||
Handler: srv.Router(),
|
Handler: srv.Router(),
|
||||||
BaseContext: func(l net.Listener) context.Context {
|
|
||||||
return serverCtx
|
|
||||||
},
|
|
||||||
ReadTimeout: 15 * time.Second,
|
ReadTimeout: 15 * time.Second,
|
||||||
WriteTimeout: 30 * time.Second,
|
WriteTimeout: 30 * time.Second,
|
||||||
IdleTimeout: 60 * time.Second,
|
IdleTimeout: 60 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
slog.Info("✨ MindSift ready", "url", "http://0.0.0.0:"+cfg.Port)
|
log.Printf("✨ MindSift ready at http://0.0.0.0:%s", cfg.Port)
|
||||||
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
slog.Error("HTTP server error", "error", err)
|
log.Fatalf("HTTP server error: %v", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -85,13 +71,8 @@ func main() {
|
|||||||
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
|
||||||
<-stop
|
<-stop
|
||||||
|
|
||||||
slog.Info("Shutting down MindSift server gracefully...")
|
log.Println("Shutting down MindSift server gracefully...")
|
||||||
serverCancel()
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
wsHub.Close()
|
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if err := httpServer.Shutdown(ctx); err != nil {
|
_ = httpServer.Shutdown(ctx)
|
||||||
slog.Warn("HTTP server shutdown finished with error", "error", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -14,9 +14,6 @@ services:
|
|||||||
- BASE_URL=${BASE_URL:-http://localhost:8080}
|
- BASE_URL=${BASE_URL:-http://localhost:8080}
|
||||||
- ALLOW_REGISTRATION=${ALLOW_REGISTRATION:-false}
|
- ALLOW_REGISTRATION=${ALLOW_REGISTRATION:-false}
|
||||||
- LOG_LEVEL=${LOG_LEVEL:-info}
|
- LOG_LEVEL=${LOG_LEVEL:-info}
|
||||||
# Set LOG_LEVEL=debug or DEBUG=true for detailed request and sync logging
|
|
||||||
# - LOG_LEVEL=debug
|
|
||||||
# - DEBUG=true
|
|
||||||
# Demo mode: if true, automatically seeds demo accounts admin/admin and user/user
|
# Demo mode: if true, automatically seeds demo accounts admin/admin and user/user
|
||||||
- MINDA_DEMO=${MINDA_DEMO:-false}
|
- MINDA_DEMO=${MINDA_DEMO:-false}
|
||||||
# Optional SMTP / Mail Configuration (can also be configured in Admin UI)
|
# Optional SMTP / Mail Configuration (can also be configured in Admin UI)
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ services:
|
|||||||
- BASE_URL=${BASE_URL:-http://localhost:8080}
|
- BASE_URL=${BASE_URL:-http://localhost:8080}
|
||||||
- ALLOW_REGISTRATION=${ALLOW_REGISTRATION:-false}
|
- ALLOW_REGISTRATION=${ALLOW_REGISTRATION:-false}
|
||||||
- LOG_LEVEL=${LOG_LEVEL:-info}
|
- LOG_LEVEL=${LOG_LEVEL:-info}
|
||||||
# Set LOG_LEVEL=debug or DEBUG=true for detailed request and sync logging
|
|
||||||
# - LOG_LEVEL=debug
|
|
||||||
# - DEBUG=true
|
|
||||||
# Demo mode: if true, automatically seeds demo accounts admin/admin and user/user
|
# Demo mode: if true, automatically seeds demo accounts admin/admin and user/user
|
||||||
- MINDA_DEMO=${MINDA_DEMO:-false}
|
- MINDA_DEMO=${MINDA_DEMO:-false}
|
||||||
# Optional SMTP / Mail Configuration (can also be configured in Admin UI)
|
# Optional SMTP / Mail Configuration (can also be configured in Admin UI)
|
||||||
|
|||||||
Generated
+1
-71
@@ -13,9 +13,7 @@
|
|||||||
"lucide-react": "^0.468.0",
|
"lucide-react": "^0.468.0",
|
||||||
"prismjs": "^1.30.0",
|
"prismjs": "^1.30.0",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1"
|
||||||
"y-indexeddb": "^9.0.12",
|
|
||||||
"yjs": "^13.6.33"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^18.3.12",
|
"@types/react": "^18.3.12",
|
||||||
@@ -1842,16 +1840,6 @@
|
|||||||
"node": ">=0.12.0"
|
"node": ">=0.12.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/isomorphic.js": {
|
|
||||||
"version": "0.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.2.5.tgz",
|
|
||||||
"integrity": "sha512-PIeMbHqMt4DnUP3MA/Flc0HElYjMXArsw1qwJZcm9sqR8mq3l8NYizFMty0pWwE/tzIGH3EKK5+jes5mAr85yw==",
|
|
||||||
"license": "MIT",
|
|
||||||
"funding": {
|
|
||||||
"type": "GitHub Sponsors ❤",
|
|
||||||
"url": "https://github.com/sponsors/dmonad"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/jiti": {
|
"node_modules/jiti": {
|
||||||
"version": "1.21.7",
|
"version": "1.21.7",
|
||||||
"resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.7.tgz",
|
"resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.7.tgz",
|
||||||
@@ -1894,27 +1882,6 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/lib0": {
|
|
||||||
"version": "0.2.119",
|
|
||||||
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.119.tgz",
|
|
||||||
"integrity": "sha512-vh+TiejVy8Xm+hCdnRfn9BthGNvNUZdEXltNjVZL3TzRIKP3s1lnQh8pWd/Q0wCgY0FPAGVVjFF4ZiHUV3LFgA==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"isomorphic.js": "^0.2.4"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"0ecdsa-generate-keypair": "bin/0ecdsa-generate-keypair.js",
|
|
||||||
"0gentesthtml": "bin/gentesthtml.js",
|
|
||||||
"0serve": "bin/0serve.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "GitHub Sponsors ❤",
|
|
||||||
"url": "https://github.com/sponsors/dmonad"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/lilconfig": {
|
"node_modules/lilconfig": {
|
||||||
"version": "3.1.4",
|
"version": "3.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.4.tgz",
|
||||||
@@ -2783,49 +2750,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/y-indexeddb": {
|
|
||||||
"version": "9.0.12",
|
|
||||||
"resolved": "https://registry.npmjs.org/y-indexeddb/-/y-indexeddb-9.0.12.tgz",
|
|
||||||
"integrity": "sha512-9oCFRSPPzBK7/w5vOkJBaVCQZKHXB/v6SIT+WYhnJxlEC61juqG0hBrAf+y3gmSMLFLwICNH9nQ53uscuse6Hg==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"lib0": "^0.2.74"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.0.0",
|
|
||||||
"npm": ">=8.0.0"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "GitHub Sponsors ❤",
|
|
||||||
"url": "https://github.com/sponsors/dmonad"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"yjs": "^13.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/yallist": {
|
"node_modules/yallist": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
||||||
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
|
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
|
||||||
"node_modules/yjs": {
|
|
||||||
"version": "13.6.33",
|
|
||||||
"resolved": "https://registry.npmjs.org/yjs/-/yjs-13.6.33.tgz",
|
|
||||||
"integrity": "sha512-q/UYvr1gOk4XII+Cu1CW2dINjYqJJFifTzogEaIARznrvX7uOlHsdTEXcnOBMuIsrCGEEKdNxi74kyMLZlKVfw==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"lib0": "^0.2.99"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.0.0",
|
|
||||||
"npm": ">=8.0.0"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "GitHub Sponsors ❤",
|
|
||||||
"url": "https://github.com/sponsors/dmonad"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,5 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||||
<rect width="512" height="512" rx="128" fill="#8ab4f8"/>
|
<rect width="512" height="512" rx="128" fill="#0b0f19"/>
|
||||||
<g transform="translate(80, 80) scale(14.666)" fill="none" stroke="#0b0f19" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
<circle cx="256" cy="256" r="164" fill="none" stroke="#8ab4f8" stroke-width="36"/>
|
||||||
<path d="M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z"/>
|
<path d="M184 266 L236 318 L338 194" fill="none" stroke="#c58af9" stroke-width="40" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
<path d="M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z"/>
|
|
||||||
<path d="M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4"/>
|
|
||||||
<path d="M17.599 6.5a3 3 0 0 0 .399-1.375"/>
|
|
||||||
<path d="M6.003 5.125A3 3 0 0 0 6.401 6.5"/>
|
|
||||||
<path d="M3.477 10.896a4 4 0 0 1 .585-.396"/>
|
|
||||||
<path d="M19.938 10.5a4 4 0 0 1 .585.396"/>
|
|
||||||
<path d="M6 18a4 4 0 0 1-1.967-.516"/>
|
|
||||||
<path d="M19.967 17.484A4 4 0 0 1 18 18"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 851 B After Width: | Height: | Size: 374 B |
+56
-77
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Layers,
|
Layers,
|
||||||
CheckSquare,
|
CheckSquare,
|
||||||
@@ -127,8 +127,6 @@ export const App: React.FC = () => {
|
|||||||
const [activeTab, setActiveTab] = useState<ActiveTab>('triage');
|
const [activeTab, setActiveTab] = useState<ActiveTab>('triage');
|
||||||
const [previousTab, setPreviousTab] = useState<ActiveTab>('triage');
|
const [previousTab, setPreviousTab] = useState<ActiveTab>('triage');
|
||||||
const [selectedDocId, setSelectedDocId] = useState<string | null>(null);
|
const [selectedDocId, setSelectedDocId] = useState<string | null>(null);
|
||||||
const [selectedBlockId, setSelectedBlockId] = useState<string | null>(null);
|
|
||||||
const [selectedTaskId, setSelectedTaskId] = useState<string | null>(null);
|
|
||||||
const [captureFocusCount, setCaptureFocusCount] = useState(0);
|
const [captureFocusCount, setCaptureFocusCount] = useState(0);
|
||||||
const [refreshRevision, setRefreshRevision] = useState(0);
|
const [refreshRevision, setRefreshRevision] = useState(0);
|
||||||
|
|
||||||
@@ -145,7 +143,6 @@ export const App: React.FC = () => {
|
|||||||
const [mobileVoiceActive, setMobileVoiceActive] = useState(false);
|
const [mobileVoiceActive, setMobileVoiceActive] = useState(false);
|
||||||
const [isVoiceCaptured, setIsVoiceCaptured] = useState(false);
|
const [isVoiceCaptured, setIsVoiceCaptured] = useState(false);
|
||||||
const mobileRecognitionRef = useRef<any>(null);
|
const mobileRecognitionRef = useRef<any>(null);
|
||||||
const mobileBaseVoiceRef = useRef('');
|
|
||||||
|
|
||||||
const toggleMobileVoice = () => {
|
const toggleMobileVoice = () => {
|
||||||
const SpeechRecognition =
|
const SpeechRecognition =
|
||||||
@@ -160,7 +157,6 @@ export const App: React.FC = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mobileBaseVoiceRef.current = mobileTriageContent.replace(/\s*\[…\]$/, '').trim();
|
|
||||||
const recognition = new SpeechRecognition();
|
const recognition = new SpeechRecognition();
|
||||||
recognition.lang = 'de-DE';
|
recognition.lang = 'de-DE';
|
||||||
recognition.continuous = false;
|
recognition.continuous = false;
|
||||||
@@ -174,8 +170,10 @@ export const App: React.FC = () => {
|
|||||||
for (let i = 0; i < event.results.length; i++) {
|
for (let i = 0; i < event.results.length; i++) {
|
||||||
transcript += event.results[i][0].transcript;
|
transcript += event.results[i][0].transcript;
|
||||||
}
|
}
|
||||||
const base = mobileBaseVoiceRef.current;
|
setMobileTriageContent((prev) => {
|
||||||
setMobileTriageContent(base ? `${base} ${transcript}` : transcript);
|
const base = prev.replace(/\s*\[…\]$/, '').trim();
|
||||||
|
return base ? `${base} ${transcript}` : transcript;
|
||||||
|
});
|
||||||
setIsVoiceCaptured(true);
|
setIsVoiceCaptured(true);
|
||||||
};
|
};
|
||||||
recognition.onerror = () => setMobileVoiceActive(false);
|
recognition.onerror = () => setMobileVoiceActive(false);
|
||||||
@@ -251,13 +249,6 @@ export const App: React.FC = () => {
|
|||||||
id: 'triage-nav',
|
id: 'triage-nav',
|
||||||
title: 'Bereiche wechseln',
|
title: 'Bereiche wechseln',
|
||||||
items: [
|
items: [
|
||||||
{
|
|
||||||
id: 'goto-workspace',
|
|
||||||
label: 'Notizen & Workspace',
|
|
||||||
icon: <FileText className="w-4 h-4" />,
|
|
||||||
badge: stats.docsCount,
|
|
||||||
onClick: () => setActiveTab('workspace'),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: 'goto-tasks',
|
id: 'goto-tasks',
|
||||||
label: 'Aufgaben & Kanban',
|
label: 'Aufgaben & Kanban',
|
||||||
@@ -265,6 +256,13 @@ export const App: React.FC = () => {
|
|||||||
badge: stats.tasksOpenCount,
|
badge: stats.tasksOpenCount,
|
||||||
onClick: () => setActiveTab('tasks'),
|
onClick: () => setActiveTab('tasks'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'goto-workspace',
|
||||||
|
label: 'Notizen & Workspace',
|
||||||
|
icon: <FileText className="w-4 h-4" />,
|
||||||
|
badge: stats.docsCount,
|
||||||
|
onClick: () => setActiveTab('workspace'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'goto-lists',
|
id: 'goto-lists',
|
||||||
label: 'Einkaufslisten',
|
label: 'Einkaufslisten',
|
||||||
@@ -299,18 +297,18 @@ export const App: React.FC = () => {
|
|||||||
variant: 'accent',
|
variant: 'accent',
|
||||||
onClick: () => setActiveTab('triage'),
|
onClick: () => setActiveTab('triage'),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: 'goto-workspace',
|
|
||||||
label: 'Zum Workspace',
|
|
||||||
icon: <FileText className="w-4 h-4" />,
|
|
||||||
onClick: () => setActiveTab('workspace'),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: 'goto-tasks',
|
id: 'goto-tasks',
|
||||||
label: 'Zu den Aufgaben',
|
label: 'Zu den Aufgaben',
|
||||||
icon: <CheckSquare className="w-4 h-4" />,
|
icon: <CheckSquare className="w-4 h-4" />,
|
||||||
onClick: () => setActiveTab('tasks'),
|
onClick: () => setActiveTab('tasks'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'goto-workspace',
|
||||||
|
label: 'Zum Workspace',
|
||||||
|
icon: <FileText className="w-4 h-4" />,
|
||||||
|
onClick: () => setActiveTab('workspace'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'goto-lists',
|
id: 'goto-lists',
|
||||||
label: 'Zu den Listen',
|
label: 'Zu den Listen',
|
||||||
@@ -416,7 +414,7 @@ export const App: React.FC = () => {
|
|||||||
setActiveThemeState(themeId);
|
setActiveThemeState(themeId);
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshAll = useCallback(async () => {
|
const refreshAll = async () => {
|
||||||
try {
|
try {
|
||||||
const [meRes, deckRes, listsRes] = await Promise.all([
|
const [meRes, deckRes, listsRes] = await Promise.all([
|
||||||
api.getMe(),
|
api.getMe(),
|
||||||
@@ -430,7 +428,7 @@ export const App: React.FC = () => {
|
|||||||
} catch {
|
} catch {
|
||||||
// If token expired or invalid, api.ts dispatches mindsift:unauthorized
|
// If token expired or invalid, api.ts dispatches mindsift:unauthorized
|
||||||
}
|
}
|
||||||
}, []);
|
};
|
||||||
|
|
||||||
const checkBootAndAuth = async () => {
|
const checkBootAndAuth = async () => {
|
||||||
setBootLoading(true);
|
setBootLoading(true);
|
||||||
@@ -551,17 +549,11 @@ export const App: React.FC = () => {
|
|||||||
refreshAll();
|
refreshAll();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOpenDocument = (docId: string, blockId?: string) => {
|
const handleOpenDocument = (docId: string) => {
|
||||||
setSelectedDocId(docId);
|
setSelectedDocId(docId);
|
||||||
setSelectedBlockId(blockId || null);
|
|
||||||
setActiveTab('workspace');
|
setActiveTab('workspace');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOpenTask = useCallback((taskId: string) => {
|
|
||||||
setSelectedTaskId(taskId);
|
|
||||||
setActiveTab('tasks');
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleTriggerAddButton = () => {
|
const handleTriggerAddButton = () => {
|
||||||
triggerHaptic(20);
|
triggerHaptic(20);
|
||||||
if (window.innerWidth < 640) {
|
if (window.innerWidth < 640) {
|
||||||
@@ -575,11 +567,7 @@ export const App: React.FC = () => {
|
|||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
triggerHaptic(20);
|
triggerHaptic(20);
|
||||||
disconnectWebSocket();
|
disconnectWebSocket();
|
||||||
try {
|
|
||||||
await api.logout();
|
|
||||||
} catch {
|
|
||||||
clearToken();
|
clearToken();
|
||||||
}
|
|
||||||
setUser(null);
|
setUser(null);
|
||||||
setShowProfileMenu(false);
|
setShowProfileMenu(false);
|
||||||
setActiveTab('triage');
|
setActiveTab('triage');
|
||||||
@@ -644,12 +632,9 @@ export const App: React.FC = () => {
|
|||||||
<Brain className="w-4 h-4" />
|
<Brain className="w-4 h-4" />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
<div className="flex flex-col">
|
<span className="font-bold text-base text-main tracking-tight">
|
||||||
<span className="font-bold text-base text-main tracking-tight leading-none">
|
|
||||||
{authStatus.instanceName || 'MindSift'}
|
{authStatus.instanceName || 'MindSift'}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-[9px] text-muted font-mono leading-tight mt-0.5">v0.1</span>
|
|
||||||
</div>
|
|
||||||
<span className="text-[11px] font-semibold text-accent bg-accent/15 px-1.5 py-0.5 rounded-md">
|
<span className="text-[11px] font-semibold text-accent bg-accent/15 px-1.5 py-0.5 rounded-md">
|
||||||
{activeTabLabelMap[activeTab]}
|
{activeTabLabelMap[activeTab]}
|
||||||
</span>
|
</span>
|
||||||
@@ -709,12 +694,9 @@ export const App: React.FC = () => {
|
|||||||
<div className="w-7 h-7 bg-accent text-on-accent rounded-btn flex items-center justify-center">
|
<div className="w-7 h-7 bg-accent text-on-accent rounded-btn flex items-center justify-center">
|
||||||
<Brain className="w-4 h-4" />
|
<Brain className="w-4 h-4" />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col">
|
|
||||||
<span className="font-bold text-sm sm:text-base text-main tracking-tight leading-none">
|
<span className="font-bold text-sm sm:text-base text-main tracking-tight leading-none">
|
||||||
{authStatus.instanceName || 'MindSift'}
|
{authStatus.instanceName || 'MindSift'}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-[10px] text-muted font-mono leading-tight mt-0.5">v0.1</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Quick-Capture Input Bubble directly in Header (above Tabs) */}
|
{/* Quick-Capture Input Bubble directly in Header (above Tabs) */}
|
||||||
@@ -880,24 +862,6 @@ export const App: React.FC = () => {
|
|||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
triggerHaptic(10);
|
|
||||||
setActiveTab('workspace');
|
|
||||||
}}
|
|
||||||
className={`tab-btn ${activeTab === 'workspace' ? 'tab-btn-active' : ''}`}
|
|
||||||
>
|
|
||||||
<FileText className="w-4 h-4" />
|
|
||||||
<span className={`relative inline-flex items-center ${(stats.docsTodosOpenCount ?? 0) > 0 ? 'pr-2' : ''}`}>
|
|
||||||
<span>Workspace</span>
|
|
||||||
{(stats.docsTodosOpenCount ?? 0) > 0 && (
|
|
||||||
<span className="absolute -top-1.5 -right-1 min-w-[15px] h-[15px] px-0.5 rounded-full text-[9px] font-bold leading-none bg-accent text-on-accent flex items-center justify-center shadow-sm pointer-events-none">
|
|
||||||
{stats.docsTodosOpenCount}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
triggerHaptic(10);
|
triggerHaptic(10);
|
||||||
@@ -916,6 +880,24 @@ export const App: React.FC = () => {
|
|||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
triggerHaptic(10);
|
||||||
|
setActiveTab('workspace');
|
||||||
|
}}
|
||||||
|
className={`tab-btn ${activeTab === 'workspace' ? 'tab-btn-active' : ''}`}
|
||||||
|
>
|
||||||
|
<FileText className="w-4 h-4" />
|
||||||
|
<span className={`relative inline-flex items-center ${(stats.docsTodosOpenCount ?? 0) > 0 ? 'pr-2' : ''}`}>
|
||||||
|
<span>Workspace</span>
|
||||||
|
{(stats.docsTodosOpenCount ?? 0) > 0 && (
|
||||||
|
<span className="absolute -top-1.5 -right-1 min-w-[15px] h-[15px] px-0.5 rounded-full text-[9px] font-bold leading-none bg-accent text-on-accent flex items-center justify-center shadow-sm pointer-events-none">
|
||||||
|
{stats.docsTodosOpenCount}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
triggerHaptic(10);
|
triggerHaptic(10);
|
||||||
@@ -968,7 +950,6 @@ export const App: React.FC = () => {
|
|||||||
onRefreshStats={refreshAll}
|
onRefreshStats={refreshAll}
|
||||||
onOpenDocument={handleOpenDocument}
|
onOpenDocument={handleOpenDocument}
|
||||||
refreshTrigger={refreshRevision}
|
refreshTrigger={refreshRevision}
|
||||||
initialSelectedTaskId={selectedTaskId}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -976,9 +957,7 @@ export const App: React.FC = () => {
|
|||||||
<WorkspaceView
|
<WorkspaceView
|
||||||
currentUser={user}
|
currentUser={user}
|
||||||
initialDocId={selectedDocId}
|
initialDocId={selectedDocId}
|
||||||
initialBlockId={selectedBlockId}
|
|
||||||
onStatsChange={refreshAll}
|
onStatsChange={refreshAll}
|
||||||
onOpenTask={handleOpenTask}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -1045,27 +1024,27 @@ export const App: React.FC = () => {
|
|||||||
<span className="text-[10px] leading-tight">Triage</span>
|
<span className="text-[10px] leading-tight">Triage</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Col 2: Workspace */}
|
{/* Col 2: Aufgaben */}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
triggerHaptic(10);
|
triggerHaptic(10);
|
||||||
setActiveTab('workspace');
|
setActiveTab('tasks');
|
||||||
}}
|
}}
|
||||||
className={`min-h-[48px] rounded-xl flex flex-col items-center justify-center gap-0.5 transition-colors relative cursor-pointer active:scale-95 ${
|
className={`min-h-[48px] rounded-xl flex flex-col items-center justify-center gap-0.5 transition-colors relative cursor-pointer active:scale-95 ${
|
||||||
activeTab === 'workspace' ? 'text-accent font-semibold' : 'text-muted hover:text-main'
|
activeTab === 'tasks' ? 'text-accent font-semibold' : 'text-muted hover:text-main'
|
||||||
}`}
|
}`}
|
||||||
title="Workspace"
|
title="Aufgaben"
|
||||||
>
|
>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<FileText className="w-5 h-5" />
|
<CheckSquare className="w-5 h-5" />
|
||||||
{(stats.docsTodosOpenCount ?? 0) > 0 && (
|
{stats.tasksOpenCount > 0 && (
|
||||||
<span className="absolute -top-1.5 -right-2.5 min-w-[16px] h-[16px] px-1 rounded-full text-[9px] font-bold leading-none bg-accent text-on-accent flex items-center justify-center shadow-xs pointer-events-none">
|
<span className="absolute -top-1.5 -right-2.5 min-w-[16px] h-[16px] px-1 rounded-full text-[9px] font-bold leading-none bg-accent text-on-accent flex items-center justify-center shadow-xs pointer-events-none">
|
||||||
{stats.docsTodosOpenCount}
|
{stats.tasksOpenCount}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[10px] leading-tight">Workspace</span>
|
<span className="text-[10px] leading-tight">Aufgaben</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Col 3 (EXACT CENTER): + Quick-Add FAB */}
|
{/* Col 3 (EXACT CENTER): + Quick-Add FAB */}
|
||||||
@@ -1087,27 +1066,27 @@ export const App: React.FC = () => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Col 4: Aufgaben */}
|
{/* Col 4: Workspace */}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
triggerHaptic(10);
|
triggerHaptic(10);
|
||||||
setActiveTab('tasks');
|
setActiveTab('workspace');
|
||||||
}}
|
}}
|
||||||
className={`min-h-[48px] rounded-xl flex flex-col items-center justify-center gap-0.5 transition-colors relative cursor-pointer active:scale-95 ${
|
className={`min-h-[48px] rounded-xl flex flex-col items-center justify-center gap-0.5 transition-colors relative cursor-pointer active:scale-95 ${
|
||||||
activeTab === 'tasks' ? 'text-accent font-semibold' : 'text-muted hover:text-main'
|
activeTab === 'workspace' ? 'text-accent font-semibold' : 'text-muted hover:text-main'
|
||||||
}`}
|
}`}
|
||||||
title="Aufgaben"
|
title="Workspace"
|
||||||
>
|
>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<CheckSquare className="w-5 h-5" />
|
<FileText className="w-5 h-5" />
|
||||||
{stats.tasksOpenCount > 0 && (
|
{(stats.docsTodosOpenCount ?? 0) > 0 && (
|
||||||
<span className="absolute -top-1.5 -right-2.5 min-w-[16px] h-[16px] px-1 rounded-full text-[9px] font-bold leading-none bg-accent text-on-accent flex items-center justify-center shadow-xs pointer-events-none">
|
<span className="absolute -top-1.5 -right-2.5 min-w-[16px] h-[16px] px-1 rounded-full text-[9px] font-bold leading-none bg-accent text-on-accent flex items-center justify-center shadow-xs pointer-events-none">
|
||||||
{stats.tasksOpenCount}
|
{stats.docsTodosOpenCount}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[10px] leading-tight">Aufgaben</span>
|
<span className="text-[10px] leading-tight">Workspace</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{/* Col 5: Listen */}
|
{/* Col 5: Listen */}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ export interface UnifiedShareModalProps {
|
|||||||
teams: Team[];
|
teams: Team[];
|
||||||
collaborators: User[];
|
collaborators: User[];
|
||||||
allowRoleSelection?: boolean; // Default true (editor vs viewer)
|
allowRoleSelection?: boolean; // Default true (editor vs viewer)
|
||||||
fixedPermission?: 'editor' | 'viewer'; // When allowRoleSelection is false, force fixedPermission (default 'viewer' for documents, 'editor' for tasks/lists)
|
|
||||||
onAddShare: (targetType: 'team' | 'user', targetId: string, permission: 'editor' | 'viewer') => Promise<void>;
|
onAddShare: (targetType: 'team' | 'user', targetId: string, permission: 'editor' | 'viewer') => Promise<void>;
|
||||||
onRemoveShare: (shareId: string) => Promise<void>;
|
onRemoveShare: (shareId: string) => Promise<void>;
|
||||||
}
|
}
|
||||||
@@ -41,17 +40,13 @@ export const UnifiedShareModal: React.FC<UnifiedShareModalProps> = ({
|
|||||||
teams,
|
teams,
|
||||||
collaborators,
|
collaborators,
|
||||||
allowRoleSelection = true,
|
allowRoleSelection = true,
|
||||||
fixedPermission,
|
|
||||||
onAddShare,
|
onAddShare,
|
||||||
onRemoveShare,
|
onRemoveShare,
|
||||||
}) => {
|
}) => {
|
||||||
const effectiveFixedPerm = fixedPermission || 'viewer';
|
|
||||||
const [shareType, setShareType] = useState<'team' | 'user'>('team');
|
const [shareType, setShareType] = useState<'team' | 'user'>('team');
|
||||||
const [selectedTeamId, setSelectedTeamId] = useState('');
|
const [selectedTeamId, setSelectedTeamId] = useState('');
|
||||||
const [selectedUser, setSelectedUser] = useState<User | null>(null);
|
const [selectedUser, setSelectedUser] = useState<User | null>(null);
|
||||||
const [selectedPermission, setSelectedPermission] = useState<'editor' | 'viewer'>(
|
const [selectedPermission, setSelectedPermission] = useState<'editor' | 'viewer'>('editor');
|
||||||
allowRoleSelection ? 'editor' : effectiveFixedPerm
|
|
||||||
);
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
@@ -68,8 +63,7 @@ export const UnifiedShareModal: React.FC<UnifiedShareModalProps> = ({
|
|||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const permToUse = allowRoleSelection ? selectedPermission : effectiveFixedPerm;
|
await onAddShare(shareType, targetId, selectedPermission);
|
||||||
await onAddShare(shareType, targetId, permToUse);
|
|
||||||
setSelectedTeamId('');
|
setSelectedTeamId('');
|
||||||
setSelectedUser(null);
|
setSelectedUser(null);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -202,7 +196,7 @@ export const UnifiedShareModal: React.FC<UnifiedShareModalProps> = ({
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
{allowRoleSelection ? (
|
{allowRoleSelection && (
|
||||||
<select
|
<select
|
||||||
value={selectedPermission}
|
value={selectedPermission}
|
||||||
onChange={(e) => setSelectedPermission(e.target.value as 'editor' | 'viewer')}
|
onChange={(e) => setSelectedPermission(e.target.value as 'editor' | 'viewer')}
|
||||||
@@ -212,20 +206,6 @@ export const UnifiedShareModal: React.FC<UnifiedShareModalProps> = ({
|
|||||||
<option value="editor" className="bg-panel text-main">Bearbeiten</option>
|
<option value="editor" className="bg-panel text-main">Bearbeiten</option>
|
||||||
<option value="viewer" className="bg-panel text-main">Nur Lesen</option>
|
<option value="viewer" className="bg-panel text-main">Nur Lesen</option>
|
||||||
</select>
|
</select>
|
||||||
) : (
|
|
||||||
<span className="inline-flex items-center gap-1 text-[11px] text-muted px-2 py-1 bg-panel rounded border border-border shrink-0 self-center">
|
|
||||||
{effectiveFixedPerm === 'editor' ? (
|
|
||||||
<>
|
|
||||||
<Check className="w-3 h-3 text-accent" />
|
|
||||||
Bearbeiten
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Lock className="w-3 h-3 text-faint" />
|
|
||||||
Nur Lesen
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -240,7 +220,7 @@ export const UnifiedShareModal: React.FC<UnifiedShareModalProps> = ({
|
|||||||
placeholder="Benutzer suchen (Name oder @Benutzername)…"
|
placeholder="Benutzer suchen (Name oder @Benutzername)…"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{allowRoleSelection ? (
|
{allowRoleSelection && (
|
||||||
<select
|
<select
|
||||||
value={selectedPermission}
|
value={selectedPermission}
|
||||||
onChange={(e) => setSelectedPermission(e.target.value as 'editor' | 'viewer')}
|
onChange={(e) => setSelectedPermission(e.target.value as 'editor' | 'viewer')}
|
||||||
@@ -250,20 +230,6 @@ export const UnifiedShareModal: React.FC<UnifiedShareModalProps> = ({
|
|||||||
<option value="editor" className="bg-panel text-main">Bearbeiten</option>
|
<option value="editor" className="bg-panel text-main">Bearbeiten</option>
|
||||||
<option value="viewer" className="bg-panel text-main">Nur Lesen</option>
|
<option value="viewer" className="bg-panel text-main">Nur Lesen</option>
|
||||||
</select>
|
</select>
|
||||||
) : (
|
|
||||||
<span className="inline-flex items-center gap-1 text-[11px] text-muted px-2 py-1 bg-panel rounded border border-border shrink-0 self-center">
|
|
||||||
{effectiveFixedPerm === 'editor' ? (
|
|
||||||
<>
|
|
||||||
<Check className="w-3 h-3 text-accent" />
|
|
||||||
Bearbeiten
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Lock className="w-3 h-3 text-faint" />
|
|
||||||
Nur Lesen
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ export const InstantCaptureBar: React.FC<InstantCaptureBarProps> = ({
|
|||||||
const inputRef = useRef<HTMLTextAreaElement>(null);
|
const inputRef = useRef<HTMLTextAreaElement>(null);
|
||||||
const containerRef = useRef<HTMLFormElement>(null);
|
const containerRef = useRef<HTMLFormElement>(null);
|
||||||
const recognitionRef = useRef<any>(null);
|
const recognitionRef = useRef<any>(null);
|
||||||
const baseVoiceTextRef = useRef('');
|
|
||||||
const hasVoiceInputRef = useRef(false);
|
|
||||||
|
|
||||||
const adjustHeight = (el?: HTMLTextAreaElement | null) => {
|
const adjustHeight = (el?: HTMLTextAreaElement | null) => {
|
||||||
const targetEl = el || inputRef.current;
|
const targetEl = el || inputRef.current;
|
||||||
@@ -133,9 +131,6 @@ export const InstantCaptureBar: React.FC<InstantCaptureBarProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
baseVoiceTextRef.current = content.replace(/\s*\[…\]$/, '').trim();
|
|
||||||
hasVoiceInputRef.current = true;
|
|
||||||
|
|
||||||
const recognition = new SpeechRecognition();
|
const recognition = new SpeechRecognition();
|
||||||
recognition.lang = 'de-DE';
|
recognition.lang = 'de-DE';
|
||||||
recognition.continuous = false;
|
recognition.continuous = false;
|
||||||
@@ -151,8 +146,10 @@ export const InstantCaptureBar: React.FC<InstantCaptureBarProps> = ({
|
|||||||
for (let i = 0; i < event.results.length; i++) {
|
for (let i = 0; i < event.results.length; i++) {
|
||||||
transcript += event.results[i][0].transcript;
|
transcript += event.results[i][0].transcript;
|
||||||
}
|
}
|
||||||
const base = baseVoiceTextRef.current;
|
setContent((prev) => {
|
||||||
setContent(base ? `${base} ${transcript}` : transcript);
|
const base = prev.replace(/\s*\[…\]$/, '').trim();
|
||||||
|
return base ? `${base} ${transcript}` : transcript;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
recognition.onerror = () => {
|
recognition.onerror = () => {
|
||||||
@@ -183,8 +180,7 @@ export const InstantCaptureBar: React.FC<InstantCaptureBarProps> = ({
|
|||||||
overrideListId || targetListId || (lists.length > 0 ? lists[0].id : '');
|
overrideListId || targetListId || (lists.length > 0 ? lists[0].id : '');
|
||||||
const capturedPriority = priority;
|
const capturedPriority = priority;
|
||||||
const capturedDueDate = dueDate;
|
const capturedDueDate = dueDate;
|
||||||
const capturedSource = hasVoiceInputRef.current || isListening ? 'voice' : 'manual';
|
const capturedSource = isListening ? 'voice' : 'manual';
|
||||||
hasVoiceInputRef.current = false;
|
|
||||||
|
|
||||||
// Optimistically clear input immediately so the UI feels instant (<10ms) in all browsers
|
// Optimistically clear input immediately so the UI feels instant (<10ms) in all browsers
|
||||||
setContent('');
|
setContent('');
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ import {
|
|||||||
Sparkles,
|
Sparkles,
|
||||||
X,
|
X,
|
||||||
Hash,
|
Hash,
|
||||||
ShoppingCart,
|
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { ListItem, SharedList, ListShare, Team, User, WSMessage } from '../../lib/types';
|
import { ListItem, SharedList, ListShare, Team, User, WSMessage } from '../../lib/types';
|
||||||
import { api, buildWebSocketURL, triggerHaptic, createRealtimeConnection, RealtimeTransport } from '../../lib/api';
|
import { api, buildWebSocketURL, triggerHaptic } from '../../lib/api';
|
||||||
import { UnifiedShareModal } from '../../components/UnifiedShareModal';
|
import { UnifiedShareModal } from '../../components/UnifiedShareModal';
|
||||||
import { useMobileActions } from '../../context/MobileActionContext';
|
import { useMobileActions } from '../../context/MobileActionContext';
|
||||||
|
|
||||||
@@ -85,11 +84,8 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
const [newItemText, setNewItemText] = useState('');
|
const [newItemText, setNewItemText] = useState('');
|
||||||
const [newItemQty, setNewItemQty] = useState('');
|
const [newItemQty, setNewItemQty] = useState('');
|
||||||
const [isSubmittingItem, setIsSubmittingItem] = useState(false);
|
const [isSubmittingItem, setIsSubmittingItem] = useState(false);
|
||||||
const [editingQtyItemId, setEditingQtyItemId] = useState<string | null>(null);
|
|
||||||
const [editingQtyValue, setEditingQtyValue] = useState('');
|
|
||||||
|
|
||||||
const [wsConnected, setWsConnected] = useState(false);
|
const [wsConnected, setWsConnected] = useState(false);
|
||||||
const [realtimeTransport, setRealtimeTransport] = useState<RealtimeTransport>('none');
|
|
||||||
const [showNewListModal, setShowNewListModal] = useState(false);
|
const [showNewListModal, setShowNewListModal] = useState(false);
|
||||||
const [newListTitle, setNewListTitle] = useState('');
|
const [newListTitle, setNewListTitle] = useState('');
|
||||||
const [newListIcon, setNewListIcon] = useState('🛒');
|
const [newListIcon, setNewListIcon] = useState('🛒');
|
||||||
@@ -108,7 +104,7 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
const [dragOverItemTarget, setDragOverItemTarget] = useState<{ itemId: string; position: 'before' | 'after' } | null>(null);
|
const [dragOverItemTarget, setDragOverItemTarget] = useState<{ itemId: string; position: 'before' | 'after' } | null>(null);
|
||||||
const [dragOverCategoryTarget, setDragOverCategoryTarget] = useState<string | null>(null);
|
const [dragOverCategoryTarget, setDragOverCategoryTarget] = useState<string | null>(null);
|
||||||
|
|
||||||
const realtimeConnRef = useRef<any>(null);
|
const wsRef = useRef<WebSocket | null>(null);
|
||||||
|
|
||||||
const loadLists = async () => {
|
const loadLists = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -151,20 +147,26 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!activeList?.id) return;
|
if (!activeList?.id) return;
|
||||||
|
|
||||||
if (realtimeConnRef.current) {
|
if (wsRef.current) {
|
||||||
try {
|
wsRef.current.close();
|
||||||
realtimeConnRef.current.close();
|
|
||||||
} catch {}
|
|
||||||
realtimeConnRef.current = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const conn = createRealtimeConnection({
|
let ws: WebSocket | null = null;
|
||||||
listId: activeList.id,
|
try {
|
||||||
onStatusChange: (status) => {
|
ws = new WebSocket(buildWebSocketURL(activeList.id));
|
||||||
setWsConnected(status.connected);
|
wsRef.current = ws;
|
||||||
setRealtimeTransport(status.transport);
|
|
||||||
},
|
ws.onopen = () => {
|
||||||
onMessage: (msg: WSMessage) => {
|
setWsConnected(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onclose = () => {
|
||||||
|
setWsConnected(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onmessage = (evt) => {
|
||||||
|
try {
|
||||||
|
const msg: WSMessage = JSON.parse(evt.data);
|
||||||
const msgListId = msg.listId || (msg as any).list_id;
|
const msgListId = msg.listId || (msg as any).list_id;
|
||||||
if (msg.event === 'ITEM_CREATED' && msgListId) {
|
if (msg.event === 'ITEM_CREATED' && msgListId) {
|
||||||
const newItem: ListItem = msg.payload;
|
const newItem: ListItem = msg.payload;
|
||||||
@@ -176,7 +178,7 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
return { ...l, items: deduplicateItems([newItem, ...l.items]) };
|
return { ...l, items: deduplicateItems([newItem, ...l.items]) };
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else if ((msg.event === 'ITEM_TOGGLED' || msg.event === 'ITEM_UPDATED') && msgListId) {
|
} else if (msg.event === 'ITEM_TOGGLED' && msgListId) {
|
||||||
const updatedItem: ListItem = msg.payload;
|
const updatedItem: ListItem = msg.payload;
|
||||||
setLists((prev) =>
|
setLists((prev) =>
|
||||||
prev.map((l) => {
|
prev.map((l) => {
|
||||||
@@ -212,18 +214,16 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
) {
|
) {
|
||||||
loadLists();
|
loadLists();
|
||||||
}
|
}
|
||||||
},
|
} catch {
|
||||||
});
|
// ignore malformed frames
|
||||||
|
}
|
||||||
realtimeConnRef.current = conn;
|
};
|
||||||
|
} catch {
|
||||||
|
setWsConnected(false);
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (realtimeConnRef.current) {
|
if (ws) ws.close();
|
||||||
try {
|
|
||||||
realtimeConnRef.current.close();
|
|
||||||
} catch {}
|
|
||||||
realtimeConnRef.current = null;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}, [activeList?.id]);
|
}, [activeList?.id]);
|
||||||
|
|
||||||
@@ -275,26 +275,6 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveQuantity = async (itemId: string, quantity: string) => {
|
|
||||||
setEditingQtyItemId(null);
|
|
||||||
if (!activeList) return;
|
|
||||||
const trimmed = quantity.trim();
|
|
||||||
try {
|
|
||||||
const updated = await api.updateListItem(activeList.id, itemId, { quantity: trimmed });
|
|
||||||
setLists((prev) =>
|
|
||||||
prev.map((l) => {
|
|
||||||
if (l.id !== activeList.id) return l;
|
|
||||||
return {
|
|
||||||
...l,
|
|
||||||
items: l.items.map((i) => (i.id === itemId ? { ...i, quantity: updated.quantity } : i)),
|
|
||||||
};
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('Fehler beim Aktualisieren der Menge', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleToggleItem = async (item: ListItem) => {
|
const handleToggleItem = async (item: ListItem) => {
|
||||||
if (!activeList) return;
|
if (!activeList) return;
|
||||||
triggerHaptic(10);
|
triggerHaptic(10);
|
||||||
@@ -817,8 +797,44 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full space-y-3">
|
<div className="w-full space-y-3">
|
||||||
|
{/* Mobile Compact Header Bar (List switching & actions live in MindSift Logo Menu) */}
|
||||||
|
<div className="flex sm:hidden items-center justify-between gap-2 px-3 py-2 rounded-btn bg-panel border border-border">
|
||||||
|
<div className="flex items-center gap-2 min-w-0">
|
||||||
|
<span className="text-sm font-semibold text-main truncate">
|
||||||
|
{activeList ? `${activeList.icon} ${activeList.title}` : '🛒 Einkaufsliste'}
|
||||||
|
</span>
|
||||||
|
{openItems.length > 0 && (
|
||||||
|
<span className="badge-neutral text-[11px] flex-shrink-0">
|
||||||
|
{openItems.length} offen
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-1.5 flex-shrink-0">
|
||||||
|
{activeList && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={openShareModal}
|
||||||
|
className="btn-icon min-h-[36px] min-w-[36px] flex items-center justify-center"
|
||||||
|
title="Liste teilen"
|
||||||
|
>
|
||||||
|
<Users className="w-4 h-4 text-accent" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<div
|
||||||
|
className={`h-9 w-9 flex items-center justify-center rounded-btn border ${
|
||||||
|
wsConnected
|
||||||
|
? 'bg-emerald-500/10 border-emerald-500/30 text-emerald-500'
|
||||||
|
: 'bg-canvas border-border text-muted'
|
||||||
|
}`}
|
||||||
|
title={wsConnected ? 'Live synchronisiert (Online)' : 'Offline'}
|
||||||
|
>
|
||||||
|
<Radio className={`w-3.5 h-3.5 ${wsConnected ? 'animate-pulse' : ''}`} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Top Header: List Tabs & Actions (Desktop) */}
|
{/* Top Header: List Tabs & Actions (Desktop) */}
|
||||||
<div className="hidden sm:flex flex-wrap items-center justify-between gap-2 border-b border-border pb-2 !mt-0">
|
<div className="hidden sm:flex flex-wrap items-center justify-between gap-2 border-b border-border pb-2">
|
||||||
{/* List Tabs */}
|
{/* List Tabs */}
|
||||||
<div className="flex flex-wrap items-center gap-1">
|
<div className="flex flex-wrap items-center gap-1">
|
||||||
{lists.map((lst) => {
|
{lists.map((lst) => {
|
||||||
@@ -911,64 +927,12 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
|
|
||||||
{/* Live Sync Status */}
|
{/* Live Sync Status */}
|
||||||
<div
|
<div
|
||||||
className={`h-8 w-8 flex items-center justify-center rounded-btn border transition-colors ${
|
className={`h-8 w-8 flex items-center justify-center rounded-btn border ${
|
||||||
wsConnected
|
wsConnected
|
||||||
? realtimeTransport === 'sse'
|
? 'bg-emerald-500/10 border-emerald-500/30 text-emerald-500'
|
||||||
? 'bg-teal-500/10 border-teal-500/30 text-teal-400'
|
|
||||||
: 'bg-emerald-500/10 border-emerald-500/30 text-emerald-500'
|
|
||||||
: 'bg-canvas border-border text-muted'
|
: 'bg-canvas border-border text-muted'
|
||||||
}`}
|
}`}
|
||||||
title={
|
title={wsConnected ? 'Live synchronisiert (Online)' : 'Offline'}
|
||||||
wsConnected
|
|
||||||
? realtimeTransport === 'sse'
|
|
||||||
? 'Live synchronisiert (Server-Sent Events / Proxy-Stream)'
|
|
||||||
: 'Live synchronisiert (WebSocket online)'
|
|
||||||
: 'Offline'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Radio className={`w-3.5 h-3.5 ${wsConnected ? 'animate-pulse' : ''}`} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Mobile Compact Header Bar (List switching & actions live in MindSift Logo Menu) */}
|
|
||||||
<div className="flex sm:hidden items-center justify-between gap-2 px-3 py-2 rounded-btn bg-panel border border-border !mt-0">
|
|
||||||
<div className="flex items-center gap-2 min-w-0">
|
|
||||||
<span className="text-sm font-semibold text-main truncate">
|
|
||||||
{activeList ? `${activeList.icon} ${activeList.title}` : '🛒 Einkaufsliste'}
|
|
||||||
</span>
|
|
||||||
{openItems.length > 0 && (
|
|
||||||
<span className="badge-neutral text-[11px] flex-shrink-0">
|
|
||||||
{openItems.length} offen
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-1.5 flex-shrink-0">
|
|
||||||
{activeList && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={openShareModal}
|
|
||||||
className="btn-icon min-h-[36px] min-w-[36px] flex items-center justify-center"
|
|
||||||
title="Liste teilen"
|
|
||||||
>
|
|
||||||
<Users className="w-4 h-4 text-accent" />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
<div
|
|
||||||
className={`h-9 w-9 flex items-center justify-center rounded-btn border transition-colors ${
|
|
||||||
wsConnected
|
|
||||||
? realtimeTransport === 'sse'
|
|
||||||
? 'bg-teal-500/10 border-teal-500/30 text-teal-400'
|
|
||||||
: 'bg-emerald-500/10 border-emerald-500/30 text-emerald-500'
|
|
||||||
: 'bg-canvas border-border text-muted'
|
|
||||||
}`}
|
|
||||||
title={
|
|
||||||
wsConnected
|
|
||||||
? realtimeTransport === 'sse'
|
|
||||||
? 'Live synchronisiert (Server-Sent Events / Proxy-Stream)'
|
|
||||||
: 'Live synchronisiert (WebSocket online)'
|
|
||||||
: 'Offline'
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<Radio className={`w-3.5 h-3.5 ${wsConnected ? 'animate-pulse' : ''}`} />
|
<Radio className={`w-3.5 h-3.5 ${wsConnected ? 'animate-pulse' : ''}`} />
|
||||||
</div>
|
</div>
|
||||||
@@ -976,61 +940,41 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{showNewListModal && (
|
{showNewListModal && (
|
||||||
<div className="fixed inset-0 !m-0 modal-overlay z-50 flex items-center justify-center p-4">
|
<form
|
||||||
<div className="w-full max-w-sm panel-surface shadow-panel p-4 space-y-3">
|
onSubmit={handleCreateList}
|
||||||
<div className="flex items-center justify-between border-b border-border pb-2">
|
className="p-2 panel-surface flex flex-wrap items-center gap-2"
|
||||||
<h3 className="text-sm font-semibold text-main flex items-center gap-1.5">
|
|
||||||
<ShoppingCart className="w-4 h-4 text-accent" />
|
|
||||||
<span>Neue Einkaufsliste erstellen</span>
|
|
||||||
</h3>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setShowNewListModal(false)}
|
|
||||||
className="text-muted hover:text-main"
|
|
||||||
>
|
>
|
||||||
<X className="w-4 h-4" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form onSubmit={handleCreateList} className="space-y-3">
|
|
||||||
<div>
|
|
||||||
<label className="block text-xs text-muted mb-1">Titel der Liste</label>
|
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
<input
|
{['🛒', '🏔️', '🍕', '🎉', '🧰', '🎁'].map((ic) => (
|
||||||
type="text"
|
<button
|
||||||
value={newListIcon}
|
key={ic}
|
||||||
onChange={(e) => setNewListIcon(e.target.value)}
|
type="button"
|
||||||
maxLength={2}
|
onClick={() => setNewListIcon(ic)}
|
||||||
className="w-10 h-8 text-center input-field text-sm"
|
className={`w-9 h-9 flex items-center justify-center rounded-btn transition-colors ${
|
||||||
title="Icon (Emoji)"
|
newListIcon === ic
|
||||||
/>
|
? 'bg-accent/20 border border-accent text-accent'
|
||||||
|
: 'bg-canvas hover:bg-panel-elevated border border-border'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{ic}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={newListTitle}
|
value={newListTitle}
|
||||||
onChange={(e) => setNewListTitle(e.target.value)}
|
onChange={(e) => setNewListTitle(e.target.value)}
|
||||||
placeholder="z.B. Supermarkt, Baumarkt, Drogerie"
|
placeholder="Titel der Liste (z. B. Baumarkt, Drogerie, Camping)…"
|
||||||
|
className="flex-1 h-9 px-3 input-field text-sm"
|
||||||
autoFocus
|
autoFocus
|
||||||
required
|
|
||||||
className="flex-1 h-8 input-field px-2.5 text-xs"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-end gap-2 pt-2 border-t border-border">
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="submit"
|
||||||
onClick={() => setShowNewListModal(false)}
|
className="btn-primary h-9 px-4 text-xs sm:text-sm"
|
||||||
className="btn-action h-7 px-3 text-xs"
|
|
||||||
>
|
>
|
||||||
Abbrechen
|
Liste erstellen
|
||||||
</button>
|
</button>
|
||||||
<button type="submit" className="btn-primary h-7 px-3 text-xs">
|
|
||||||
Erstellen
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Active Shared List View */}
|
{/* Active Shared List View */}
|
||||||
@@ -1107,8 +1051,8 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={newItemQty}
|
value={newItemQty}
|
||||||
onChange={(e) => setNewItemQty(e.target.value.replace(/[^0-9.,xX]/g, ''))}
|
onChange={(e) => setNewItemQty(e.target.value)}
|
||||||
placeholder="Menge (z.B. 2)"
|
placeholder="Menge (z.B. 2x)"
|
||||||
className="flex-1 sm:flex-none sm:w-28 h-9 sm:h-7 px-2.5 sm:px-2 input-field text-xs"
|
className="flex-1 sm:flex-none sm:w-28 h-9 sm:h-7 px-2.5 sm:px-2 input-field text-xs"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
@@ -1218,45 +1162,10 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
{displayContent}
|
{displayContent}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{editingQtyItemId === item.id ? (
|
{item.quantity && (
|
||||||
<div className="flex items-center gap-1" onClick={(e) => e.stopPropagation()}>
|
<span className="badge-accent">
|
||||||
<input
|
{item.quantity}
|
||||||
type="text"
|
</span>
|
||||||
autoFocus
|
|
||||||
value={editingQtyValue}
|
|
||||||
onChange={(e) => setEditingQtyValue(e.target.value.replace(/[^0-9.,xX]/g, ''))}
|
|
||||||
onKeyDown={async (e) => {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
e.preventDefault();
|
|
||||||
await handleSaveQuantity(item.id, editingQtyValue);
|
|
||||||
} else if (e.key === 'Escape') {
|
|
||||||
setEditingQtyItemId(null);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onBlur={async () => {
|
|
||||||
await handleSaveQuantity(item.id, editingQtyValue);
|
|
||||||
}}
|
|
||||||
className="w-16 h-6 px-1.5 text-xs input-field font-semibold text-accent text-center"
|
|
||||||
placeholder="Menge"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
setEditingQtyItemId(item.id);
|
|
||||||
setEditingQtyValue(item.quantity || '');
|
|
||||||
}}
|
|
||||||
className={`text-xs px-2 py-0.5 rounded-full transition-colors ${
|
|
||||||
item.quantity
|
|
||||||
? 'badge-accent cursor-pointer hover:brightness-125'
|
|
||||||
: 'opacity-0 group-hover:opacity-60 hover:!opacity-100 text-muted hover:text-accent border border-dashed border-border/70 hover:border-accent text-[11px]'
|
|
||||||
}`}
|
|
||||||
title="Menge bearbeiten"
|
|
||||||
>
|
|
||||||
{item.quantity || '+ Menge'}
|
|
||||||
</button>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{cat && !group.label && (
|
{cat && !group.label && (
|
||||||
@@ -1331,45 +1240,8 @@ export const SharedListsView: React.FC<SharedListsViewProps> = ({ onRefreshGloba
|
|||||||
{displayContent}
|
{displayContent}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{editingQtyItemId === item.id ? (
|
{item.quantity && (
|
||||||
<div className="flex items-center gap-1" onClick={(e) => e.stopPropagation()}>
|
<span className="text-xs text-faint">({item.quantity})</span>
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
autoFocus
|
|
||||||
value={editingQtyValue}
|
|
||||||
onChange={(e) => setEditingQtyValue(e.target.value.replace(/[^0-9.,xX]/g, ''))}
|
|
||||||
onKeyDown={async (e) => {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
e.preventDefault();
|
|
||||||
await handleSaveQuantity(item.id, editingQtyValue);
|
|
||||||
} else if (e.key === 'Escape') {
|
|
||||||
setEditingQtyItemId(null);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onBlur={async () => {
|
|
||||||
await handleSaveQuantity(item.id, editingQtyValue);
|
|
||||||
}}
|
|
||||||
className="w-16 h-6 px-1.5 text-xs input-field font-semibold text-accent text-center"
|
|
||||||
placeholder="Menge"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
setEditingQtyItemId(item.id);
|
|
||||||
setEditingQtyValue(item.quantity || '');
|
|
||||||
}}
|
|
||||||
className={`text-xs px-1.5 py-0.5 rounded transition-colors ${
|
|
||||||
item.quantity
|
|
||||||
? 'text-faint hover:text-main cursor-pointer'
|
|
||||||
: 'opacity-0 group-hover:opacity-60 text-faint hover:text-main text-[11px]'
|
|
||||||
}`}
|
|
||||||
title="Menge bearbeiten"
|
|
||||||
>
|
|
||||||
{item.quantity ? `(${item.quantity})` : '+ Menge'}
|
|
||||||
</button>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ export const UserSettingsView: React.FC<UserSettingsViewProps> = ({
|
|||||||
const [newPassword, setNewPassword] = useState('');
|
const [newPassword, setNewPassword] = useState('');
|
||||||
const [profileMsg, setProfileMsg] = useState<{ type: 'ok' | 'err'; text: string } | null>(null);
|
const [profileMsg, setProfileMsg] = useState<{ type: 'ok' | 'err'; text: string } | null>(null);
|
||||||
const [savingProfile, setSavingProfile] = useState(false);
|
const [savingProfile, setSavingProfile] = useState(false);
|
||||||
const [revokingSessions, setRevokingSessions] = useState(false);
|
|
||||||
const [isProcessingAvatar, setIsProcessingAvatar] = useState(false);
|
const [isProcessingAvatar, setIsProcessingAvatar] = useState(false);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
@@ -156,21 +155,6 @@ export const UserSettingsView: React.FC<UserSettingsViewProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRevokeAllSessions = async () => {
|
|
||||||
if (!window.confirm('Möchtest du wirklich alle aktiven Sitzungen auf allen Geräten beenden? Du wirst dabei auch auf diesem Gerät abgemeldet.')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setRevokingSessions(true);
|
|
||||||
try {
|
|
||||||
await api.revokeAllSessions();
|
|
||||||
await api.logout();
|
|
||||||
window.location.reload();
|
|
||||||
} catch (err: any) {
|
|
||||||
setProfileMsg({ type: 'err', text: err.message || 'Fehler beim Beenden der Sitzungen' });
|
|
||||||
setRevokingSessions(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- Handlers: Alarms ---
|
// --- Handlers: Alarms ---
|
||||||
const handleSaveAlarms = async (e: React.FormEvent) => {
|
const handleSaveAlarms = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -546,32 +530,6 @@ export const UserSettingsView: React.FC<UserSettingsViewProps> = ({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{/* Sessions & Security */}
|
|
||||||
<div className="pt-5 border-t border-border space-y-3">
|
|
||||||
<div>
|
|
||||||
<h3 className="text-xs font-bold text-main">Aktive Sitzungen & Sicherheit</h3>
|
|
||||||
<p className="text-[11px] text-muted">
|
|
||||||
Sitzungen werden durch kryptografische JWTs geschützt. Bei einer Passwortänderung werden alle alten Sitzungen automatisch ungültig.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3 p-3.5 rounded-card border border-border bg-canvas">
|
|
||||||
<div className="text-xs">
|
|
||||||
<p className="font-semibold text-main">Alle Sitzungen sofort beenden</p>
|
|
||||||
<p className="text-[11px] text-faint">
|
|
||||||
Invalidiert alle ausgestellten Tokens auf allen Geräten und Browsern.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={handleRevokeAllSessions}
|
|
||||||
disabled={revokingSessions}
|
|
||||||
className="btn-danger h-8 px-3 text-xs shrink-0 cursor-pointer"
|
|
||||||
>
|
|
||||||
{revokingSessions ? 'Beende…' : 'Alle Sitzungen beenden'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,9 @@ import {
|
|||||||
ChevronRight,
|
ChevronRight,
|
||||||
Folder,
|
Folder,
|
||||||
Webhook,
|
Webhook,
|
||||||
Lock,
|
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { Thought, SubTask, TaskList, KanbanColumn } from '../../lib/types';
|
import { Thought, SubTask, TaskList, KanbanColumn } from '../../lib/types';
|
||||||
import { triggerHaptic } from '../../lib/api';
|
import { triggerHaptic } from '../../lib/api';
|
||||||
import { MarkdownViewer } from '../../lib/markdown';
|
|
||||||
|
|
||||||
interface TaskDetailModalProps {
|
interface TaskDetailModalProps {
|
||||||
task: Thought | null;
|
task: Thought | null;
|
||||||
@@ -38,9 +36,7 @@ interface TaskDetailModalProps {
|
|||||||
onAddSubtask: (task: Thought, title: string) => Promise<void>;
|
onAddSubtask: (task: Thought, title: string) => Promise<void>;
|
||||||
onDeleteSubtask: (task: Thought, subtaskId: string) => Promise<void>;
|
onDeleteSubtask: (task: Thought, subtaskId: string) => Promise<void>;
|
||||||
onConvertToDoc: (task: Thought) => void;
|
onConvertToDoc: (task: Thought) => void;
|
||||||
onOpenDocument?: (docId: string, blockId?: string) => void;
|
|
||||||
onDeleteTask: (taskId: string) => void;
|
onDeleteTask: (taskId: string) => void;
|
||||||
readOnly?: boolean; // Task belongs to a list shared with "viewer" permission
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
||||||
@@ -60,9 +56,7 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
onAddSubtask,
|
onAddSubtask,
|
||||||
onDeleteSubtask,
|
onDeleteSubtask,
|
||||||
onConvertToDoc,
|
onConvertToDoc,
|
||||||
onOpenDocument,
|
|
||||||
onDeleteTask,
|
onDeleteTask,
|
||||||
readOnly = false,
|
|
||||||
}) => {
|
}) => {
|
||||||
if (!isOpen || !task) return null;
|
if (!isOpen || !task) return null;
|
||||||
|
|
||||||
@@ -179,7 +173,6 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
<div className="flex items-center justify-between px-4 py-3 border-b border-border bg-panel">
|
<div className="flex items-center justify-between px-4 py-3 border-b border-border bg-panel">
|
||||||
<div className="flex items-center gap-2 min-w-0">
|
<div className="flex items-center gap-2 min-w-0">
|
||||||
<button
|
<button
|
||||||
disabled={readOnly}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
triggerHaptic(15);
|
triggerHaptic(15);
|
||||||
const nextState = !task.isCompleted;
|
const nextState = !task.isCompleted;
|
||||||
@@ -188,7 +181,7 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
const nextKanban = nextState ? (doneCol ? doneCol.id : 'done') : (todoCol ? todoCol.id : 'todo');
|
const nextKanban = nextState ? (doneCol ? doneCol.id : 'done') : (todoCol ? todoCol.id : 'todo');
|
||||||
onUpdateStatus(task, nextKanban);
|
onUpdateStatus(task, nextKanban);
|
||||||
}}
|
}}
|
||||||
className={`w-5 h-5 checkbox-square flex items-center justify-center flex-shrink-0 transition-colors border disabled:cursor-default ${
|
className={`w-5 h-5 checkbox-square flex items-center justify-center flex-shrink-0 transition-colors border ${
|
||||||
task.isCompleted
|
task.isCompleted
|
||||||
? 'bg-status-ok border-status-ok text-on-accent'
|
? 'bg-status-ok border-status-ok text-on-accent'
|
||||||
: 'border-strong hover:border-accent text-transparent'
|
: 'border-strong hover:border-accent text-transparent'
|
||||||
@@ -198,14 +191,8 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
<Check className="w-3.5 h-3.5 stroke-[3]" />
|
<Check className="w-3.5 h-3.5 stroke-[3]" />
|
||||||
</button>
|
</button>
|
||||||
<span className="text-xs font-semibold text-main truncate">
|
<span className="text-xs font-semibold text-main truncate">
|
||||||
{readOnly ? 'Aufgabe ansehen' : task.isCompleted ? 'Erledigte Aufgabe' : 'Aufgabe bearbeiten'}
|
{task.isCompleted ? 'Erledigte Aufgabe' : 'Aufgabe bearbeiten'}
|
||||||
</span>
|
</span>
|
||||||
{readOnly && (
|
|
||||||
<span className="px-1.5 py-0.5 border border-border bg-canvas text-muted rounded-btn text-[10px] font-medium flex items-center gap-1 flex-shrink-0">
|
|
||||||
<Lock className="w-2.5 h-2.5 text-faint" />
|
|
||||||
<span>Nur Lesen</span>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{task.source?.toLowerCase() === 'webhook' && (
|
{task.source?.toLowerCase() === 'webhook' && (
|
||||||
<span className="px-1.5 py-0.5 border border-border bg-canvas text-muted rounded-btn text-[10px] font-medium flex items-center gap-1 flex-shrink-0">
|
<span className="px-1.5 py-0.5 border border-border bg-canvas text-muted rounded-btn text-[10px] font-medium flex items-center gap-1 flex-shrink-0">
|
||||||
<Webhook className="w-2.5 h-2.5 text-accent" />
|
<Webhook className="w-2.5 h-2.5 text-accent" />
|
||||||
@@ -215,22 +202,6 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
{(task.convertedType === 'document_block' || task.docId) ? (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => {
|
|
||||||
onClose();
|
|
||||||
const docId = task.docId || (task.convertedRefId ? task.convertedRefId.split(':')[0] : '');
|
|
||||||
const blockId = task.blockId || (task.convertedRefId ? task.convertedRefId.split(':')[1] : '');
|
|
||||||
if (docId && onOpenDocument) onOpenDocument(docId, blockId);
|
|
||||||
}}
|
|
||||||
title="Zur verlinkten Notiz springen"
|
|
||||||
className="btn-primary min-h-[38px] sm:min-h-0 h-9 sm:h-7 px-2.5 sm:px-2 text-xs flex items-center gap-1.5 font-semibold"
|
|
||||||
>
|
|
||||||
<FileText className="w-4 h-4 sm:w-3.5 sm:h-3.5" />
|
|
||||||
<span>In Notiz öffnen</span>
|
|
||||||
</button>
|
|
||||||
) : !readOnly && (
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -243,8 +214,6 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
<FileText className="w-4 h-4 sm:w-3.5 sm:h-3.5 text-accent" />
|
<FileText className="w-4 h-4 sm:w-3.5 sm:h-3.5 text-accent" />
|
||||||
<span className="hidden sm:inline">Als Notiz vertiefen</span>
|
<span className="hidden sm:inline">Als Notiz vertiefen</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
|
||||||
{!readOnly && (
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -259,7 +228,6 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
<Trash2 className="w-4 h-4 sm:w-3.5 sm:h-3.5" />
|
<Trash2 className="w-4 h-4 sm:w-3.5 sm:h-3.5" />
|
||||||
<span className="sm:hidden font-medium">Löschen</span>
|
<span className="sm:hidden font-medium">Löschen</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
@@ -271,8 +239,8 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Scrollable Body (all controls disabled for read-only shares) */}
|
{/* Scrollable Body */}
|
||||||
<fieldset disabled={readOnly} className="p-4 overflow-y-auto space-y-4 flex-1 min-w-0 border-0 m-0">
|
<div className="p-4 overflow-y-auto space-y-4 flex-1">
|
||||||
{/* Task Title */}
|
{/* Task Title */}
|
||||||
<div>
|
<div>
|
||||||
{isEditingTitle ? (
|
{isEditingTitle ? (
|
||||||
@@ -315,11 +283,9 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<div
|
||||||
onClick={() => !readOnly && setIsEditingTitle(true)}
|
onClick={() => setIsEditingTitle(true)}
|
||||||
className={`group p-2 rounded-card transition-colors border border-transparent ${
|
className="group cursor-pointer p-2 rounded-card hover:bg-panel transition-colors border border-transparent hover:border-border"
|
||||||
readOnly ? '' : 'cursor-pointer hover:bg-panel hover:border-border'
|
title="Klicken zum Bearbeiten des Titels"
|
||||||
}`}
|
|
||||||
title={readOnly ? undefined : 'Klicken zum Bearbeiten des Titels'}
|
|
||||||
>
|
>
|
||||||
<h2
|
<h2
|
||||||
className={`text-base font-semibold break-words leading-snug ${
|
className={`text-base font-semibold break-words leading-snug ${
|
||||||
@@ -328,11 +294,9 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
>
|
>
|
||||||
{task.content}
|
{task.content}
|
||||||
</h2>
|
</h2>
|
||||||
{!readOnly && (
|
|
||||||
<span className="text-[10px] text-muted opacity-0 group-hover:opacity-100 transition-opacity">
|
<span className="text-[10px] text-muted opacity-0 group-hover:opacity-100 transition-opacity">
|
||||||
Klicken zum Umbenennen
|
Klicken zum Umbenennen
|
||||||
</span>
|
</span>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -531,7 +495,6 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
className="inline-flex items-center gap-1 px-2 py-0.5 rounded-pill bg-panel border border-border text-xs text-main"
|
className="inline-flex items-center gap-1 px-2 py-0.5 rounded-pill bg-panel border border-border text-xs text-main"
|
||||||
>
|
>
|
||||||
<span>#{tag}</span>
|
<span>#{tag}</span>
|
||||||
{!readOnly && (
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => handleRemoveTag(tag)}
|
onClick={() => handleRemoveTag(tag)}
|
||||||
@@ -539,10 +502,8 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
>
|
>
|
||||||
<X className="w-3 h-3" />
|
<X className="w-3 h-3" />
|
||||||
</button>
|
</button>
|
||||||
)}
|
|
||||||
</span>
|
</span>
|
||||||
))}
|
))}
|
||||||
{!readOnly && (
|
|
||||||
<form onSubmit={handleAddTagSubmit} className="inline-flex items-center gap-1">
|
<form onSubmit={handleAddTagSubmit} className="inline-flex items-center gap-1">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@@ -552,7 +513,6 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
className="h-6 w-24 px-1.5 text-xs input-field"
|
className="h-6 w-24 px-1.5 text-xs input-field"
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -607,7 +567,6 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
{st.title}
|
{st.title}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{!readOnly && (
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => onDeleteSubtask(task, st.id)}
|
onClick={() => onDeleteSubtask(task, st.id)}
|
||||||
@@ -615,14 +574,12 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
>
|
>
|
||||||
<Trash2 className="w-3 h-3" />
|
<Trash2 className="w-3 h-3" />
|
||||||
</button>
|
</button>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Inline add subtask form */}
|
{/* Inline add subtask form */}
|
||||||
{!readOnly && (
|
|
||||||
<form onSubmit={handleAddSubtaskSubmit} className="flex items-center gap-1.5">
|
<form onSubmit={handleAddSubtaskSubmit} className="flex items-center gap-1.5">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@@ -640,7 +597,6 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
<span>Hinzufügen</span>
|
<span>Hinzufügen</span>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Notes Section */}
|
{/* Notes Section */}
|
||||||
@@ -650,7 +606,7 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
<FileText className="w-3.5 h-3.5 text-accent" />
|
<FileText className="w-3.5 h-3.5 text-accent" />
|
||||||
<span>Detailnotizen:</span>
|
<span>Detailnotizen:</span>
|
||||||
</label>
|
</label>
|
||||||
{!readOnly && !isEditingNotes && task.notes && (
|
{!isEditingNotes && task.notes && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -697,19 +653,14 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
) : task.notes ? (
|
) : task.notes ? (
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (readOnly) return;
|
|
||||||
setNotesDraft(task.notes || '');
|
setNotesDraft(task.notes || '');
|
||||||
setIsEditingNotes(true);
|
setIsEditingNotes(true);
|
||||||
}}
|
}}
|
||||||
className={`p-3 bg-canvas border border-border rounded-card text-xs text-muted leading-relaxed transition-colors ${
|
className="p-3 bg-canvas border border-border rounded-card text-xs text-muted leading-relaxed whitespace-pre-wrap cursor-pointer hover:border-strong transition-colors"
|
||||||
readOnly ? '' : 'cursor-pointer hover:border-strong'
|
title="Klicken zum Bearbeiten"
|
||||||
}`}
|
|
||||||
title={readOnly ? undefined : 'Klicken zum Bearbeiten'}
|
|
||||||
>
|
>
|
||||||
<MarkdownViewer content={task.notes} />
|
{task.notes}
|
||||||
</div>
|
</div>
|
||||||
) : readOnly ? (
|
|
||||||
<p className="text-xs text-faint">Keine Detailnotizen.</p>
|
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -724,7 +675,7 @@ export const TaskDetailModal: React.FC<TaskDetailModalProps> = ({
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</div>
|
||||||
|
|
||||||
{/* Modal Footer */}
|
{/* Modal Footer */}
|
||||||
<div className="flex items-center justify-between px-4 py-2.5 border-t border-border bg-panel">
|
<div className="flex items-center justify-between px-4 py-2.5 border-t border-border bg-panel">
|
||||||
|
|||||||
@@ -46,9 +46,8 @@ const getInitials = (name?: string): string => {
|
|||||||
interface TasksViewProps {
|
interface TasksViewProps {
|
||||||
currentUser?: User | null;
|
currentUser?: User | null;
|
||||||
onRefreshStats: () => void;
|
onRefreshStats: () => void;
|
||||||
onOpenDocument: (docId: string, blockId?: string) => void;
|
onOpenDocument: (docId: string) => void;
|
||||||
refreshTrigger?: number;
|
refreshTrigger?: number;
|
||||||
initialSelectedTaskId?: string | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TasksView: React.FC<TasksViewProps> = ({
|
export const TasksView: React.FC<TasksViewProps> = ({
|
||||||
@@ -56,7 +55,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
onRefreshStats,
|
onRefreshStats,
|
||||||
onOpenDocument,
|
onOpenDocument,
|
||||||
refreshTrigger = 0,
|
refreshTrigger = 0,
|
||||||
initialSelectedTaskId,
|
|
||||||
}) => {
|
}) => {
|
||||||
const [viewMode, setViewMode] = useState<'list' | 'kanban'>('list');
|
const [viewMode, setViewMode] = useState<'list' | 'kanban'>('list');
|
||||||
const [filter, setFilter] = useState<'open' | 'done' | 'discarded'>('open');
|
const [filter, setFilter] = useState<'open' | 'done' | 'discarded'>('open');
|
||||||
@@ -103,18 +101,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
// Detail modal state
|
// Detail modal state
|
||||||
const [detailTaskId, setDetailTaskId] = useState<string | null>(null);
|
const [detailTaskId, setDetailTaskId] = useState<string | null>(null);
|
||||||
const [showDetailModal, setShowDetailModal] = useState(false);
|
const [showDetailModal, setShowDetailModal] = useState(false);
|
||||||
const [extraTask, setExtraTask] = useState<Thought | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (initialSelectedTaskId) {
|
|
||||||
setDetailTaskId(initialSelectedTaskId);
|
|
||||||
setShowDetailModal(true);
|
|
||||||
setFilter('open');
|
|
||||||
api.getThought(initialSelectedTaskId).then((th) => {
|
|
||||||
if (th) setExtraTask(th);
|
|
||||||
}).catch(() => {});
|
|
||||||
}
|
|
||||||
}, [initialSelectedTaskId]);
|
|
||||||
|
|
||||||
// Manage columns modal state
|
// Manage columns modal state
|
||||||
const [showManageColumnsModal, setShowManageColumnsModal] = useState(false);
|
const [showManageColumnsModal, setShowManageColumnsModal] = useState(false);
|
||||||
@@ -229,9 +215,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
|
|
||||||
const safeTaskLists = Array.isArray(taskLists) ? taskLists : [];
|
const safeTaskLists = Array.isArray(taskLists) ? taskLists : [];
|
||||||
const currentSelectedList = safeTaskLists.find((l) => l.id === selectedListId);
|
const currentSelectedList = safeTaskLists.find((l) => l.id === selectedListId);
|
||||||
const isSelectedListReadOnly = currentSelectedList?.permission === 'viewer';
|
|
||||||
const isTaskReadOnly = (task: Thought) =>
|
|
||||||
!!task.taskListId && safeTaskLists.find((l) => l.id === task.taskListId)?.permission === 'viewer';
|
|
||||||
|
|
||||||
// Active Kanban Columns (from selected list, or global custom, or default)
|
// Active Kanban Columns (from selected list, or global custom, or default)
|
||||||
const activeColumns: KanbanColumn[] = useMemo(() => {
|
const activeColumns: KanbanColumn[] = useMemo(() => {
|
||||||
@@ -260,8 +243,8 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
|
|
||||||
const detailTask = useMemo(() => {
|
const detailTask = useMemo(() => {
|
||||||
if (!detailTaskId) return null;
|
if (!detailTaskId) return null;
|
||||||
return tasks.find((t) => t.id === detailTaskId) || (extraTask?.id === detailTaskId ? extraTask : null);
|
return tasks.find((t) => t.id === detailTaskId) || null;
|
||||||
}, [detailTaskId, tasks, extraTask]);
|
}, [detailTaskId, tasks]);
|
||||||
|
|
||||||
const safeTeams = Array.isArray(teams) ? teams : [];
|
const safeTeams = Array.isArray(teams) ? teams : [];
|
||||||
const safeCollaborators = Array.isArray(collaborators) ? collaborators : [];
|
const safeCollaborators = Array.isArray(collaborators) ? collaborators : [];
|
||||||
@@ -605,10 +588,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
|
|
||||||
const handleTaskDragStart = (e: React.DragEvent, task: Thought) => {
|
const handleTaskDragStart = (e: React.DragEvent, task: Thought) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (isTaskReadOnly(task)) {
|
|
||||||
e.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
e.dataTransfer.setData('application/mindsift-task-id', task.id);
|
e.dataTransfer.setData('application/mindsift-task-id', task.id);
|
||||||
e.dataTransfer.setData('text/plain', task.id);
|
e.dataTransfer.setData('text/plain', task.id);
|
||||||
e.dataTransfer.effectAllowed = 'move';
|
e.dataTransfer.effectAllowed = 'move';
|
||||||
@@ -872,7 +851,7 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPrimaryAction(() => {
|
setPrimaryAction(() => {
|
||||||
setMobileCreateListId(selectedListId === 'all' || isSelectedListReadOnly ? '' : selectedListId);
|
setMobileCreateListId(selectedListId === 'all' ? '' : selectedListId);
|
||||||
setShowMobileCreateModal(true);
|
setShowMobileCreateModal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -883,7 +862,7 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
icon: <Plus className="w-4 h-4" />,
|
icon: <Plus className="w-4 h-4" />,
|
||||||
variant: 'accent',
|
variant: 'accent',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setMobileCreateListId(selectedListId === 'all' || isSelectedListReadOnly ? '' : selectedListId);
|
setMobileCreateListId(selectedListId === 'all' ? '' : selectedListId);
|
||||||
setShowMobileCreateModal(true);
|
setShowMobileCreateModal(true);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -972,7 +951,7 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (viewMode === 'kanban' && !isSelectedListReadOnly) {
|
if (viewMode === 'kanban') {
|
||||||
viewItems.push({
|
viewItems.push({
|
||||||
id: 'manage-columns',
|
id: 'manage-columns',
|
||||||
label: 'Kanban-Spalten verwalten',
|
label: 'Kanban-Spalten verwalten',
|
||||||
@@ -1037,7 +1016,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
kanbanTasks.length,
|
kanbanTasks.length,
|
||||||
safeTaskLists,
|
safeTaskLists,
|
||||||
currentSelectedList,
|
currentSelectedList,
|
||||||
isSelectedListReadOnly,
|
|
||||||
setPrimaryAction,
|
setPrimaryAction,
|
||||||
setGroups,
|
setGroups,
|
||||||
]);
|
]);
|
||||||
@@ -1079,14 +1057,13 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
// Clean Task Row in List View
|
// Clean Task Row in List View
|
||||||
const renderTaskRow = (task: Thought) => {
|
const renderTaskRow = (task: Thought) => {
|
||||||
const isCompleted = task.isCompleted;
|
const isCompleted = task.isCompleted;
|
||||||
const readOnly = isTaskReadOnly(task);
|
|
||||||
const isDragging = draggingTaskId === task.id;
|
const isDragging = draggingTaskId === task.id;
|
||||||
const isTarget = dragOverTaskTarget?.taskId === task.id;
|
const isTarget = dragOverTaskTarget?.taskId === task.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={task.id}
|
key={task.id}
|
||||||
draggable={!readOnly}
|
draggable
|
||||||
onDragStart={(e) => handleTaskDragStart(e, task)}
|
onDragStart={(e) => handleTaskDragStart(e, task)}
|
||||||
onDragEnd={() => {
|
onDragEnd={() => {
|
||||||
setDraggingTaskId(null);
|
setDraggingTaskId(null);
|
||||||
@@ -1100,9 +1077,7 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
setDetailTaskId(task.id);
|
setDetailTaskId(task.id);
|
||||||
setShowDetailModal(true);
|
setShowDetailModal(true);
|
||||||
}}
|
}}
|
||||||
className={`px-3.5 py-3.5 sm:px-3 sm:py-2.5 flex items-center justify-between gap-3 transition-colors hover:bg-panel-hover group border-b border-border last:border-b-0 relative cursor-pointer select-none ${
|
className={`px-3.5 py-3.5 sm:px-3 sm:py-2.5 flex items-center justify-between gap-3 transition-colors hover:bg-panel-hover group border-b border-border last:border-b-0 relative cursor-pointer cursor-grab active:cursor-grabbing select-none ${
|
||||||
readOnly ? '' : 'cursor-grab active:cursor-grabbing'
|
|
||||||
} ${
|
|
||||||
isCompleted ? 'opacity-65' : ''
|
isCompleted ? 'opacity-65' : ''
|
||||||
} ${isDragging ? 'opacity-30 border border-dashed border-accent/40' : ''}`}
|
} ${isDragging ? 'opacity-30 border border-dashed border-accent/40' : ''}`}
|
||||||
>
|
>
|
||||||
@@ -1119,18 +1094,17 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
draggable={false}
|
draggable={false}
|
||||||
disabled={readOnly}
|
|
||||||
onMouseDown={(e) => e.stopPropagation()}
|
onMouseDown={(e) => e.stopPropagation()}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
handleToggleDone(task);
|
handleToggleDone(task);
|
||||||
}}
|
}}
|
||||||
className={`w-5 h-5 sm:w-4 sm:h-4 checkbox-square flex items-center justify-center flex-shrink-0 transition-colors border disabled:cursor-default ${
|
className={`w-5 h-5 sm:w-4 sm:h-4 checkbox-square flex items-center justify-center flex-shrink-0 transition-colors border ${
|
||||||
isCompleted
|
isCompleted
|
||||||
? 'bg-status-ok border-status-ok text-on-accent'
|
? 'bg-status-ok border-status-ok text-on-accent'
|
||||||
: 'border-strong hover:border-accent text-transparent'
|
: 'border-strong hover:border-accent text-transparent'
|
||||||
}`}
|
}`}
|
||||||
title={readOnly ? 'Nur Lesen' : isCompleted ? 'Als offen markieren' : 'Als erledigt abhaken'}
|
title={isCompleted ? 'Als offen markieren' : 'Als erledigt abhaken'}
|
||||||
>
|
>
|
||||||
<Check className="w-3.5 h-3.5 sm:w-3 sm:h-3 stroke-[3]" />
|
<Check className="w-3.5 h-3.5 sm:w-3 sm:h-3 stroke-[3]" />
|
||||||
</button>
|
</button>
|
||||||
@@ -1161,27 +1135,9 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
className="flex flex-wrap items-center gap-1.5 pt-0.5 empty:hidden"
|
className="flex flex-wrap items-center gap-1.5 pt-0.5 empty:hidden"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
{(task.convertedType === 'document_block' || task.docId) && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
const docId = task.docId || (task.convertedRefId ? task.convertedRefId.split(':')[0] : '');
|
|
||||||
const blockId = task.blockId || (task.convertedRefId ? task.convertedRefId.split(':')[1] : '');
|
|
||||||
if (docId) onOpenDocument(docId, blockId);
|
|
||||||
}}
|
|
||||||
className="h-5 px-1.5 text-[10px] rounded-btn border border-accent/40 bg-accent/10 text-accent hover:bg-accent/20 cursor-pointer flex items-center gap-1 font-medium"
|
|
||||||
title="In Notiz an der passenden Stelle öffnen"
|
|
||||||
>
|
|
||||||
<FileText className="w-2.5 h-2.5" />
|
|
||||||
<span>In Notiz</span>
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Kanban status selector pill (Desktop only - on mobile done via TaskDetailModal) */}
|
{/* Kanban status selector pill (Desktop only - on mobile done via TaskDetailModal) */}
|
||||||
<select
|
<select
|
||||||
value={task.kanbanStatus || (isCompleted ? 'done' : 'todo')}
|
value={task.kanbanStatus || (isCompleted ? 'done' : 'todo')}
|
||||||
disabled={readOnly}
|
|
||||||
onChange={(e) => handleSetKanbanStatus(task, e.target.value)}
|
onChange={(e) => handleSetKanbanStatus(task, e.target.value)}
|
||||||
className="hidden sm:inline-block h-5 px-1.5 text-[10px] rounded-btn border border-border bg-panel text-muted hover:text-main cursor-pointer"
|
className="hidden sm:inline-block h-5 px-1.5 text-[10px] rounded-btn border border-border bg-panel text-muted hover:text-main cursor-pointer"
|
||||||
title="Status / Zustand ändern"
|
title="Status / Zustand ändern"
|
||||||
@@ -1197,9 +1153,8 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
{task.priority === 'urgent' && (
|
{task.priority === 'urgent' && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={readOnly}
|
|
||||||
onClick={() => handleCyclePriority(task)}
|
onClick={() => handleCyclePriority(task)}
|
||||||
className="badge-accent text-[10px] cursor-pointer hover:opacity-85 disabled:cursor-default"
|
className="badge-accent text-[10px] cursor-pointer hover:opacity-85"
|
||||||
title="Klicken zum Ändern der Priorität (Dringend -> Normal)"
|
title="Klicken zum Ändern der Priorität (Dringend -> Normal)"
|
||||||
>
|
>
|
||||||
🔥 Dringend
|
🔥 Dringend
|
||||||
@@ -1208,9 +1163,8 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
{task.priority === 'high' && (
|
{task.priority === 'high' && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={readOnly}
|
|
||||||
onClick={() => handleCyclePriority(task)}
|
onClick={() => handleCyclePriority(task)}
|
||||||
className="px-1.5 py-0.5 border border-status-warn text-status-warn rounded-btn text-[10px] font-medium cursor-pointer hover:opacity-85 disabled:cursor-default"
|
className="px-1.5 py-0.5 border border-status-warn text-status-warn rounded-btn text-[10px] font-medium cursor-pointer hover:opacity-85"
|
||||||
title="Klicken zum Ändern der Priorität (Wichtig -> Dringend)"
|
title="Klicken zum Ändern der Priorität (Wichtig -> Dringend)"
|
||||||
>
|
>
|
||||||
⚠️ Wichtig
|
⚠️ Wichtig
|
||||||
@@ -1281,12 +1235,10 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
setShowDetailModal(true);
|
setShowDetailModal(true);
|
||||||
}}
|
}}
|
||||||
className="text-faint hover:text-accent p-1.5 transition-colors"
|
className="text-faint hover:text-accent p-1.5 transition-colors"
|
||||||
title={readOnly ? 'Aufgabe ansehen' : 'Aufgabe bearbeiten'}
|
title="Aufgabe bearbeiten"
|
||||||
>
|
>
|
||||||
{readOnly ? <Lock className="w-3.5 h-3.5" /> : <Edit3 className="w-3.5 h-3.5" />}
|
<Edit3 className="w-3.5 h-3.5" />
|
||||||
</button>
|
</button>
|
||||||
{!readOnly && (
|
|
||||||
<>
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
draggable={false}
|
draggable={false}
|
||||||
@@ -1305,8 +1257,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
>
|
>
|
||||||
<Trash2 className="w-3.5 h-3.5" />
|
<Trash2 className="w-3.5 h-3.5" />
|
||||||
</button>
|
</button>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -1314,8 +1264,36 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full space-y-3">
|
<div className="w-full space-y-3">
|
||||||
|
{/* Mobile Compact Context Bar (replaces cluttered button rows; options live in MindSift Logo Menu) */}
|
||||||
|
<div className="flex sm:hidden items-center justify-between gap-2 px-3 py-2 rounded-btn bg-panel border border-border">
|
||||||
|
<div className="flex items-center gap-2 min-w-0">
|
||||||
|
<span className="text-sm font-semibold text-main truncate">
|
||||||
|
{currentSelectedList ? `${currentSelectedList.icon} ${currentSelectedList.title}` : '📋 Alle Aufgaben'}
|
||||||
|
</span>
|
||||||
|
<span className="badge-neutral text-[11px] flex-shrink-0">
|
||||||
|
{viewMode === 'kanban'
|
||||||
|
? 'Kanban'
|
||||||
|
: filter === 'open'
|
||||||
|
? `Offen (${openTasks.length})`
|
||||||
|
: filter === 'done'
|
||||||
|
? `Erledigt (${doneTasks.length})`
|
||||||
|
: `Papierkorb (${safeDiscarded.length})`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{currentSelectedList && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleOpenShareModal(currentSelectedList)}
|
||||||
|
className="btn-icon min-h-[36px] min-w-[36px] flex items-center justify-center flex-shrink-0"
|
||||||
|
title="Aufgabenliste teilen"
|
||||||
|
>
|
||||||
|
<Users className="w-4 h-4 text-accent" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Top Header: Task Lists Tabs & View Mode Switcher (Desktop) */}
|
{/* Top Header: Task Lists Tabs & View Mode Switcher (Desktop) */}
|
||||||
<div className="hidden sm:flex flex-wrap items-center justify-between gap-2 border-b border-border pb-2 !mt-0">
|
<div className="hidden sm:flex flex-wrap items-center justify-between gap-2 border-b border-border pb-2">
|
||||||
{/* Task Lists selector tabs */}
|
{/* Task Lists selector tabs */}
|
||||||
<div className="flex flex-wrap items-center gap-1">
|
<div className="flex flex-wrap items-center gap-1">
|
||||||
<button
|
<button
|
||||||
@@ -1470,45 +1448,7 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mobile Compact Context Bar (replaces cluttered button rows; options live in MindSift Logo Menu) */}
|
|
||||||
<div className="flex sm:hidden items-center justify-between gap-2 px-3 py-2 rounded-btn bg-panel border border-border !mt-0">
|
|
||||||
<div className="flex items-center gap-2 min-w-0">
|
|
||||||
<span className="text-sm font-semibold text-main truncate">
|
|
||||||
{currentSelectedList ? `${currentSelectedList.icon} ${currentSelectedList.title}` : '📋 Alle Aufgaben'}
|
|
||||||
</span>
|
|
||||||
<span className="badge-neutral text-[11px] flex-shrink-0">
|
|
||||||
{viewMode === 'kanban'
|
|
||||||
? 'Kanban'
|
|
||||||
: filter === 'open'
|
|
||||||
? `Offen (${openTasks.length})`
|
|
||||||
: filter === 'done'
|
|
||||||
? `Erledigt (${doneTasks.length})`
|
|
||||||
: `Papierkorb (${safeDiscarded.length})`}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{currentSelectedList && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleOpenShareModal(currentSelectedList)}
|
|
||||||
className="btn-icon min-h-[36px] min-w-[36px] flex items-center justify-center flex-shrink-0"
|
|
||||||
title="Aufgabenliste teilen"
|
|
||||||
>
|
|
||||||
<Users className="w-4 h-4 text-accent" />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{isSelectedListReadOnly && (
|
|
||||||
<div className="flex items-center gap-2 p-2.5 rounded-btn bg-panel-elevated border border-border text-xs text-muted">
|
|
||||||
<Lock className="w-3.5 h-3.5 text-faint shrink-0" />
|
|
||||||
<span>
|
|
||||||
Diese Liste wurde von {currentSelectedList?.ownerName || 'einem anderen Benutzer'} nur zum Lesen freigegeben.
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Quick Add Task Input (Desktop only - on mobile, tapping the bottom '+' FAB opens mobile create sheet) */}
|
{/* Quick Add Task Input (Desktop only - on mobile, tapping the bottom '+' FAB opens mobile create sheet) */}
|
||||||
{!isSelectedListReadOnly && (
|
|
||||||
<form
|
<form
|
||||||
onSubmit={handleQuickAddTask}
|
onSubmit={handleQuickAddTask}
|
||||||
className="hidden sm:flex items-center gap-1.5 panel-surface p-2 sm:p-1.5"
|
className="hidden sm:flex items-center gap-1.5 panel-surface p-2 sm:p-1.5"
|
||||||
@@ -1543,7 +1483,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Mobile Active Filter Badge Banner (minimal and clean) */}
|
{/* Mobile Active Filter Badge Banner (minimal and clean) */}
|
||||||
{(selectedTag || groupBy !== 'none' || sortBy !== 'custom') && (
|
{(selectedTag || groupBy !== 'none' || sortBy !== 'custom') && (
|
||||||
@@ -1628,7 +1567,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
{/* Group By & Sort By Dropdowns & Manage Columns button */}
|
{/* Group By & Sort By Dropdowns & Manage Columns button */}
|
||||||
<div className="flex items-center gap-2 flex-shrink-0 ml-auto">
|
<div className="flex items-center gap-2 flex-shrink-0 ml-auto">
|
||||||
{viewMode === 'kanban' ? (
|
{viewMode === 'kanban' ? (
|
||||||
!isSelectedListReadOnly && (
|
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowManageColumnsModal(true)}
|
onClick={() => setShowManageColumnsModal(true)}
|
||||||
className="btn-action h-7 px-2.5 text-xs flex items-center gap-1.5"
|
className="btn-action h-7 px-2.5 text-xs flex items-center gap-1.5"
|
||||||
@@ -1637,7 +1575,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
<Columns className="w-3.5 h-3.5 text-accent" />
|
<Columns className="w-3.5 h-3.5 text-accent" />
|
||||||
<span>Spalten anpassen</span>
|
<span>Spalten anpassen</span>
|
||||||
</button>
|
</button>
|
||||||
)
|
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{/* Group By */}
|
{/* Group By */}
|
||||||
@@ -2034,17 +1971,17 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
targetName: sh.targetName || (sh.targetType === 'team' ? 'Gruppe' : sh.email || 'Benutzer'),
|
targetName: sh.targetName || (sh.targetType === 'team' ? 'Gruppe' : sh.email || 'Benutzer'),
|
||||||
targetEmail: sh.email,
|
targetEmail: sh.email,
|
||||||
avatarUrl: sh.avatarUrl,
|
avatarUrl: sh.avatarUrl,
|
||||||
permission: sh.permission === 'viewer' ? 'viewer' as const : 'editor' as const,
|
permission: 'editor' as const,
|
||||||
role: sh.permission === 'viewer' ? 'viewer' : 'editor',
|
role: 'editor',
|
||||||
createdAt: sh.createdAt,
|
createdAt: sh.createdAt,
|
||||||
}))}
|
}))}
|
||||||
teams={safeTeams}
|
teams={safeTeams}
|
||||||
collaborators={safeCollaborators}
|
collaborators={safeCollaborators}
|
||||||
onAddShare={async (targetType, targetId, permission) => {
|
allowRoleSelection={false}
|
||||||
|
onAddShare={async (targetType, targetId) => {
|
||||||
await api.addTaskListShare(sharingTaskList.id, {
|
await api.addTaskListShare(sharingTaskList.id, {
|
||||||
targetType,
|
targetType,
|
||||||
targetId,
|
targetId,
|
||||||
permission,
|
|
||||||
});
|
});
|
||||||
const [freshLists, freshShares] = await Promise.all([
|
const [freshLists, freshShares] = await Promise.all([
|
||||||
api.getTaskLists(),
|
api.getTaskLists(),
|
||||||
@@ -2092,7 +2029,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
}}
|
}}
|
||||||
activeColumns={activeColumns}
|
activeColumns={activeColumns}
|
||||||
taskLists={safeTaskLists}
|
taskLists={safeTaskLists}
|
||||||
onOpenDocument={onOpenDocument}
|
|
||||||
onUpdateTitle={handleUpdateTaskTitle}
|
onUpdateTitle={handleUpdateTaskTitle}
|
||||||
onUpdateStatus={handleSetKanbanStatus}
|
onUpdateStatus={handleSetKanbanStatus}
|
||||||
onUpdatePriority={handleSetPriority}
|
onUpdatePriority={handleSetPriority}
|
||||||
@@ -2105,7 +2041,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
onDeleteSubtask={handleDeleteSubtask}
|
onDeleteSubtask={handleDeleteSubtask}
|
||||||
onConvertToDoc={handleConvertToDoc}
|
onConvertToDoc={handleConvertToDoc}
|
||||||
onDeleteTask={handleDeletePermanent}
|
onDeleteTask={handleDeletePermanent}
|
||||||
readOnly={detailTask ? isTaskReadOnly(detailTask) : false}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* VIEW MODES: LIST OR KANBAN */}
|
{/* VIEW MODES: LIST OR KANBAN */}
|
||||||
@@ -2162,12 +2097,11 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
{colTasks.map((task) => {
|
{colTasks.map((task) => {
|
||||||
const isDragging = draggingTaskId === task.id;
|
const isDragging = draggingTaskId === task.id;
|
||||||
const isTarget = dragOverTaskTarget?.taskId === task.id;
|
const isTarget = dragOverTaskTarget?.taskId === task.id;
|
||||||
const readOnly = isTaskReadOnly(task);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={task.id}
|
key={task.id}
|
||||||
draggable={!readOnly}
|
draggable
|
||||||
onDragStart={(e) => handleTaskDragStart(e, task)}
|
onDragStart={(e) => handleTaskDragStart(e, task)}
|
||||||
onDragEnd={() => {
|
onDragEnd={() => {
|
||||||
setDraggingTaskId(null);
|
setDraggingTaskId(null);
|
||||||
@@ -2181,9 +2115,7 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
setDetailTaskId(task.id);
|
setDetailTaskId(task.id);
|
||||||
setShowDetailModal(true);
|
setShowDetailModal(true);
|
||||||
}}
|
}}
|
||||||
className={`panel-surface p-2.5 space-y-2 hover:border-strong transition-all shadow-sm group relative ${
|
className={`panel-surface p-2.5 space-y-2 hover:border-strong transition-all cursor-grab active:cursor-grabbing shadow-sm group relative ${
|
||||||
readOnly ? 'cursor-pointer' : 'cursor-grab active:cursor-grabbing'
|
|
||||||
} ${
|
|
||||||
isDragging ? 'opacity-30 border border-dashed border-accent/40' : ''
|
isDragging ? 'opacity-30 border border-dashed border-accent/40' : ''
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
@@ -2202,7 +2134,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
>
|
>
|
||||||
{task.content}
|
{task.content}
|
||||||
</p>
|
</p>
|
||||||
{!readOnly && (
|
|
||||||
<div className="hidden sm:flex items-center gap-1 flex-shrink-0" onClick={(e) => e.stopPropagation()}>
|
<div className="hidden sm:flex items-center gap-1 flex-shrink-0" onClick={(e) => e.stopPropagation()}>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleConvertToDoc(task)}
|
onClick={() => handleConvertToDoc(task)}
|
||||||
@@ -2219,7 +2150,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
<Trash2 className="w-3 h-3" />
|
<Trash2 className="w-3 h-3" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Subtasks progress */}
|
{/* Subtasks progress */}
|
||||||
@@ -2233,30 +2163,13 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Badges: In Notiz, Priority, Status, Tags */}
|
{/* Badges: Priority, Status, Tags */}
|
||||||
<div className="flex flex-wrap items-center gap-1 pt-0.5" onClick={(e) => e.stopPropagation()}>
|
<div className="flex flex-wrap items-center gap-1 pt-0.5" onClick={(e) => e.stopPropagation()}>
|
||||||
{(task.convertedType === 'document_block' || task.docId) && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
const docId = task.docId || (task.convertedRefId ? task.convertedRefId.split(':')[0] : '');
|
|
||||||
const blockId = task.blockId || (task.convertedRefId ? task.convertedRefId.split(':')[1] : '');
|
|
||||||
if (docId) onOpenDocument(docId, blockId);
|
|
||||||
}}
|
|
||||||
className="h-4 px-1.5 text-[9px] rounded-btn border border-accent/40 bg-accent/10 text-accent hover:bg-accent/20 cursor-pointer flex items-center gap-1 font-medium shrink-0"
|
|
||||||
title="In Notiz an der passenden Stelle öffnen"
|
|
||||||
>
|
|
||||||
<FileText className="w-2.5 h-2.5" />
|
|
||||||
<span>In Notiz</span>
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
{task.priority === 'urgent' && (
|
{task.priority === 'urgent' && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={readOnly}
|
|
||||||
onClick={() => handleCyclePriority(task)}
|
onClick={() => handleCyclePriority(task)}
|
||||||
className="badge-accent text-[9px] cursor-pointer hover:opacity-85 disabled:cursor-default"
|
className="badge-accent text-[9px] cursor-pointer hover:opacity-85"
|
||||||
title="Klicken zum Ändern der Priorität (Dringend -> Normal)"
|
title="Klicken zum Ändern der Priorität (Dringend -> Normal)"
|
||||||
>
|
>
|
||||||
🔥 Dringend
|
🔥 Dringend
|
||||||
@@ -2265,9 +2178,8 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
{task.priority === 'high' && (
|
{task.priority === 'high' && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={readOnly}
|
|
||||||
onClick={() => handleCyclePriority(task)}
|
onClick={() => handleCyclePriority(task)}
|
||||||
className="px-1.5 py-0.2 border border-status-warn text-status-warn rounded-btn text-[9px] font-medium cursor-pointer hover:opacity-85 disabled:cursor-default"
|
className="px-1.5 py-0.2 border border-status-warn text-status-warn rounded-btn text-[9px] font-medium cursor-pointer hover:opacity-85"
|
||||||
title="Klicken zum Ändern der Priorität (Wichtig -> Dringend)"
|
title="Klicken zum Ändern der Priorität (Wichtig -> Dringend)"
|
||||||
>
|
>
|
||||||
⚠️ Wichtig
|
⚠️ Wichtig
|
||||||
@@ -2305,7 +2217,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Column Navigation controls: Move Left / Move Right */}
|
{/* Column Navigation controls: Move Left / Move Right */}
|
||||||
{!readOnly && (
|
|
||||||
<div
|
<div
|
||||||
className="flex items-center justify-between pt-1 border-t border-border text-[10px]"
|
className="flex items-center justify-between pt-1 border-t border-border text-[10px]"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
@@ -2332,7 +2243,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
<ArrowRight className="w-3 h-3" />
|
<ArrowRight className="w-3 h-3" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -2345,7 +2255,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Quick Add Task to Column */}
|
{/* Quick Add Task to Column */}
|
||||||
{!isSelectedListReadOnly && (
|
|
||||||
<div className="p-2 border-t border-border bg-panel">
|
<div className="p-2 border-t border-border bg-panel">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -2356,7 +2265,6 @@ export const TasksView: React.FC<TasksViewProps> = ({
|
|||||||
<span>Aufgabe hinzufügen</span>
|
<span>Aufgabe hinzufügen</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -1,308 +0,0 @@
|
|||||||
import React, { useState, useEffect, useMemo, useRef } from 'react';
|
|
||||||
import {
|
|
||||||
Link as LinkIcon,
|
|
||||||
FileText,
|
|
||||||
Globe,
|
|
||||||
X,
|
|
||||||
Search,
|
|
||||||
ExternalLink,
|
|
||||||
Loader2,
|
|
||||||
Plus,
|
|
||||||
} from 'lucide-react';
|
|
||||||
import { api } from '../../lib/api';
|
|
||||||
import { Document } from '../../lib/types';
|
|
||||||
|
|
||||||
export interface LinkModalProps {
|
|
||||||
isOpen: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
onInsertLink: (markdown: string) => void;
|
|
||||||
availableDocs?: { id: string; title: string; icon?: string; folderPath?: string }[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export const LinkModal: React.FC<LinkModalProps> = ({
|
|
||||||
isOpen,
|
|
||||||
onClose,
|
|
||||||
onInsertLink,
|
|
||||||
availableDocs,
|
|
||||||
}) => {
|
|
||||||
const [tab, setTab] = useState<'note' | 'web'>('note');
|
|
||||||
const [search, setSearch] = useState('');
|
|
||||||
const [docs, setDocs] = useState<Document[]>([]);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
const [webTitle, setWebTitle] = useState('');
|
|
||||||
const [webUrl, setWebUrl] = useState('');
|
|
||||||
|
|
||||||
const searchInputRef = useRef<HTMLInputElement | null>(null);
|
|
||||||
const webTitleInputRef = useRef<HTMLInputElement | null>(null);
|
|
||||||
|
|
||||||
// Load documents when modal opens
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isOpen) return;
|
|
||||||
if (availableDocs && availableDocs.length > 0) {
|
|
||||||
setDocs(availableDocs as Document[]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let isCancelled = false;
|
|
||||||
setLoading(true);
|
|
||||||
api
|
|
||||||
.getDocuments()
|
|
||||||
.then((fetched) => {
|
|
||||||
if (!isCancelled) {
|
|
||||||
setDocs(fetched);
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
if (!isCancelled) {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
isCancelled = true;
|
|
||||||
};
|
|
||||||
}, [isOpen, availableDocs]);
|
|
||||||
|
|
||||||
// Focus input on mount or tab change
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isOpen) return;
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
if (tab === 'note') {
|
|
||||||
searchInputRef.current?.focus();
|
|
||||||
} else {
|
|
||||||
webTitleInputRef.current?.focus();
|
|
||||||
}
|
|
||||||
}, 50);
|
|
||||||
return () => clearTimeout(timer);
|
|
||||||
}, [isOpen, tab]);
|
|
||||||
|
|
||||||
// Close on Escape
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isOpen) return;
|
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
|
||||||
if (e.key === 'Escape') {
|
|
||||||
e.preventDefault();
|
|
||||||
onClose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
window.addEventListener('keydown', handleKeyDown);
|
|
||||||
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
||||||
}, [isOpen, onClose]);
|
|
||||||
|
|
||||||
const filteredDocs = useMemo(() => {
|
|
||||||
if (!search.trim()) return docs;
|
|
||||||
const q = search.toLowerCase();
|
|
||||||
return docs.filter(
|
|
||||||
(d) =>
|
|
||||||
d.title.toLowerCase().includes(q) ||
|
|
||||||
(d.folderPath && d.folderPath.toLowerCase().includes(q))
|
|
||||||
);
|
|
||||||
}, [docs, search]);
|
|
||||||
|
|
||||||
const handleSelectNote = (doc: { title: string }) => {
|
|
||||||
const noteTitle = doc.title.trim() || 'Notiz';
|
|
||||||
onInsertLink(`[[${noteTitle}]]`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleWebLinkSubmit = (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
let url = webUrl.trim();
|
|
||||||
if (!url) return;
|
|
||||||
if (!/^https?:\/\//i.test(url) && !url.startsWith('#') && !url.startsWith('/')) {
|
|
||||||
url = `https://${url}`;
|
|
||||||
}
|
|
||||||
const label = webTitle.trim() || url;
|
|
||||||
onInsertLink(`[${label}](${url})`);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!isOpen) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="fixed inset-0 !m-0 modal-overlay z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-xs"
|
|
||||||
onClick={(e) => {
|
|
||||||
if (e.target === e.currentTarget) onClose();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div className="panel-surface w-full max-w-lg p-5 shadow-panel rounded-card border border-border space-y-4 animate-in fade-in zoom-in-95 duration-150">
|
|
||||||
{/* Header - identical to UnifiedShareModal */}
|
|
||||||
<div className="flex items-center justify-between pb-3 border-b border-border">
|
|
||||||
<div className="flex items-center gap-2.5 min-w-0">
|
|
||||||
<div className="w-8 h-8 rounded-btn bg-accent/15 text-accent flex items-center justify-center shrink-0">
|
|
||||||
<LinkIcon className="w-4 h-4" />
|
|
||||||
</div>
|
|
||||||
<div className="min-w-0">
|
|
||||||
<h3 className="text-sm font-bold text-main truncate">Link einfügen</h3>
|
|
||||||
<p className="text-[11px] text-muted truncate">
|
|
||||||
Notiz intern verknüpfen oder externen Web-Link einbetten
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onClose}
|
|
||||||
className="p-1.5 text-muted hover:text-main rounded-btn hover:bg-panel transition-colors cursor-pointer"
|
|
||||||
title="Schließen"
|
|
||||||
>
|
|
||||||
<X className="w-4 h-4" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Control Box - matching UnifiedShareModal form header */}
|
|
||||||
<div className="space-y-3 p-3 bg-panel-elevated border border-border rounded-card">
|
|
||||||
<div className="flex items-center justify-between gap-2">
|
|
||||||
<span className="text-xs font-semibold text-main">Link-Typ:</span>
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setTab('note')}
|
|
||||||
className={`h-7 px-2.5 text-xs rounded-btn font-medium flex items-center gap-1.5 border transition-colors cursor-pointer ${
|
|
||||||
tab === 'note'
|
|
||||||
? 'bg-panel border-accent text-accent font-semibold shadow-xs'
|
|
||||||
: 'bg-canvas border-border text-muted hover:text-main'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<FileText className="w-3.5 h-3.5" />
|
|
||||||
<span>Notiz</span>
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setTab('web')}
|
|
||||||
className={`h-7 px-2.5 text-xs rounded-btn font-medium flex items-center gap-1.5 border transition-colors cursor-pointer ${
|
|
||||||
tab === 'web'
|
|
||||||
? 'bg-panel border-accent text-accent font-semibold shadow-xs'
|
|
||||||
: 'bg-canvas border-border text-muted hover:text-main'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<Globe className="w-3.5 h-3.5" />
|
|
||||||
<span>Web-Link</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{tab === 'note' ? (
|
|
||||||
<div className="relative">
|
|
||||||
<Search className="w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted pointer-events-none" />
|
|
||||||
<input
|
|
||||||
ref={searchInputRef}
|
|
||||||
type="text"
|
|
||||||
value={search}
|
|
||||||
onChange={(e) => setSearch(e.target.value)}
|
|
||||||
placeholder="Notiz suchen (Titel oder Ordner)…"
|
|
||||||
className="input-field bg-panel h-8 pl-8 pr-2.5 text-xs w-full text-main placeholder:text-muted"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<form onSubmit={handleWebLinkSubmit} className="space-y-2.5">
|
|
||||||
<div>
|
|
||||||
<label className="text-[10px] font-bold uppercase tracking-wider text-faint mb-1 block">
|
|
||||||
Link-Text / Label
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
ref={webTitleInputRef}
|
|
||||||
type="text"
|
|
||||||
value={webTitle}
|
|
||||||
onChange={(e) => setWebTitle(e.target.value)}
|
|
||||||
placeholder="z. B. MindSift Dokumentation"
|
|
||||||
className="input-field bg-panel h-8 px-2.5 text-xs w-full text-main placeholder:text-muted"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="text-[10px] font-bold uppercase tracking-wider text-faint mb-1 block">
|
|
||||||
Web-Adresse (URL) *
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
required
|
|
||||||
value={webUrl}
|
|
||||||
onChange={(e) => setWebUrl(e.target.value)}
|
|
||||||
placeholder="https://example.com"
|
|
||||||
className="input-field bg-panel h-8 px-2.5 text-xs w-full text-main placeholder:text-muted"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex justify-end gap-2 pt-1">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onClose}
|
|
||||||
className="btn-action text-xs h-8 px-3.5 cursor-pointer"
|
|
||||||
>
|
|
||||||
Abbrechen
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={!webUrl.trim()}
|
|
||||||
className="btn-primary text-xs h-8 px-3.5 flex items-center gap-1.5 cursor-pointer disabled:opacity-50"
|
|
||||||
>
|
|
||||||
<Plus className="w-3.5 h-3.5" />
|
|
||||||
<span>Link einfügen</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Note List Section (Matching Active Shares list in UnifiedShareModal) */}
|
|
||||||
{tab === 'note' && (
|
|
||||||
<div className="space-y-2">
|
|
||||||
<div className="flex items-center justify-between text-xs font-semibold text-muted uppercase tracking-wider px-0.5">
|
|
||||||
<span>Verfügbare Notizen</span>
|
|
||||||
<span className="font-mono text-[11px] font-normal lowercase">
|
|
||||||
{filteredDocs.length} {filteredDocs.length === 1 ? 'Notiz' : 'Notizen'}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-1.5 max-h-56 overflow-y-auto pr-0.5">
|
|
||||||
{loading ? (
|
|
||||||
<div className="p-6 bg-canvas border border-border rounded-card text-xs text-muted flex items-center gap-2 justify-center text-center">
|
|
||||||
<Loader2 className="w-4 h-4 animate-spin text-accent" />
|
|
||||||
<span>Notizen werden geladen…</span>
|
|
||||||
</div>
|
|
||||||
) : filteredDocs.length === 0 ? (
|
|
||||||
<div className="p-4 bg-canvas border border-border rounded-card text-xs text-muted flex items-center gap-2.5 justify-center text-center">
|
|
||||||
<Search className="w-4 h-4 text-faint shrink-0" />
|
|
||||||
<span>
|
|
||||||
{search
|
|
||||||
? `Keine Notiz für "${search}" gefunden.`
|
|
||||||
: 'Keine Notizen im Workspace vorhanden.'}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
filteredDocs.map((d) => (
|
|
||||||
<div
|
|
||||||
key={d.id}
|
|
||||||
onClick={() => handleSelectNote(d)}
|
|
||||||
className="flex items-center justify-between p-2.5 bg-canvas border border-border rounded-card hover:border-accent/60 transition-colors group cursor-pointer"
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-2.5 min-w-0">
|
|
||||||
<span className="text-base shrink-0">{d.icon || '📝'}</span>
|
|
||||||
<div className="min-w-0">
|
|
||||||
<div className="text-xs font-semibold text-main truncate group-hover:text-accent">
|
|
||||||
{d.title || 'Unbenannte Notiz'}
|
|
||||||
</div>
|
|
||||||
{d.folderPath && (
|
|
||||||
<div className="text-[10px] text-muted truncate">
|
|
||||||
📁 {d.folderPath}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="btn-action text-xs h-7 px-2.5 opacity-0 group-hover:opacity-100 transition-opacity flex items-center gap-1 text-accent cursor-pointer shrink-0"
|
|
||||||
>
|
|
||||||
<span>Einfügen</span>
|
|
||||||
<ExternalLink className="w-3 h-3" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,957 +0,0 @@
|
|||||||
import React, { useState, useEffect, useRef, useLayoutEffect, useCallback, useMemo } from 'react';
|
|
||||||
import {
|
|
||||||
ChevronRight,
|
|
||||||
ChevronDown,
|
|
||||||
Check,
|
|
||||||
CheckSquare,
|
|
||||||
X,
|
|
||||||
Trash2,
|
|
||||||
MoreHorizontal,
|
|
||||||
Code,
|
|
||||||
Heading1,
|
|
||||||
Heading2,
|
|
||||||
Heading3,
|
|
||||||
ListTodo,
|
|
||||||
Minus,
|
|
||||||
MessageSquare,
|
|
||||||
Hash,
|
|
||||||
ExternalLink,
|
|
||||||
Maximize2,
|
|
||||||
Link as LinkIcon,
|
|
||||||
FileText,
|
|
||||||
} from 'lucide-react';
|
|
||||||
import { DocumentBlock, BlockType } from '../../lib/types';
|
|
||||||
import { LinkModal } from './LinkModal';
|
|
||||||
import { renderInlineMarkdown } from '../../lib/markdown';
|
|
||||||
import { api } from '../../lib/api';
|
|
||||||
|
|
||||||
export interface SlashCommand {
|
|
||||||
type: BlockType | 'link';
|
|
||||||
label: string;
|
|
||||||
desc: string;
|
|
||||||
icon: React.ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SLASH_COMMANDS: SlashCommand[] = [
|
|
||||||
{ type: 'todo', label: '/todo', desc: 'Aufgabe mit Checkbox', icon: <ListTodo className="w-3.5 h-3.5" /> },
|
|
||||||
{ type: 'link', label: '/link', desc: 'Notiz verknüpfen oder Web-Link einfügen', icon: <LinkIcon className="w-3.5 h-3.5" /> },
|
|
||||||
{ type: 'h1', label: '/h1', desc: 'Große Überschrift', icon: <Heading1 className="w-3.5 h-3.5" /> },
|
|
||||||
{ type: 'h2', label: '/h2', desc: 'Abschnitts-Überschrift', icon: <Heading2 className="w-3.5 h-3.5" /> },
|
|
||||||
{ type: 'h3', label: '/h3', desc: 'Unterabschnitt', icon: <Heading3 className="w-3.5 h-3.5" /> },
|
|
||||||
{ type: 'code', label: '/code', desc: 'Code-Block mit Syntax', icon: <Code className="w-3.5 h-3.5" /> },
|
|
||||||
{ type: 'callout', label: '/callout', desc: 'Hinweisbox', icon: <MessageSquare className="w-3.5 h-3.5" /> },
|
|
||||||
{ type: 'divider', label: '/divider', desc: 'Trennlinie', icon: <Minus className="w-3.5 h-3.5" /> },
|
|
||||||
];
|
|
||||||
|
|
||||||
export interface OutlinerBlockProps {
|
|
||||||
docId: string;
|
|
||||||
block: DocumentBlock;
|
|
||||||
index: number;
|
|
||||||
isLast: boolean;
|
|
||||||
maxAllowedLevel: number;
|
|
||||||
hasChildren: boolean;
|
|
||||||
isFocused: boolean;
|
|
||||||
canEdit: boolean;
|
|
||||||
levelOffset?: number;
|
|
||||||
onZoomBlock?: (blockId: string) => void;
|
|
||||||
onUpdateBlock: (updated: DocumentBlock, immediate?: boolean) => void;
|
|
||||||
onCreateBlockBelow: (afterBlockId: string, newContent?: string) => void;
|
|
||||||
onDeleteBlock: (blockId: string, deleteSubtree?: boolean) => void;
|
|
||||||
onIndentBlock: (blockId: string, delta: 1 | -1) => void;
|
|
||||||
onNavigateFocus: (blockId: string, direction: 'up' | 'down') => void;
|
|
||||||
onFocusBlock?: (blockId: string) => void;
|
|
||||||
onOpenTask?: (taskId: string) => void;
|
|
||||||
onTagClick?: (tag: string) => void;
|
|
||||||
onWikiLinkClick?: (pageTitle: string) => void;
|
|
||||||
onDragStartBlock?: (index: number) => void;
|
|
||||||
onDragOverBlock?: (e: React.DragEvent, index: number) => void;
|
|
||||||
onDropBlock?: (index: number) => void;
|
|
||||||
isDragTarget?: boolean;
|
|
||||||
isTargeted?: boolean;
|
|
||||||
registerTextareaRef: (blockId: string, el: HTMLTextAreaElement | null) => void;
|
|
||||||
onPasteMultiLines?: (blockId: string, textBefore: string, textAfter: string, rawLines: string[]) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const OutlinerBlock: React.FC<OutlinerBlockProps> = ({
|
|
||||||
docId,
|
|
||||||
block,
|
|
||||||
index,
|
|
||||||
isLast,
|
|
||||||
maxAllowedLevel,
|
|
||||||
hasChildren,
|
|
||||||
isFocused,
|
|
||||||
canEdit,
|
|
||||||
levelOffset = 0,
|
|
||||||
onZoomBlock,
|
|
||||||
onUpdateBlock,
|
|
||||||
onCreateBlockBelow,
|
|
||||||
onDeleteBlock,
|
|
||||||
onIndentBlock,
|
|
||||||
onNavigateFocus,
|
|
||||||
onFocusBlock,
|
|
||||||
onOpenTask,
|
|
||||||
onTagClick,
|
|
||||||
onWikiLinkClick,
|
|
||||||
onDragStartBlock,
|
|
||||||
onDragOverBlock,
|
|
||||||
onDropBlock,
|
|
||||||
isDragTarget,
|
|
||||||
isTargeted,
|
|
||||||
registerTextareaRef,
|
|
||||||
onPasteMultiLines,
|
|
||||||
}) => {
|
|
||||||
const [localContent, setLocalContent] = useState<string>(block.content || '');
|
|
||||||
const [isLocallyFocused, setIsLocallyFocused] = useState<boolean>(false);
|
|
||||||
const activeFocus = isFocused || isLocallyFocused;
|
|
||||||
const [slashSearch, setSlashSearch] = useState<string | null>(null);
|
|
||||||
const [slashIndex, setSlashIndex] = useState(0);
|
|
||||||
const [showLinkModal, setShowLinkModal] = useState<boolean>(false);
|
|
||||||
const [showTodoMenu, setShowTodoMenu] = useState<boolean>(false);
|
|
||||||
|
|
||||||
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
|
|
||||||
const debounceTimerRef = useRef<number | null>(null);
|
|
||||||
const latestBlockRef = useRef<DocumentBlock>(block);
|
|
||||||
latestBlockRef.current = block;
|
|
||||||
const localContentRef = useRef<string>(localContent);
|
|
||||||
localContentRef.current = localContent;
|
|
||||||
|
|
||||||
// Callback refs to avoid stale closures in setTimeout, debounce flush, and event listeners
|
|
||||||
const onUpdateBlockRef = useRef(onUpdateBlock);
|
|
||||||
onUpdateBlockRef.current = onUpdateBlock;
|
|
||||||
const onCreateBlockBelowRef = useRef(onCreateBlockBelow);
|
|
||||||
onCreateBlockBelowRef.current = onCreateBlockBelow;
|
|
||||||
const onPasteMultiLinesRef = useRef(onPasteMultiLines);
|
|
||||||
onPasteMultiLinesRef.current = onPasteMultiLines;
|
|
||||||
const onDeleteBlockRef = useRef(onDeleteBlock);
|
|
||||||
onDeleteBlockRef.current = onDeleteBlock;
|
|
||||||
const onIndentBlockRef = useRef(onIndentBlock);
|
|
||||||
onIndentBlockRef.current = onIndentBlock;
|
|
||||||
const onNavigateFocusRef = useRef(onNavigateFocus);
|
|
||||||
onNavigateFocusRef.current = onNavigateFocus;
|
|
||||||
const isPastingRef = useRef<boolean>(false);
|
|
||||||
|
|
||||||
// Track if this input currently has actual focus in an active browser window
|
|
||||||
const isFocusedRef = useRef<boolean>(false);
|
|
||||||
|
|
||||||
const flushDebounce = useCallback(
|
|
||||||
(contentToFlush: string, overrides?: Partial<DocumentBlock>) => {
|
|
||||||
if (debounceTimerRef.current !== null) {
|
|
||||||
window.clearTimeout(debounceTimerRef.current);
|
|
||||||
debounceTimerRef.current = null;
|
|
||||||
}
|
|
||||||
const nextBlock: DocumentBlock = {
|
|
||||||
...latestBlockRef.current,
|
|
||||||
content: contentToFlush,
|
|
||||||
...overrides,
|
|
||||||
};
|
|
||||||
onUpdateBlockRef.current(nextBlock, true);
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Sync incoming remote changes ONLY when this textarea is NOT actively being edited
|
|
||||||
// Condition: isFocusedRef.current === true && document.hasFocus()
|
|
||||||
useEffect(() => {
|
|
||||||
const isActivelyEditing =
|
|
||||||
isFocusedRef.current === true &&
|
|
||||||
typeof document !== 'undefined' &&
|
|
||||||
document.hasFocus() &&
|
|
||||||
textareaRef.current !== null &&
|
|
||||||
document.activeElement === textareaRef.current;
|
|
||||||
|
|
||||||
if (!isActivelyEditing && block.content !== localContentRef.current) {
|
|
||||||
setLocalContent(block.content || '');
|
|
||||||
localContentRef.current = block.content || '';
|
|
||||||
}
|
|
||||||
}, [block.content]);
|
|
||||||
|
|
||||||
// Handle window blur / focus to instantly flush debounced input and clear zombie focus
|
|
||||||
useEffect(() => {
|
|
||||||
const handleWindowBlur = () => {
|
|
||||||
if (debounceTimerRef.current !== null) {
|
|
||||||
window.clearTimeout(debounceTimerRef.current);
|
|
||||||
debounceTimerRef.current = null;
|
|
||||||
flushDebounce(localContentRef.current);
|
|
||||||
} else if (localContentRef.current !== latestBlockRef.current.content) {
|
|
||||||
flushDebounce(localContentRef.current);
|
|
||||||
}
|
|
||||||
isFocusedRef.current = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleWindowFocus = () => {
|
|
||||||
const isThisActive =
|
|
||||||
textareaRef.current !== null &&
|
|
||||||
document.activeElement === textareaRef.current &&
|
|
||||||
document.hasFocus();
|
|
||||||
isFocusedRef.current = isThisActive;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('blur', handleWindowBlur);
|
|
||||||
window.addEventListener('focus', handleWindowFocus);
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('blur', handleWindowBlur);
|
|
||||||
window.removeEventListener('focus', handleWindowFocus);
|
|
||||||
};
|
|
||||||
}, [flushDebounce]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
return () => {
|
|
||||||
if (debounceTimerRef.current !== null) {
|
|
||||||
window.clearTimeout(debounceTimerRef.current);
|
|
||||||
debounceTimerRef.current = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const adjustHeight = useCallback(() => {
|
|
||||||
const el = textareaRef.current;
|
|
||||||
if (!el) return;
|
|
||||||
el.style.height = 'auto';
|
|
||||||
el.style.height = `${Math.max(22, el.scrollHeight)}px`;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
adjustHeight();
|
|
||||||
}, [localContent, block.type, block.level, activeFocus, adjustHeight]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
window.addEventListener('resize', adjustHeight);
|
|
||||||
return () => window.removeEventListener('resize', adjustHeight);
|
|
||||||
}, [adjustHeight]);
|
|
||||||
|
|
||||||
const filteredSlashCommands = useMemo(() => {
|
|
||||||
if (slashSearch === null) return [];
|
|
||||||
const q = slashSearch.toLowerCase();
|
|
||||||
return SLASH_COMMANDS.filter(
|
|
||||||
(c) => c.label.toLowerCase().includes(q) || c.desc.toLowerCase().includes(q)
|
|
||||||
);
|
|
||||||
}, [slashSearch]);
|
|
||||||
|
|
||||||
const applySlashCommand = (cmd: SlashCommand) => {
|
|
||||||
setSlashSearch(null);
|
|
||||||
const clean = localContent.replace(/\/([a-z0-9]*)$/i, '').trim();
|
|
||||||
if (cmd.type === 'link') {
|
|
||||||
setLocalContent(clean);
|
|
||||||
setShowLinkModal(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setLocalContent(clean);
|
|
||||||
flushDebounce(clean, {
|
|
||||||
type: cmd.type,
|
|
||||||
checked: cmd.type === 'todo' ? Boolean(block.checked) : false,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleInsertLink = (linkMarkdown: string) => {
|
|
||||||
setShowLinkModal(false);
|
|
||||||
const cursor = textareaRef.current?.selectionStart ?? localContent.length;
|
|
||||||
const before = localContent.slice(0, cursor);
|
|
||||||
const after = localContent.slice(cursor);
|
|
||||||
const newContent = `${before}${before && !before.endsWith(' ') ? ' ' : ''}${linkMarkdown}${after && !after.startsWith(' ') ? ' ' : ''}${after}`.trim();
|
|
||||||
setLocalContent(newContent);
|
|
||||||
flushDebounce(newContent);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleContentChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
||||||
if (!canEdit) return;
|
|
||||||
let val = e.target.value;
|
|
||||||
let typeOverride: BlockType | undefined;
|
|
||||||
let checkedOverride: boolean | undefined;
|
|
||||||
|
|
||||||
// Quick markdown shortcuts
|
|
||||||
if (val.startsWith('[] ') || val.startsWith('[ ] ')) {
|
|
||||||
val = val.replace(/^\[\s?\]\s/, '');
|
|
||||||
typeOverride = 'todo';
|
|
||||||
checkedOverride = false;
|
|
||||||
} else if (val.startsWith('[x] ') || val.startsWith('[X] ')) {
|
|
||||||
val = val.replace(/^\[[xX]\]\s/, '');
|
|
||||||
typeOverride = 'todo';
|
|
||||||
checkedOverride = true;
|
|
||||||
} else if (val.startsWith('# ') && block.type !== 'h1') {
|
|
||||||
val = val.slice(2);
|
|
||||||
typeOverride = 'h1';
|
|
||||||
} else if (val.startsWith('## ') && block.type !== 'h2') {
|
|
||||||
val = val.slice(3);
|
|
||||||
typeOverride = 'h2';
|
|
||||||
} else if (val.startsWith('### ') && block.type !== 'h3') {
|
|
||||||
val = val.slice(4);
|
|
||||||
typeOverride = 'h3';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for slash command invocation
|
|
||||||
const slashMatch = val.match(/\/([a-z0-9]*)$/i);
|
|
||||||
if (slashMatch) {
|
|
||||||
setSlashSearch(slashMatch[1]);
|
|
||||||
setSlashIndex(0);
|
|
||||||
} else {
|
|
||||||
setSlashSearch(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
setLocalContent(val);
|
|
||||||
|
|
||||||
if (debounceTimerRef.current !== null) {
|
|
||||||
window.clearTimeout(debounceTimerRef.current);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeOverride) {
|
|
||||||
flushDebounce(val, {
|
|
||||||
type: typeOverride,
|
|
||||||
checked: checkedOverride ?? latestBlockRef.current.checked,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
debounceTimerRef.current = window.setTimeout(() => {
|
|
||||||
debounceTimerRef.current = null;
|
|
||||||
onUpdateBlockRef.current({
|
|
||||||
...latestBlockRef.current,
|
|
||||||
content: val,
|
|
||||||
});
|
|
||||||
}, 150);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFocus = () => {
|
|
||||||
isFocusedRef.current = true;
|
|
||||||
setIsLocallyFocused(true);
|
|
||||||
onFocusBlock?.(block.id);
|
|
||||||
setTimeout(adjustHeight, 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBlur = () => {
|
|
||||||
isFocusedRef.current = false;
|
|
||||||
setIsLocallyFocused(false);
|
|
||||||
if (isPastingRef.current) {
|
|
||||||
isPastingRef.current = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (debounceTimerRef.current !== null) {
|
|
||||||
window.clearTimeout(debounceTimerRef.current);
|
|
||||||
debounceTimerRef.current = null;
|
|
||||||
flushDebounce(localContentRef.current);
|
|
||||||
} else if (localContentRef.current !== latestBlockRef.current.content) {
|
|
||||||
flushDebounce(localContentRef.current);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePaste = (e: React.ClipboardEvent<HTMLTextAreaElement>) => {
|
|
||||||
if (!canEdit || block.type === 'code') return;
|
|
||||||
const pastedText = e.clipboardData.getData('text');
|
|
||||||
if (!pastedText || !pastedText.includes('\n')) return;
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
const rawLines = pastedText.split(/\r?\n/);
|
|
||||||
if (rawLines.length <= 1) return;
|
|
||||||
|
|
||||||
const start = e.currentTarget.selectionStart ?? localContent.length;
|
|
||||||
const end = e.currentTarget.selectionEnd ?? start;
|
|
||||||
const textBefore = localContent.slice(0, start);
|
|
||||||
const textAfter = localContent.slice(end);
|
|
||||||
|
|
||||||
if (debounceTimerRef.current !== null) {
|
|
||||||
window.clearTimeout(debounceTimerRef.current);
|
|
||||||
debounceTimerRef.current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
isPastingRef.current = true;
|
|
||||||
onPasteMultiLinesRef.current?.(block.id, textBefore, textAfter, rawLines);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
||||||
if (!canEdit) return;
|
|
||||||
|
|
||||||
// Slash command navigation
|
|
||||||
if (slashSearch !== null && filteredSlashCommands.length > 0) {
|
|
||||||
if (e.key === 'ArrowDown') {
|
|
||||||
e.preventDefault();
|
|
||||||
setSlashIndex((prev) => (prev + 1) % filteredSlashCommands.length);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (e.key === 'ArrowUp') {
|
|
||||||
e.preventDefault();
|
|
||||||
setSlashIndex((prev) => (prev - 1 + filteredSlashCommands.length) % filteredSlashCommands.length);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (e.key === 'Enter' || e.key === 'Tab') {
|
|
||||||
e.preventDefault();
|
|
||||||
const selected = filteredSlashCommands[slashIndex];
|
|
||||||
if (selected) {
|
|
||||||
applySlashCommand(selected);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (e.key === 'Escape') {
|
|
||||||
e.preventDefault();
|
|
||||||
setSlashSearch(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. Tab / Shift+Tab -> Strict Indent / Outdent
|
|
||||||
if (e.key === 'Tab') {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
flushDebounce(localContent);
|
|
||||||
onIndentBlockRef.current(block.id, e.shiftKey ? -1 : 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Enter (without Shift) -> If block is completely empty:
|
|
||||||
// - If level > minLevel, outdent (Shift+Tab behaviour)
|
|
||||||
// - If already at minLevel and is the last block, do NOT create another empty block below
|
|
||||||
// - Otherwise split paragraph at cursor and create new block below
|
|
||||||
if (e.key === 'Enter' && !e.shiftKey && block.type !== 'code') {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
setSlashSearch(null);
|
|
||||||
|
|
||||||
const minLevel = levelOffset || 0;
|
|
||||||
if (localContent === '') {
|
|
||||||
if (Math.max(0, block.level || 0) > minLevel) {
|
|
||||||
flushDebounce(localContent);
|
|
||||||
onIndentBlockRef.current(block.id, -1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isLast) {
|
|
||||||
// Bereits auf oberster Ebene und der letzte Block: kein weiterer leerer Block
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const start = e.currentTarget.selectionStart ?? localContent.length;
|
|
||||||
const end = e.currentTarget.selectionEnd ?? start;
|
|
||||||
let beforeText = localContent.slice(0, start);
|
|
||||||
let afterText = localContent.slice(end);
|
|
||||||
|
|
||||||
// Clean linebreaks at the split boundary if present
|
|
||||||
if (beforeText.endsWith('\r\n')) {
|
|
||||||
beforeText = beforeText.slice(0, -2);
|
|
||||||
} else if (beforeText.endsWith('\n')) {
|
|
||||||
beforeText = beforeText.slice(0, -1);
|
|
||||||
}
|
|
||||||
if (afterText.startsWith('\r\n')) {
|
|
||||||
afterText = afterText.slice(2);
|
|
||||||
} else if (afterText.startsWith('\n')) {
|
|
||||||
afterText = afterText.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
setLocalContent(beforeText);
|
|
||||||
localContentRef.current = beforeText;
|
|
||||||
flushDebounce(beforeText);
|
|
||||||
onCreateBlockBelowRef.current(block.id, afterText);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Backspace on empty block -> IMMEDIATELY DELETE THE BLOCK (regardless of level)!
|
|
||||||
// Outdenting is strictly done via Shift+Tab.
|
|
||||||
if (e.key === 'Backspace' && localContent === '') {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
setSlashSearch(null);
|
|
||||||
if (debounceTimerRef.current !== null) {
|
|
||||||
window.clearTimeout(debounceTimerRef.current);
|
|
||||||
debounceTimerRef.current = null;
|
|
||||||
}
|
|
||||||
onDeleteBlockRef.current(block.id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Arrow navigation between blocks
|
|
||||||
if (e.key === 'ArrowUp' && !e.shiftKey && !e.altKey) {
|
|
||||||
const el = textareaRef.current;
|
|
||||||
if (el && el.selectionStart === 0 && el.selectionEnd === 0) {
|
|
||||||
e.preventDefault();
|
|
||||||
flushDebounce(localContent);
|
|
||||||
onNavigateFocusRef.current(block.id, 'up');
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.key === 'ArrowDown' && !e.shiftKey && !e.altKey) {
|
|
||||||
const el = textareaRef.current;
|
|
||||||
if (el && el.selectionStart === localContent.length && el.selectionEnd === localContent.length) {
|
|
||||||
e.preventDefault();
|
|
||||||
flushDebounce(localContent);
|
|
||||||
onNavigateFocusRef.current(block.id, 'down');
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const level = Math.max(0, block.level || 0);
|
|
||||||
const visualLevel = Math.max(0, level - (levelOffset || 0));
|
|
||||||
const isEmpty = (!localContent || localContent.trim() === '') && !hasChildren;
|
|
||||||
|
|
||||||
// Parse rich tokens (WikiLinks [[Page]], Markdown Links [Title](url), raw URLs, and #Tags)
|
|
||||||
const tokens = useMemo(() => {
|
|
||||||
const parts = (localContent || '').split(
|
|
||||||
/(\[\[.*?\]\]|\[.*?\]\(https?:\/\/.*?\)|\bhttps?:\/\/[^\s]+|#[a-zA-Z0-9äöüÄÖÜß_-]+)/g
|
|
||||||
);
|
|
||||||
return parts.filter(Boolean);
|
|
||||||
}, [localContent]);
|
|
||||||
|
|
||||||
const hasSpecialTokens = tokens.some(
|
|
||||||
(t) =>
|
|
||||||
t.startsWith('#') ||
|
|
||||||
(t.startsWith('[[') && t.endsWith(']]')) ||
|
|
||||||
/^\[(.*?)\]\((https?:\/\/.*?)\)$/.test(t) ||
|
|
||||||
/^https?:\/\//.test(t)
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={`group relative flex items-start gap-1 py-1 px-1.5 rounded-card transition-all duration-300 ${
|
|
||||||
isDragTarget
|
|
||||||
? 'border-t-2 border-accent bg-accent/10'
|
|
||||||
: isTargeted
|
|
||||||
? 'bg-accent/15 ring-2 ring-accent'
|
|
||||||
: activeFocus
|
|
||||||
? 'bg-panel-elevated'
|
|
||||||
: 'hover:bg-panel'
|
|
||||||
}`}
|
|
||||||
style={{
|
|
||||||
paddingLeft: `${visualLevel * 22 + 4}px`,
|
|
||||||
}}
|
|
||||||
onDragOver={(e) => onDragOverBlock?.(e, index)}
|
|
||||||
onDrop={() => onDropBlock?.(index)}
|
|
||||||
onClick={(e) => {
|
|
||||||
if ((e.target as HTMLElement).closest('button, a, input, select')) return;
|
|
||||||
if (!activeFocus && canEdit && textareaRef.current) {
|
|
||||||
textareaRef.current.focus();
|
|
||||||
const len = textareaRef.current.value.length;
|
|
||||||
textareaRef.current.setSelectionRange(len, len);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{/* Indentation Guide Line */}
|
|
||||||
{visualLevel > 0 &&
|
|
||||||
Array.from({ length: visualLevel }).map((_, lvlIdx) => (
|
|
||||||
<div
|
|
||||||
key={lvlIdx}
|
|
||||||
className="pointer-events-none absolute top-0 bottom-0 w-px border-l border-border"
|
|
||||||
style={{ left: `${lvlIdx * 22 + 12}px` }}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{/* Bullet Controls: Collapse Toggle & Bullet (Drag-Handle & Zoom) / Checkbox */}
|
|
||||||
<div className="flex items-center gap-0.5 pt-1 select-none shrink-0">
|
|
||||||
{hasChildren ? (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() =>
|
|
||||||
flushDebounce(localContent, { collapsed: !block.collapsed })
|
|
||||||
}
|
|
||||||
className="p-0.5 text-muted hover:text-accent transition-colors"
|
|
||||||
title={block.collapsed ? 'Unterpunkte ausklappen' : 'Unterpunkte einklappen'}
|
|
||||||
>
|
|
||||||
{block.collapsed ? (
|
|
||||||
<ChevronRight className="w-3.5 h-3.5" />
|
|
||||||
) : (
|
|
||||||
<ChevronDown className="w-3.5 h-3.5 text-accent" />
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
) : (
|
|
||||||
<span className="w-3.5" />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Bullet handle for dragging and zoom focus */}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
draggable={canEdit}
|
|
||||||
onDragStart={() => canEdit && onDragStartBlock?.(index)}
|
|
||||||
onClick={() => onZoomBlock?.(block.id)}
|
|
||||||
className={`w-4 h-4 flex items-center justify-center rounded-btn hover:bg-panel-hover group/bullet transition-transform ${
|
|
||||||
canEdit ? 'cursor-grab active:cursor-grabbing' : 'cursor-pointer'
|
|
||||||
}`}
|
|
||||||
title={
|
|
||||||
canEdit
|
|
||||||
? 'Ziehen zum Verschieben • Klick: Ast hineinzoomen (Fokus-Modus)'
|
|
||||||
: 'Klick: In diesen Ast hineinzoomen (Fokus-Modus)'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={`w-1.5 h-1.5 rounded-full transition-all duration-150 ${
|
|
||||||
block.collapsed && hasChildren
|
|
||||||
? 'bg-accent ring-2 ring-accent/30'
|
|
||||||
: activeFocus
|
|
||||||
? 'bg-accent scale-125'
|
|
||||||
: 'bg-faint group-hover/bullet:bg-accent group-hover/bullet:scale-125'
|
|
||||||
} ${
|
|
||||||
isEmpty
|
|
||||||
? 'opacity-0 group-hover:opacity-100 hover:opacity-100'
|
|
||||||
: 'opacity-100'
|
|
||||||
}`}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* If To-Do block: checkbox alongside bullet */}
|
|
||||||
{block.type === 'todo' && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
disabled={!canEdit}
|
|
||||||
onClick={() =>
|
|
||||||
flushDebounce(localContent, { checked: !block.checked })
|
|
||||||
}
|
|
||||||
className={`w-4 h-4 checkbox-square flex items-center justify-center transition-colors border ${
|
|
||||||
block.checked
|
|
||||||
? 'bg-status-ok border-status-ok text-on-accent'
|
|
||||||
: 'border-strong hover:border-accent text-transparent'
|
|
||||||
}`}
|
|
||||||
title={block.checked ? 'Als offen markieren' : 'Als erledigt markieren'}
|
|
||||||
>
|
|
||||||
<Check className="w-3 h-3 stroke-[3]" />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Main Block Content */}
|
|
||||||
<div className="flex-1 min-w-0 pr-1 relative min-h-[1.5rem]">
|
|
||||||
{block.type === 'divider' ? (
|
|
||||||
<div className="py-2">
|
|
||||||
<hr className="border-t border-border" />
|
|
||||||
</div>
|
|
||||||
) : block.type === 'code' ? (
|
|
||||||
<div className="bg-code border border-border rounded-btn p-2 my-0.5">
|
|
||||||
<div className="text-[10px] text-faint font-mono uppercase pb-1 flex justify-between">
|
|
||||||
<span>Code</span>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => flushDebounce(localContent, { type: 'bullet' })}
|
|
||||||
className="hover:text-accent"
|
|
||||||
>
|
|
||||||
Als Text
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<textarea
|
|
||||||
ref={(el) => {
|
|
||||||
textareaRef.current = el;
|
|
||||||
registerTextareaRef(block.id, el);
|
|
||||||
}}
|
|
||||||
rows={1}
|
|
||||||
value={localContent}
|
|
||||||
readOnly={!canEdit}
|
|
||||||
onFocus={handleFocus}
|
|
||||||
onBlur={handleBlur}
|
|
||||||
onChange={handleContentChange}
|
|
||||||
onKeyDown={handleKeyDown}
|
|
||||||
className="w-full resize-none font-mono text-xs bg-transparent text-status-ok border-0 focus:outline-none focus:ring-0 leading-relaxed"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : block.type === 'callout' ? (
|
|
||||||
<div className="bg-panel-elevated border-l-2 border-accent p-2 rounded-r-btn my-0.5">
|
|
||||||
<textarea
|
|
||||||
ref={(el) => {
|
|
||||||
textareaRef.current = el;
|
|
||||||
registerTextareaRef(block.id, el);
|
|
||||||
}}
|
|
||||||
rows={1}
|
|
||||||
value={localContent}
|
|
||||||
readOnly={!canEdit}
|
|
||||||
onFocus={handleFocus}
|
|
||||||
onBlur={handleBlur}
|
|
||||||
onChange={handleContentChange}
|
|
||||||
onKeyDown={handleKeyDown}
|
|
||||||
className="w-full resize-none bg-transparent text-sm text-main border-0 focus:outline-none focus:ring-0 leading-relaxed italic"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="relative w-full min-h-[1.5rem]">
|
|
||||||
{/* View Layer with Inline Markdown & Actions (3-dots or Erweitert Badge) directly behind text */}
|
|
||||||
<div
|
|
||||||
onClick={() => {
|
|
||||||
if (!activeFocus && canEdit && textareaRef.current) {
|
|
||||||
textareaRef.current.focus();
|
|
||||||
const len = textareaRef.current.value.length;
|
|
||||||
textareaRef.current.setSelectionRange(len, len);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className={`w-full min-h-[1.5rem] leading-relaxed whitespace-pre-wrap break-words [overflow-wrap:anywhere] ${
|
|
||||||
activeFocus ? 'absolute inset-0 pointer-events-none' : 'relative cursor-text'
|
|
||||||
} ${
|
|
||||||
block.type === 'h1'
|
|
||||||
? 'text-lg font-bold text-main tracking-tight'
|
|
||||||
: block.type === 'h2'
|
|
||||||
? 'text-base font-semibold text-main'
|
|
||||||
: block.type === 'h3'
|
|
||||||
? 'text-sm font-semibold text-main'
|
|
||||||
: block.type === 'todo' && block.checked
|
|
||||||
? 'text-sm text-faint line-through'
|
|
||||||
: 'text-sm text-main'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{/* When actively focused, ghost text is invisible so textarea renders text/caret directly */}
|
|
||||||
<span className={activeFocus ? 'invisible' : ''}>
|
|
||||||
{localContent ? renderInlineMarkdown(localContent) : '\u200b'}
|
|
||||||
</span>
|
|
||||||
|
|
||||||
{/* Inline Badge and 3-Dots directly behind the text */}
|
|
||||||
{block.type === 'todo' && (
|
|
||||||
<span className="inline-flex items-center align-middle ml-1.5 gap-1 shrink-0 pointer-events-auto z-10 relative select-none">
|
|
||||||
{block.taskId && (
|
|
||||||
<span
|
|
||||||
className="badge-accent text-[9px] inline-flex items-center gap-0.5 px-1.5 py-0.2 rounded font-medium shrink-0"
|
|
||||||
title="Mit erweiterter Aufgabe synchronisiert"
|
|
||||||
>
|
|
||||||
<CheckSquare className="w-2.5 h-2.5" />
|
|
||||||
<span>Erweitert</span>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{canEdit && (
|
|
||||||
<span className="relative inline-flex items-center">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
setShowTodoMenu((prev) => !prev);
|
|
||||||
}}
|
|
||||||
className="p-0.5 text-faint hover:text-accent rounded-btn transition-colors cursor-pointer"
|
|
||||||
title="Aufgaben-Optionen"
|
|
||||||
>
|
|
||||||
<MoreHorizontal className="w-3.5 h-3.5" />
|
|
||||||
</button>
|
|
||||||
{showTodoMenu && (
|
|
||||||
<div
|
|
||||||
className="absolute left-0 top-full mt-1 bg-panel border border-border shadow-lg rounded-card p-1 z-30 w-52 text-xs"
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
{!block.taskId ? (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={async () => {
|
|
||||||
setShowTodoMenu(false);
|
|
||||||
try {
|
|
||||||
const targetDocId = docId || block.documentId || block.docId || '';
|
|
||||||
const thought = await api.createEnhancedTask(targetDocId, block.id, {
|
|
||||||
content: localContent || 'Aufgabe',
|
|
||||||
checked: Boolean(block.checked),
|
|
||||||
});
|
|
||||||
const updatedBlock: DocumentBlock = {
|
|
||||||
...latestBlockRef.current,
|
|
||||||
content: localContent,
|
|
||||||
taskId: thought.id,
|
|
||||||
type: 'todo',
|
|
||||||
};
|
|
||||||
onUpdateBlockRef.current(updatedBlock, true);
|
|
||||||
} catch (err: any) {
|
|
||||||
alert(err.message || 'Fehler beim Erstellen der erweiterten Aufgabe');
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="w-full text-left px-2 py-1.5 rounded-btn hover:bg-panel-elevated hover:text-accent flex items-center gap-1.5 text-main font-medium cursor-pointer"
|
|
||||||
>
|
|
||||||
<CheckSquare className="w-3.5 h-3.5 text-accent" />
|
|
||||||
<span>In erweiterte Aufgabe umwandeln</span>
|
|
||||||
</button>
|
|
||||||
) : (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={async () => {
|
|
||||||
setShowTodoMenu(false);
|
|
||||||
try {
|
|
||||||
if (block.taskId) {
|
|
||||||
await api.unlinkEnhancedTask(block.taskId).catch(() => {});
|
|
||||||
}
|
|
||||||
const updatedBlock: DocumentBlock = {
|
|
||||||
...latestBlockRef.current,
|
|
||||||
content: localContent,
|
|
||||||
taskId: '',
|
|
||||||
type: 'todo',
|
|
||||||
};
|
|
||||||
onUpdateBlockRef.current(updatedBlock, true);
|
|
||||||
} catch (err: any) {
|
|
||||||
alert(err.message || 'Fehler beim Aufheben der Verknüpfung');
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="w-full text-left px-2 py-1.5 rounded-btn hover:bg-panel-elevated hover:text-status-warn flex items-center gap-1.5 text-main font-medium cursor-pointer"
|
|
||||||
>
|
|
||||||
<X className="w-3.5 h-3.5 text-status-warn" />
|
|
||||||
<span>Verknüpfung aufheben</span>
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<textarea
|
|
||||||
ref={(el) => {
|
|
||||||
textareaRef.current = el;
|
|
||||||
registerTextareaRef(block.id, el);
|
|
||||||
}}
|
|
||||||
rows={1}
|
|
||||||
value={localContent}
|
|
||||||
readOnly={!canEdit}
|
|
||||||
onFocus={handleFocus}
|
|
||||||
onBlur={handleBlur}
|
|
||||||
onChange={handleContentChange}
|
|
||||||
onKeyDown={handleKeyDown}
|
|
||||||
onPaste={handlePaste}
|
|
||||||
className={`w-full min-h-[1.5rem] resize-none overflow-hidden bg-transparent border-0 focus:outline-none focus:ring-0 leading-relaxed whitespace-pre-wrap break-words [overflow-wrap:anywhere] ${
|
|
||||||
activeFocus ? 'relative z-0 text-main' : 'absolute inset-0 text-transparent selection:text-transparent pointer-events-none'
|
|
||||||
} ${
|
|
||||||
block.type === 'h1'
|
|
||||||
? 'text-lg font-bold text-main tracking-tight'
|
|
||||||
: block.type === 'h2'
|
|
||||||
? 'text-base font-semibold text-main'
|
|
||||||
: block.type === 'h3'
|
|
||||||
? 'text-sm font-semibold text-main'
|
|
||||||
: block.type === 'todo' && block.checked
|
|
||||||
? 'text-sm text-faint line-through'
|
|
||||||
: 'text-sm text-main'
|
|
||||||
}`}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Rich Tokens Bar (Wiki-Links & #Tags) if present */}
|
|
||||||
{hasSpecialTokens && !isFocused && (
|
|
||||||
<div className="flex flex-wrap items-center gap-1 mt-0.5">
|
|
||||||
{tokens.map((part, idx) => {
|
|
||||||
if (part.startsWith('#') && part.length > 1) {
|
|
||||||
const tag = part.slice(1);
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={idx}
|
|
||||||
type="button"
|
|
||||||
onClick={() => onTagClick?.(tag)}
|
|
||||||
className="inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] font-medium text-accent bg-accent-dim hover:bg-accent/20 rounded-btn transition-colors"
|
|
||||||
>
|
|
||||||
<Hash className="w-2.5 h-2.5 opacity-80" />
|
|
||||||
<span>{tag}</span>
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (part.startsWith('[[') && part.endsWith(']]')) {
|
|
||||||
const page = part.slice(2, -2).trim();
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={idx}
|
|
||||||
type="button"
|
|
||||||
onClick={() => onWikiLinkClick?.(page)}
|
|
||||||
className="inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] font-medium text-status-info bg-status-info/10 hover:bg-status-info/20 rounded-btn transition-colors"
|
|
||||||
title={`Notiz öffnen: ${page}`}
|
|
||||||
>
|
|
||||||
<FileText className="w-2.5 h-2.5 opacity-80" />
|
|
||||||
<span>{page}</span>
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const mdMatch = part.match(/^\[(.*?)\]\((https?:\/\/.*?)\)$/);
|
|
||||||
if (mdMatch) {
|
|
||||||
const label = mdMatch[1];
|
|
||||||
const url = mdMatch[2];
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
key={idx}
|
|
||||||
href={url}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] font-medium text-status-ok bg-status-ok/10 hover:bg-status-ok/20 rounded-btn transition-colors"
|
|
||||||
title={url}
|
|
||||||
>
|
|
||||||
<ExternalLink className="w-2.5 h-2.5 opacity-80" />
|
|
||||||
<span>{label || url}</span>
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (/^https?:\/\//.test(part)) {
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
key={idx}
|
|
||||||
href={part}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] font-medium text-status-ok bg-status-ok/10 hover:bg-status-ok/20 rounded-btn transition-colors"
|
|
||||||
title={part}
|
|
||||||
>
|
|
||||||
<ExternalLink className="w-2.5 h-2.5 opacity-80" />
|
|
||||||
<span className="truncate max-w-[160px]">{part}</span>
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Floating Slash Commands Menu */}
|
|
||||||
{slashSearch !== null && canEdit && (
|
|
||||||
<div className="absolute left-0 top-8 z-40 w-56 panel-surface shadow-panel border border-border rounded-card p-1">
|
|
||||||
<div className="px-2 py-1 text-[10px] font-bold uppercase tracking-wider text-faint border-b border-border mb-1">
|
|
||||||
Befehl auswählen
|
|
||||||
</div>
|
|
||||||
<div className="max-h-48 overflow-y-auto space-y-0.5">
|
|
||||||
{filteredSlashCommands.map((cmd, i) => (
|
|
||||||
<button
|
|
||||||
key={cmd.type}
|
|
||||||
type="button"
|
|
||||||
onMouseDown={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
applySlashCommand(cmd);
|
|
||||||
}}
|
|
||||||
className={`w-full text-left px-2 py-1 rounded-btn text-xs flex items-center justify-between transition-colors ${
|
|
||||||
i === slashIndex
|
|
||||||
? 'bg-accent text-on-accent'
|
|
||||||
: 'text-main hover:bg-panel-elevated'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-1.5">
|
|
||||||
{cmd.icon}
|
|
||||||
<span className="font-semibold">{cmd.label}</span>
|
|
||||||
</div>
|
|
||||||
<span className="text-[10px] opacity-75">{cmd.desc}</span>
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
{filteredSlashCommands.length === 0 && (
|
|
||||||
<div className="p-2 text-center text-xs text-faint">
|
|
||||||
Kein Befehl gefunden
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Zoom / Focus button on hover */}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => onZoomBlock?.(block.id)}
|
|
||||||
className="opacity-0 group-hover:opacity-100 focus:opacity-100 p-0.5 text-faint hover:text-accent rounded-btn transition-opacity shrink-0"
|
|
||||||
title="In diesen Ast hineinzoomen (Fokus-Modus)"
|
|
||||||
>
|
|
||||||
<Maximize2 className="w-3.5 h-3.5" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Delete button on hover (Trash2 icon) */}
|
|
||||||
{canEdit && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => {
|
|
||||||
if (hasChildren) {
|
|
||||||
if (window.confirm('Bist du sicher? Alle Unterpunkte dieses Asts werden ebenfalls gelöscht.')) {
|
|
||||||
onDeleteBlockRef.current(block.id, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
onDeleteBlockRef.current(block.id, false);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="opacity-0 group-hover:opacity-100 focus:opacity-100 p-0.5 text-faint hover:text-status-err rounded-btn transition-opacity shrink-0 cursor-pointer"
|
|
||||||
title="Block löschen"
|
|
||||||
>
|
|
||||||
<Trash2 className="w-3.5 h-3.5" />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Link Insertion Modal */}
|
|
||||||
{showLinkModal && (
|
|
||||||
<LinkModal
|
|
||||||
isOpen={showLinkModal}
|
|
||||||
onClose={() => setShowLinkModal(false)}
|
|
||||||
onInsertLink={handleInsertLink}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,731 +0,0 @@
|
|||||||
import React, { useState, useRef, useEffect, useCallback, useMemo, forwardRef, useImperativeHandle } from 'react';
|
|
||||||
import { DocumentBlock, BlockType } from '../../lib/types';
|
|
||||||
import { OutlinerBlock } from './OutlinerBlock';
|
|
||||||
|
|
||||||
export interface OutlinerTreeHandle {
|
|
||||||
focusFirstBlock: () => void;
|
|
||||||
focusBlock: (blockId: string, cursor?: 'start' | 'end') => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface OutlinerTreeProps {
|
|
||||||
docId: string;
|
|
||||||
blocks: DocumentBlock[];
|
|
||||||
canEdit: boolean;
|
|
||||||
levelOffset?: number;
|
|
||||||
onZoomBlock?: (blockId: string) => void;
|
|
||||||
onUpdateBlock: (updated: DocumentBlock, immediate?: boolean) => void;
|
|
||||||
onUpdateBlocks?: (updated: DocumentBlock[]) => void;
|
|
||||||
onCreateBlock: (newBlock: DocumentBlock, afterBlockId?: string) => void;
|
|
||||||
onInsertBlocks?: (afterBlockId: string, updatedCurrent: DocumentBlock, newBlocks: DocumentBlock[]) => void;
|
|
||||||
onDeleteBlock: (blockId: string) => void;
|
|
||||||
onMoveBlock: (blockId: string, newIndex: number, level?: number) => void;
|
|
||||||
onOpenTask?: (taskId: string) => void;
|
|
||||||
onTagClick?: (tag: string) => void;
|
|
||||||
onWikiLinkClick?: (pageTitle: string) => void;
|
|
||||||
initialFocusedBlockId?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const OutlinerTree = forwardRef<OutlinerTreeHandle, OutlinerTreeProps>(({
|
|
||||||
docId,
|
|
||||||
blocks,
|
|
||||||
canEdit,
|
|
||||||
levelOffset = 0,
|
|
||||||
onZoomBlock,
|
|
||||||
onUpdateBlock,
|
|
||||||
onUpdateBlocks,
|
|
||||||
onCreateBlock,
|
|
||||||
onInsertBlocks,
|
|
||||||
onDeleteBlock,
|
|
||||||
onMoveBlock,
|
|
||||||
onOpenTask,
|
|
||||||
onTagClick,
|
|
||||||
onWikiLinkClick,
|
|
||||||
initialFocusedBlockId,
|
|
||||||
}, ref) => {
|
|
||||||
const [focusedBlockId, setFocusedBlockId] = useState<string | null>(null);
|
|
||||||
const [highlightedBlockId, setHighlightedBlockId] = useState<string | null>(
|
|
||||||
initialFocusedBlockId || null
|
|
||||||
);
|
|
||||||
const [draggedIndex, setDraggedIndex] = useState<number | null>(null);
|
|
||||||
const [dragOverIndex, setDragOverIndex] = useState<number | null>(null);
|
|
||||||
|
|
||||||
const textareaMapRef = useRef<Map<string, HTMLTextAreaElement>>(new Map());
|
|
||||||
const pendingFocusRef = useRef<{ blockId: string; cursor: 'start' | 'end' | 'select' } | null>(null);
|
|
||||||
|
|
||||||
const focusBlockInput = useCallback(
|
|
||||||
(blockId: string, cursor: 'start' | 'end' | 'select' = 'end') => {
|
|
||||||
setFocusedBlockId(blockId);
|
|
||||||
const el = textareaMapRef.current.get(blockId);
|
|
||||||
if (el) {
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
el.focus();
|
|
||||||
try {
|
|
||||||
if (cursor === 'select') {
|
|
||||||
el.select();
|
|
||||||
} else {
|
|
||||||
const pos = cursor === 'end' ? el.value.length : 0;
|
|
||||||
el.setSelectionRange(pos, pos);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
pendingFocusRef.current = { blockId, cursor };
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
useImperativeHandle(
|
|
||||||
ref,
|
|
||||||
() => ({
|
|
||||||
focusFirstBlock: () => {
|
|
||||||
if (blocks.length > 0) {
|
|
||||||
focusBlockInput(blocks[0].id, 'end');
|
|
||||||
} else {
|
|
||||||
const firstBlock: DocumentBlock = {
|
|
||||||
id: `blk_${Date.now().toString(36)}_0`,
|
|
||||||
documentId: docId,
|
|
||||||
type: 'text',
|
|
||||||
content: '',
|
|
||||||
level: levelOffset || 0,
|
|
||||||
position: 1000,
|
|
||||||
};
|
|
||||||
pendingFocusRef.current = { blockId: firstBlock.id, cursor: 'end' };
|
|
||||||
onCreateBlock(firstBlock);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
focusBlock: (blockId: string, cursor: 'start' | 'end' = 'end') => {
|
|
||||||
focusBlockInput(blockId, cursor);
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
[blocks, docId, levelOffset, onCreateBlock, focusBlockInput]
|
|
||||||
);
|
|
||||||
|
|
||||||
const registerTextareaRef = useCallback((blockId: string, el: HTMLTextAreaElement | null) => {
|
|
||||||
if (el) {
|
|
||||||
textareaMapRef.current.set(blockId, el);
|
|
||||||
if (pendingFocusRef.current && pendingFocusRef.current.blockId === blockId) {
|
|
||||||
const target = pendingFocusRef.current;
|
|
||||||
pendingFocusRef.current = null;
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
setFocusedBlockId(blockId);
|
|
||||||
el.focus();
|
|
||||||
try {
|
|
||||||
if (target.cursor === 'select') {
|
|
||||||
el.select();
|
|
||||||
} else {
|
|
||||||
const pos = target.cursor === 'end' ? el.value.length : 0;
|
|
||||||
el.setSelectionRange(pos, pos);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
textareaMapRef.current.delete(blockId);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (initialFocusedBlockId) {
|
|
||||||
setHighlightedBlockId(initialFocusedBlockId);
|
|
||||||
focusBlockInput(initialFocusedBlockId, 'select');
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
focusBlockInput(initialFocusedBlockId, 'select');
|
|
||||||
}, 70);
|
|
||||||
const timer2 = setTimeout(() => {
|
|
||||||
focusBlockInput(initialFocusedBlockId, 'select');
|
|
||||||
}, 200);
|
|
||||||
const fadeTimer = setTimeout(() => {
|
|
||||||
setHighlightedBlockId(null);
|
|
||||||
}, 2800);
|
|
||||||
return () => {
|
|
||||||
clearTimeout(timer);
|
|
||||||
clearTimeout(timer2);
|
|
||||||
clearTimeout(fadeTimer);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, [initialFocusedBlockId, blocks.length, focusBlockInput]);
|
|
||||||
|
|
||||||
// Compute visibility based on collapsed ancestor blocks
|
|
||||||
const visibleEntries = useMemo(() => {
|
|
||||||
const result: {
|
|
||||||
block: DocumentBlock;
|
|
||||||
index: number;
|
|
||||||
hasChildren: boolean;
|
|
||||||
maxAllowedLevel: number;
|
|
||||||
}[] = [];
|
|
||||||
|
|
||||||
let collapsedAboveLevel: number | null = null;
|
|
||||||
|
|
||||||
for (let i = 0; i < blocks.length; i++) {
|
|
||||||
const b = blocks[i];
|
|
||||||
const lvl = Math.max(0, b.level || 0);
|
|
||||||
|
|
||||||
if (collapsedAboveLevel !== null) {
|
|
||||||
if (lvl > collapsedAboveLevel) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
collapsedAboveLevel = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextBlock = blocks[i + 1];
|
|
||||||
const nextLvl = nextBlock ? Math.max(0, nextBlock.level || 0) : 0;
|
|
||||||
const hasChildren = Boolean(nextBlock && nextLvl > lvl);
|
|
||||||
|
|
||||||
const prevBlock = i > 0 ? blocks[i - 1] : null;
|
|
||||||
const maxAllowedLevel = prevBlock ? Math.max(0, prevBlock.level || 0) + 1 : (levelOffset || 0);
|
|
||||||
|
|
||||||
result.push({
|
|
||||||
block: b,
|
|
||||||
index: i,
|
|
||||||
hasChildren,
|
|
||||||
maxAllowedLevel,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (b.collapsed && hasChildren) {
|
|
||||||
collapsedAboveLevel = lvl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}, [blocks, levelOffset]);
|
|
||||||
|
|
||||||
const handleCreateBlockBelow = useCallback(
|
|
||||||
(afterBlockId: string, newContent: string = '') => {
|
|
||||||
if (!canEdit) return;
|
|
||||||
const idx = blocks.findIndex((b) => b.id === afterBlockId);
|
|
||||||
const currentBlock = idx >= 0 ? blocks[idx] : null;
|
|
||||||
const level = currentBlock ? Math.max(0, currentBlock.level || 0) : 0;
|
|
||||||
const inheritedType: BlockType = 'text';
|
|
||||||
|
|
||||||
const newBlock: DocumentBlock = {
|
|
||||||
id: `blk_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 7)}`,
|
|
||||||
documentId: docId,
|
|
||||||
type: inheritedType,
|
|
||||||
content: newContent,
|
|
||||||
level,
|
|
||||||
checked: false,
|
|
||||||
collapsed: false,
|
|
||||||
position: ((idx >= 0 ? idx + 2 : blocks.length + 1) * 1000),
|
|
||||||
};
|
|
||||||
|
|
||||||
pendingFocusRef.current = { blockId: newBlock.id, cursor: 'start' };
|
|
||||||
setFocusedBlockId(newBlock.id);
|
|
||||||
onCreateBlock(newBlock, afterBlockId);
|
|
||||||
},
|
|
||||||
[blocks, canEdit, docId, onCreateBlock]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handlePasteMultiLines = useCallback(
|
|
||||||
(blockId: string, textBefore: string, textAfter: string, rawLines: string[]) => {
|
|
||||||
if (!canEdit || rawLines.length === 0) return;
|
|
||||||
const idx = blocks.findIndex((b) => b.id === blockId);
|
|
||||||
if (idx === -1) return;
|
|
||||||
|
|
||||||
const currentBlock = blocks[idx];
|
|
||||||
const baseLevel = Math.max(0, currentBlock.level || 0);
|
|
||||||
|
|
||||||
// Detect indentation style (2-space vs 4-space tabs)
|
|
||||||
let detectedSpaceStep = 2;
|
|
||||||
const leadingSpacesList: number[] = [];
|
|
||||||
for (const line of rawLines) {
|
|
||||||
if (!line.trim()) continue;
|
|
||||||
let sp = 0;
|
|
||||||
while (sp < line.length && line[sp] === ' ') sp++;
|
|
||||||
if (sp > 0) leadingSpacesList.push(sp);
|
|
||||||
}
|
|
||||||
if (leadingSpacesList.length > 0 && leadingSpacesList.every((s) => s % 4 === 0)) {
|
|
||||||
detectedSpaceStep = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse lines into structured blocks
|
|
||||||
interface ParsedPasteItem {
|
|
||||||
type: BlockType;
|
|
||||||
checked?: boolean;
|
|
||||||
content: string;
|
|
||||||
indent: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsed: ParsedPasteItem[] = [];
|
|
||||||
let currentItem: ParsedPasteItem | null = null;
|
|
||||||
let inCodeBlock = false;
|
|
||||||
let afterHeading = false;
|
|
||||||
|
|
||||||
const pushCurrentItem = () => {
|
|
||||||
if (currentItem) {
|
|
||||||
currentItem.content = currentItem.content.trimEnd();
|
|
||||||
parsed.push(currentItem);
|
|
||||||
currentItem = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (let i = 0; i < rawLines.length; i++) {
|
|
||||||
const rawLine = rawLines[i];
|
|
||||||
|
|
||||||
// 1. Inside a fenced code block
|
|
||||||
if (inCodeBlock) {
|
|
||||||
if (currentItem) {
|
|
||||||
currentItem.content += '\n' + rawLine;
|
|
||||||
}
|
|
||||||
if (rawLine.trim().startsWith('```')) {
|
|
||||||
inCodeBlock = false;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Starts a code fence
|
|
||||||
if (rawLine.trim().startsWith('```')) {
|
|
||||||
inCodeBlock = true;
|
|
||||||
if (afterHeading) {
|
|
||||||
afterHeading = false;
|
|
||||||
pushCurrentItem();
|
|
||||||
currentItem = {
|
|
||||||
type: 'text',
|
|
||||||
content: rawLine,
|
|
||||||
indent: 0,
|
|
||||||
};
|
|
||||||
} else if (currentItem) {
|
|
||||||
currentItem.content += (currentItem.content.endsWith('\n') ? '' : '\n') + rawLine;
|
|
||||||
} else {
|
|
||||||
currentItem = {
|
|
||||||
type: 'text',
|
|
||||||
content: rawLine,
|
|
||||||
indent: 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Measure leading indent
|
|
||||||
let tabs = 0;
|
|
||||||
let spaces = 0;
|
|
||||||
let charIdx = 0;
|
|
||||||
while (charIdx < rawLine.length) {
|
|
||||||
if (rawLine[charIdx] === '\t') {
|
|
||||||
tabs++;
|
|
||||||
charIdx++;
|
|
||||||
} else if (rawLine[charIdx] === ' ') {
|
|
||||||
spaces++;
|
|
||||||
charIdx++;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const strippedLine = rawLine.slice(charIdx);
|
|
||||||
const lineIndent = tabs + Math.floor(spaces / detectedSpaceStep);
|
|
||||||
|
|
||||||
// Blank lines
|
|
||||||
if (strippedLine.trim() === '') {
|
|
||||||
if (currentItem) {
|
|
||||||
currentItem.content += '\n';
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Headings: #, ##, ###
|
|
||||||
const h3Match = strippedLine.match(/^###\s+(.*)$/);
|
|
||||||
const h2Match = strippedLine.match(/^##\s+(.*)$/);
|
|
||||||
const h1Match = strippedLine.match(/^#\s+(.*)$/);
|
|
||||||
if (h1Match || h2Match || h3Match) {
|
|
||||||
pushCurrentItem();
|
|
||||||
afterHeading = true;
|
|
||||||
const type: BlockType = h1Match ? 'h1' : h2Match ? 'h2' : 'h3';
|
|
||||||
const content = (h1Match || h2Match || h3Match)![1];
|
|
||||||
parsed.push({ type, content, indent: lineIndent });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dividers: ---, ***, ___
|
|
||||||
if (/^(?:---|---|\*\*\*|___)\s*$/.test(strippedLine.trim())) {
|
|
||||||
pushCurrentItem();
|
|
||||||
afterHeading = false;
|
|
||||||
parsed.push({ type: 'divider', content: '---', indent: lineIndent });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Todo items: - [ ], - [x], * [ ], * [x]
|
|
||||||
const todoMatch = strippedLine.match(/^[-*]\s*\[([ xX])\]\s*(.*)$/);
|
|
||||||
if (todoMatch) {
|
|
||||||
pushCurrentItem();
|
|
||||||
afterHeading = false;
|
|
||||||
parsed.push({
|
|
||||||
type: 'todo',
|
|
||||||
checked: todoMatch[1].toLowerCase() === 'x',
|
|
||||||
content: todoMatch[2],
|
|
||||||
indent: lineIndent,
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicit bullet or numbered list: - item, * item, • item, 1. item, 1) item
|
|
||||||
const bulletMatch = strippedLine.match(/^[-*•]\s+(.*)$/);
|
|
||||||
const numMatch = strippedLine.match(/^\d+[\.\)]\s+(.*)$/);
|
|
||||||
if (bulletMatch || numMatch) {
|
|
||||||
pushCurrentItem();
|
|
||||||
afterHeading = false;
|
|
||||||
parsed.push({
|
|
||||||
type: 'text',
|
|
||||||
content: (bulletMatch ? bulletMatch[1] : numMatch![1]),
|
|
||||||
indent: lineIndent,
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regular text line
|
|
||||||
if (afterHeading) {
|
|
||||||
// This starts the single bullet point after the heading
|
|
||||||
afterHeading = false;
|
|
||||||
pushCurrentItem();
|
|
||||||
currentItem = {
|
|
||||||
type: 'text',
|
|
||||||
content: strippedLine,
|
|
||||||
indent: lineIndent,
|
|
||||||
};
|
|
||||||
} else if (currentItem) {
|
|
||||||
if (currentItem.content.endsWith('\n')) {
|
|
||||||
currentItem.content += strippedLine;
|
|
||||||
} else {
|
|
||||||
currentItem.content += '\n' + strippedLine;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
currentItem = {
|
|
||||||
type: 'text',
|
|
||||||
content: strippedLine,
|
|
||||||
indent: lineIndent,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pushCurrentItem();
|
|
||||||
|
|
||||||
if (parsed.length === 0) return;
|
|
||||||
|
|
||||||
const line0 = parsed[0];
|
|
||||||
const baseIndent = line0.indent;
|
|
||||||
const isSingle = parsed.length === 1;
|
|
||||||
const line0Content = textBefore + line0.content + (isSingle ? textAfter : '');
|
|
||||||
|
|
||||||
const isCurrentEmpty = (currentBlock.content || '').trim() === '';
|
|
||||||
const adoptedType = line0.type !== 'text' ? line0.type : (isCurrentEmpty ? 'text' : currentBlock.type);
|
|
||||||
const adoptedChecked = line0.type === 'todo' ? (line0.checked ?? false) : currentBlock.checked;
|
|
||||||
|
|
||||||
const updatedCurrentBlock: DocumentBlock = {
|
|
||||||
...currentBlock,
|
|
||||||
content: line0Content,
|
|
||||||
type: adoptedType,
|
|
||||||
checked: adoptedChecked,
|
|
||||||
};
|
|
||||||
|
|
||||||
const newBlocks: DocumentBlock[] = [];
|
|
||||||
const nowBase = Date.now().toString(36);
|
|
||||||
|
|
||||||
for (let j = 1; j < parsed.length; j++) {
|
|
||||||
const p = parsed[j];
|
|
||||||
const isLastLine = j === parsed.length - 1;
|
|
||||||
const lineContent = isLastLine ? (p.content + textAfter) : p.content;
|
|
||||||
const lineLevel = Math.max(0, baseLevel + (p.indent - baseIndent));
|
|
||||||
|
|
||||||
newBlocks.push({
|
|
||||||
id: `blk_${nowBase}_${j}_${Math.random().toString(36).slice(2, 6)}`,
|
|
||||||
documentId: docId,
|
|
||||||
type: p.type,
|
|
||||||
checked: p.checked || false,
|
|
||||||
content: lineContent,
|
|
||||||
level: lineLevel,
|
|
||||||
collapsed: false,
|
|
||||||
position: (currentBlock.position || 1000) + j * 10,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const lastTargetId = newBlocks.length > 0 ? newBlocks[newBlocks.length - 1].id : currentBlock.id;
|
|
||||||
const existingEl = textareaMapRef.current.get(lastTargetId);
|
|
||||||
if (existingEl) {
|
|
||||||
pendingFocusRef.current = null;
|
|
||||||
focusBlockInput(lastTargetId, 'end');
|
|
||||||
} else {
|
|
||||||
pendingFocusRef.current = { blockId: lastTargetId, cursor: 'end' };
|
|
||||||
}
|
|
||||||
setFocusedBlockId(lastTargetId);
|
|
||||||
|
|
||||||
if (onInsertBlocks) {
|
|
||||||
onInsertBlocks(currentBlock.id, updatedCurrentBlock, newBlocks);
|
|
||||||
} else {
|
|
||||||
onUpdateBlock(updatedCurrentBlock, true);
|
|
||||||
for (let k = 0; k < newBlocks.length; k++) {
|
|
||||||
const afterId = k === 0 ? currentBlock.id : newBlocks[k - 1].id;
|
|
||||||
onCreateBlock(newBlocks[k], afterId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[blocks, canEdit, docId, focusBlockInput, onCreateBlock, onInsertBlocks, onUpdateBlock]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleDeleteBlock = useCallback(
|
|
||||||
(blockId: string, deleteSubtree = false) => {
|
|
||||||
if (!canEdit) return;
|
|
||||||
const idx = blocks.findIndex((b) => b.id === blockId);
|
|
||||||
if (idx === -1) return;
|
|
||||||
|
|
||||||
// If this is the only block in the document (and not in an isolated zoom subtree), clear instead of deleting
|
|
||||||
if (blocks.length <= 1 && !levelOffset) {
|
|
||||||
const only = blocks[0];
|
|
||||||
onUpdateBlock(
|
|
||||||
{
|
|
||||||
...only,
|
|
||||||
content: '',
|
|
||||||
type: 'text',
|
|
||||||
level: 0,
|
|
||||||
checked: false,
|
|
||||||
},
|
|
||||||
true
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const targetFocusBlock = idx > 0 ? blocks[idx - 1] : blocks[idx + 1];
|
|
||||||
if (targetFocusBlock) {
|
|
||||||
focusBlockInput(targetFocusBlock.id, 'end');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deleteSubtree) {
|
|
||||||
const rootLevel = blocks[idx].level || 0;
|
|
||||||
const idsToDelete = [blockId];
|
|
||||||
for (let j = idx + 1; j < blocks.length; j++) {
|
|
||||||
if ((blocks[j].level || 0) > rootLevel) {
|
|
||||||
idsToDelete.push(blocks[j].id);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const id of idsToDelete) {
|
|
||||||
onDeleteBlock(id);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
onDeleteBlock(blockId);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[blocks, canEdit, focusBlockInput, levelOffset, onDeleteBlock, onUpdateBlock]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleIndentBlock = useCallback(
|
|
||||||
(blockId: string, delta: 1 | -1) => {
|
|
||||||
if (!canEdit) return;
|
|
||||||
const idx = blocks.findIndex((b) => b.id === blockId);
|
|
||||||
if (idx === -1) return;
|
|
||||||
|
|
||||||
const current = blocks[idx];
|
|
||||||
const currentLevel = Math.max(0, current.level || 0);
|
|
||||||
const prevLevel = idx > 0 ? Math.max(0, blocks[idx - 1].level || 0) : 0;
|
|
||||||
const minLevel = levelOffset || 0;
|
|
||||||
const maxLevel = idx === 0 ? minLevel : prevLevel + 1;
|
|
||||||
|
|
||||||
const nextLevel =
|
|
||||||
delta === 1
|
|
||||||
? Math.min(maxLevel, currentLevel + 1)
|
|
||||||
: Math.max(minLevel, currentLevel - 1);
|
|
||||||
|
|
||||||
if (nextLevel === currentLevel) return;
|
|
||||||
|
|
||||||
const actualDelta = nextLevel - currentLevel;
|
|
||||||
|
|
||||||
// Find all contiguous children / descendants:
|
|
||||||
// contiguous blocks with level > currentLevel
|
|
||||||
let count = 1;
|
|
||||||
for (let i = idx + 1; i < blocks.length; i++) {
|
|
||||||
if (Math.max(0, blocks[i].level || 0) > currentLevel) {
|
|
||||||
count++;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedBlocks: DocumentBlock[] = [];
|
|
||||||
for (let i = idx; i < idx + count; i++) {
|
|
||||||
const b = blocks[i];
|
|
||||||
const newLvl = Math.max(minLevel, (b.level || 0) + actualDelta);
|
|
||||||
updatedBlocks.push({
|
|
||||||
...b,
|
|
||||||
level: newLvl,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onUpdateBlocks) {
|
|
||||||
onUpdateBlocks(updatedBlocks);
|
|
||||||
} else {
|
|
||||||
for (const b of updatedBlocks) {
|
|
||||||
onUpdateBlock(b, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[blocks, canEdit, levelOffset, onUpdateBlock, onUpdateBlocks]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleNavigateFocus = useCallback(
|
|
||||||
(blockId: string, direction: 'up' | 'down') => {
|
|
||||||
const visIdx = visibleEntries.findIndex((e) => e.block.id === blockId);
|
|
||||||
if (visIdx === -1) return;
|
|
||||||
const targetEntry =
|
|
||||||
direction === 'up' ? visibleEntries[visIdx - 1] : visibleEntries[visIdx + 1];
|
|
||||||
if (targetEntry) {
|
|
||||||
focusBlockInput(
|
|
||||||
targetEntry.block.id,
|
|
||||||
direction === 'up' ? 'end' : 'start'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[focusBlockInput, visibleEntries]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleDragStartBlock = useCallback((index: number) => {
|
|
||||||
setDraggedIndex(index);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleDragOverBlock = useCallback(
|
|
||||||
(e: React.DragEvent, index: number) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (draggedIndex !== null) {
|
|
||||||
const parentLevel = Math.max(0, blocks[draggedIndex]?.level || 0);
|
|
||||||
let count = 1;
|
|
||||||
for (let i = draggedIndex + 1; i < blocks.length; i++) {
|
|
||||||
if (Math.max(0, blocks[i].level || 0) > parentLevel) {
|
|
||||||
count++;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Do not allow dropping inside its own subtree (self or descendants)
|
|
||||||
if (index >= draggedIndex && index < draggedIndex + count) {
|
|
||||||
setDragOverIndex(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setDragOverIndex(index);
|
|
||||||
},
|
|
||||||
[blocks, draggedIndex]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleDropBlock = useCallback(
|
|
||||||
(targetIndex: number) => {
|
|
||||||
if (draggedIndex === null || draggedIndex === targetIndex) {
|
|
||||||
setDraggedIndex(null);
|
|
||||||
setDragOverIndex(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const parentLevel = Math.max(0, blocks[draggedIndex]?.level || 0);
|
|
||||||
let count = 1;
|
|
||||||
for (let i = draggedIndex + 1; i < blocks.length; i++) {
|
|
||||||
if (Math.max(0, blocks[i].level || 0) > parentLevel) {
|
|
||||||
count++;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (targetIndex >= draggedIndex && targetIndex < draggedIndex + count) {
|
|
||||||
setDraggedIndex(null);
|
|
||||||
setDragOverIndex(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const movingBlock = blocks[draggedIndex];
|
|
||||||
if (movingBlock) {
|
|
||||||
onMoveBlock(movingBlock.id, targetIndex, movingBlock.level);
|
|
||||||
}
|
|
||||||
setDraggedIndex(null);
|
|
||||||
setDragOverIndex(null);
|
|
||||||
},
|
|
||||||
[blocks, draggedIndex, onMoveBlock]
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const clearDrag = () => {
|
|
||||||
setDraggedIndex(null);
|
|
||||||
setDragOverIndex(null);
|
|
||||||
};
|
|
||||||
window.addEventListener('dragend', clearDrag);
|
|
||||||
return () => window.removeEventListener('dragend', clearDrag);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-0.5">
|
|
||||||
{visibleEntries.map(({ block, index, hasChildren, maxAllowedLevel }, entryIdx) => {
|
|
||||||
const isLast = entryIdx === visibleEntries.length - 1;
|
|
||||||
return (
|
|
||||||
<OutlinerBlock
|
|
||||||
key={block.id}
|
|
||||||
docId={docId}
|
|
||||||
block={block}
|
|
||||||
index={index}
|
|
||||||
isLast={isLast}
|
|
||||||
maxAllowedLevel={maxAllowedLevel}
|
|
||||||
hasChildren={hasChildren}
|
|
||||||
isFocused={focusedBlockId === block.id}
|
|
||||||
canEdit={canEdit}
|
|
||||||
levelOffset={levelOffset}
|
|
||||||
onZoomBlock={onZoomBlock}
|
|
||||||
onUpdateBlock={onUpdateBlock}
|
|
||||||
onCreateBlockBelow={handleCreateBlockBelow}
|
|
||||||
onPasteMultiLines={handlePasteMultiLines}
|
|
||||||
onDeleteBlock={handleDeleteBlock}
|
|
||||||
onIndentBlock={handleIndentBlock}
|
|
||||||
onNavigateFocus={handleNavigateFocus}
|
|
||||||
onFocusBlock={setFocusedBlockId}
|
|
||||||
onOpenTask={onOpenTask}
|
|
||||||
onTagClick={onTagClick}
|
|
||||||
onWikiLinkClick={onWikiLinkClick}
|
|
||||||
onDragStartBlock={handleDragStartBlock}
|
|
||||||
onDragOverBlock={handleDragOverBlock}
|
|
||||||
onDropBlock={handleDropBlock}
|
|
||||||
isDragTarget={dragOverIndex === index && draggedIndex !== index}
|
|
||||||
isTargeted={highlightedBlockId === block.id}
|
|
||||||
registerTextareaRef={registerTextareaRef}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
|
|
||||||
{canEdit && (
|
|
||||||
<div
|
|
||||||
className={`min-h-[14rem] pt-2 pl-2 transition-colors cursor-text ${
|
|
||||||
dragOverIndex === blocks.length ? 'border-t-2 border-accent bg-accent/10 rounded' : ''
|
|
||||||
}`}
|
|
||||||
onClick={(e) => {
|
|
||||||
if (e.target !== e.currentTarget && (e.target as HTMLElement).closest('button, a, input, textarea, select')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (blocks.length === 0) {
|
|
||||||
const firstBlock: DocumentBlock = {
|
|
||||||
id: `blk_${Date.now().toString(36)}_0`,
|
|
||||||
documentId: docId,
|
|
||||||
type: 'text',
|
|
||||||
content: '',
|
|
||||||
level: levelOffset || 0,
|
|
||||||
position: 1000,
|
|
||||||
};
|
|
||||||
pendingFocusRef.current = { blockId: firstBlock.id, cursor: 'start' };
|
|
||||||
onCreateBlock(firstBlock);
|
|
||||||
} else {
|
|
||||||
const lastBlock = blocks[blocks.length - 1];
|
|
||||||
if (lastBlock.content && lastBlock.content.trim() !== '') {
|
|
||||||
handleCreateBlockBelow(lastBlock.id, '');
|
|
||||||
} else {
|
|
||||||
focusBlockInput(lastBlock.id, 'end');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onDragOver={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
if (draggedIndex !== null) {
|
|
||||||
setDragOverIndex(blocks.length);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onDrop={() => handleDropBlock(blocks.length)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
File diff suppressed because it is too large.
Load diff
+66
-378
@@ -5,6 +5,7 @@ import {
|
|||||||
Document,
|
Document,
|
||||||
DocumentBlock,
|
DocumentBlock,
|
||||||
DocShare,
|
DocShare,
|
||||||
|
DocLockInfo,
|
||||||
KanbanColumn,
|
KanbanColumn,
|
||||||
ListItem,
|
ListItem,
|
||||||
ListShare,
|
ListShare,
|
||||||
@@ -36,19 +37,6 @@ export function getToken(): string | null {
|
|||||||
return localStorage.getItem(TOKEN_STORAGE_KEY);
|
return localStorage.getItem(TOKEN_STORAGE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCurrentUserId(): string | null {
|
|
||||||
const token = getToken();
|
|
||||||
if (!token) return null;
|
|
||||||
try {
|
|
||||||
const parts = token.split('.');
|
|
||||||
if (parts.length >= 2) {
|
|
||||||
const payload = JSON.parse(atob(parts[1]));
|
|
||||||
return payload.userId || payload.sub || payload.id || null;
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setToken(token: string): void {
|
export function setToken(token: string): void {
|
||||||
localStorage.setItem(TOKEN_STORAGE_KEY, token);
|
localStorage.setItem(TOKEN_STORAGE_KEY, token);
|
||||||
}
|
}
|
||||||
@@ -129,18 +117,6 @@ export const api = {
|
|||||||
return request<AuthStatus>('/api/v1/auth/status');
|
return request<AuthStatus>('/api/v1/auth/status');
|
||||||
},
|
},
|
||||||
|
|
||||||
async logout(): Promise<void> {
|
|
||||||
try {
|
|
||||||
await request<{ success: boolean }>('/api/v1/auth/logout', { method: 'POST' });
|
|
||||||
} finally {
|
|
||||||
clearToken();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async revokeAllSessions(): Promise<void> {
|
|
||||||
await request<{ success: boolean }>('/api/v1/auth/revoke-all', { method: 'POST' });
|
|
||||||
},
|
|
||||||
|
|
||||||
async completeSetup(payload: {
|
async completeSetup(payload: {
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
@@ -309,10 +285,6 @@ export const api = {
|
|||||||
return ensureArray(res);
|
return ensureArray(res);
|
||||||
},
|
},
|
||||||
|
|
||||||
async getThought(thoughtId: string): Promise<Thought> {
|
|
||||||
return request<Thought>(`/api/v1/thoughts/${encodeURIComponent(thoughtId)}`);
|
|
||||||
},
|
|
||||||
|
|
||||||
async triageAction(
|
async triageAction(
|
||||||
thoughtId: string,
|
thoughtId: string,
|
||||||
action: 'keep' | 'discard' | 'restore',
|
action: 'keep' | 'discard' | 'restore',
|
||||||
@@ -430,7 +402,7 @@ export const api = {
|
|||||||
|
|
||||||
async addTaskListShare(
|
async addTaskListShare(
|
||||||
id: string,
|
id: string,
|
||||||
payload: { targetType: 'team' | 'user'; targetId: string; permission?: 'editor' | 'viewer' }
|
payload: { targetType: 'team' | 'user'; targetId: string }
|
||||||
): Promise<TaskListShare> {
|
): Promise<TaskListShare> {
|
||||||
return request<TaskListShare>(`/api/v1/task-lists/${id}/shares`, {
|
return request<TaskListShare>(`/api/v1/task-lists/${id}/shares`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -630,13 +602,6 @@ export const api = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async joinSSERoom(sseId: string, room: string, action: 'join' | 'leave' = 'join'): Promise<{ success: boolean }> {
|
|
||||||
return request<{ success: boolean }>('/api/v1/events/rooms', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({ sseId, room, action }),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
async deleteDocument(id: string): Promise<void> {
|
async deleteDocument(id: string): Promise<void> {
|
||||||
await request(`/api/v1/documents/${id}`, { method: 'DELETE' });
|
await request(`/api/v1/documents/${id}`, { method: 'DELETE' });
|
||||||
},
|
},
|
||||||
@@ -653,23 +618,6 @@ export const api = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async createEnhancedTask(
|
|
||||||
docId: string,
|
|
||||||
blockId: string,
|
|
||||||
payload: { content: string; checked: boolean }
|
|
||||||
): Promise<Thought> {
|
|
||||||
return request<Thought>(`/api/v1/documents/${docId}/blocks/${blockId}/enhanced-task`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
async unlinkEnhancedTask(taskId: string): Promise<{ unlinked: boolean }> {
|
|
||||||
return request<{ unlinked: boolean }>(`/api/v1/tasks/${encodeURIComponent(taskId)}/unlink`, {
|
|
||||||
method: 'POST',
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// --- DOCUMENT SHARING ---
|
// --- DOCUMENT SHARING ---
|
||||||
async getDocShares(docId: string): Promise<DocShare[]> {
|
async getDocShares(docId: string): Promise<DocShare[]> {
|
||||||
const res = await request<DocShare[]>(`/api/v1/documents/${docId}/shares`);
|
const res = await request<DocShare[]>(`/api/v1/documents/${docId}/shares`);
|
||||||
@@ -695,6 +643,44 @@ export const api = {
|
|||||||
return ensureArray(res);
|
return ensureArray(res);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// --- DOCUMENT LOCKING ---
|
||||||
|
async getDocLock(docId: string): Promise<{ locked: boolean; lock?: DocLockInfo }> {
|
||||||
|
return request<{ locked: boolean; lock?: DocLockInfo }>(`/api/v1/documents/${docId}/lock`);
|
||||||
|
},
|
||||||
|
|
||||||
|
async lockDocument(
|
||||||
|
docId: string
|
||||||
|
): Promise<{ locked: boolean; acquired: boolean; lock?: DocLockInfo; message?: string }> {
|
||||||
|
try {
|
||||||
|
return await request<{ locked: boolean; acquired: boolean; lock?: DocLockInfo; message?: string }>(
|
||||||
|
`/api/v1/documents/${docId}/lock`,
|
||||||
|
{ method: 'POST' }
|
||||||
|
);
|
||||||
|
} catch (e: any) {
|
||||||
|
return { locked: true, acquired: false, message: e.message };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async heartbeatDocLock(docId: string): Promise<{ extended: boolean }> {
|
||||||
|
try {
|
||||||
|
return await request<{ extended: boolean }>(`/api/v1/documents/${docId}/lock/heartbeat`, {
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
return { extended: false };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async unlockDocument(docId: string): Promise<{ unlocked: boolean }> {
|
||||||
|
try {
|
||||||
|
return await request<{ unlocked: boolean }>(`/api/v1/documents/${docId}/lock`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
return { unlocked: false };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// --- SPACES & REALTIME LISTS ---
|
// --- SPACES & REALTIME LISTS ---
|
||||||
async getSpaces(): Promise<Space[]> {
|
async getSpaces(): Promise<Space[]> {
|
||||||
const res = await request<Space[]>('/api/v1/spaces');
|
const res = await request<Space[]>('/api/v1/spaces');
|
||||||
@@ -817,17 +803,6 @@ export const api = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async updateListItem(
|
|
||||||
listId: string,
|
|
||||||
itemId: string,
|
|
||||||
payload: { content?: string; category?: string; quantity?: string }
|
|
||||||
): Promise<ListItem> {
|
|
||||||
return request<ListItem>(`/api/v1/lists/${listId}/items/${itemId}`, {
|
|
||||||
method: 'PUT',
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
async deleteListItem(listId: string, itemId: string): Promise<void> {
|
async deleteListItem(listId: string, itemId: string): Promise<void> {
|
||||||
await request(`/api/v1/lists/${listId}/items/${itemId}`, { method: 'DELETE' });
|
await request(`/api/v1/lists/${listId}/items/${itemId}`, { method: 'DELETE' });
|
||||||
},
|
},
|
||||||
@@ -1067,17 +1042,11 @@ export function getOfflineQueue(): Thought[] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RealtimeTransport = 'ws' | 'sse' | 'none';
|
|
||||||
|
|
||||||
let activeTransport: RealtimeTransport = 'none';
|
|
||||||
let activeGlobalWS: WebSocket | null = null;
|
let activeGlobalWS: WebSocket | null = null;
|
||||||
let activeGlobalSSE: EventSource | null = null;
|
|
||||||
let activeSSEId: string | null = null;
|
|
||||||
let wsReconnectTimer: any = null;
|
let wsReconnectTimer: any = null;
|
||||||
let wsConnectionWatchdog: any = null;
|
|
||||||
let wsListeners: ((msg: WSMessage) => void)[] = [];
|
let wsListeners: ((msg: WSMessage) => void)[] = [];
|
||||||
let realtimeStatusListeners: ((connected: boolean, transport: RealtimeTransport) => void)[] = [];
|
let wsStatusListeners: ((connected: boolean) => void)[] = [];
|
||||||
let isRealtimeConnectedState = false;
|
let isWSConnected = false;
|
||||||
let manualDisconnect = false;
|
let manualDisconnect = false;
|
||||||
let wsReconnectDelay = 2000;
|
let wsReconnectDelay = 2000;
|
||||||
|
|
||||||
@@ -1090,160 +1059,28 @@ export function buildWebSocketURL(listId?: string): string {
|
|||||||
return `${protocol}//${window.location.host}/api/v1/ws?token=${encodeURIComponent(token)}`;
|
return `${protocol}//${window.location.host}/api/v1/ws?token=${encodeURIComponent(token)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildSSEURL(listId?: string, docId?: string, rooms?: string[]): string {
|
|
||||||
const token = getToken() || '';
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
if (token) params.set('token', token);
|
|
||||||
if (listId) params.set('listId', listId);
|
|
||||||
if (docId) params.set('docId', docId);
|
|
||||||
if (rooms && rooms.length > 0) params.set('rooms', rooms.join(','));
|
|
||||||
return `/api/v1/events?${params.toString()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isWebSocketConnected(): boolean {
|
export function isWebSocketConnected(): boolean {
|
||||||
return activeTransport === 'ws' && activeGlobalWS !== null && activeGlobalWS.readyState === WebSocket.OPEN;
|
return isWSConnected && activeGlobalWS !== null && activeGlobalWS.readyState === WebSocket.OPEN;
|
||||||
}
|
|
||||||
|
|
||||||
export function isRealtimeConnected(): boolean {
|
|
||||||
return isRealtimeConnectedState;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getRealtimeTransport(): RealtimeTransport {
|
|
||||||
return activeTransport;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getSSEId(): string | null {
|
|
||||||
return activeSSEId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onWebSocketStatus(callback: (connected: boolean) => void): () => void {
|
export function onWebSocketStatus(callback: (connected: boolean) => void): () => void {
|
||||||
const wrapper = (connected: boolean) => callback(connected);
|
wsStatusListeners.push(callback);
|
||||||
realtimeStatusListeners.push(wrapper);
|
callback(isWebSocketConnected());
|
||||||
callback(isRealtimeConnected());
|
|
||||||
return () => {
|
return () => {
|
||||||
realtimeStatusListeners = realtimeStatusListeners.filter((fn) => fn !== wrapper);
|
wsStatusListeners = wsStatusListeners.filter((fn) => fn !== callback);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onRealtimeStatus(callback: (connected: boolean, transport: RealtimeTransport) => void): () => void {
|
function notifyStatusChange(connected: boolean) {
|
||||||
realtimeStatusListeners.push(callback);
|
isWSConnected = connected;
|
||||||
callback(isRealtimeConnected(), activeTransport);
|
wsStatusListeners.forEach((fn) => {
|
||||||
return () => {
|
|
||||||
realtimeStatusListeners = realtimeStatusListeners.filter((fn) => fn !== callback);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let isWsBlockedByProxy = typeof window !== 'undefined' && sessionStorage.getItem('mindsift_ws_blocked') === 'true';
|
|
||||||
let sseReconnectTimer: any = null;
|
|
||||||
let sseReconnectDelay = 2000;
|
|
||||||
const globalSubscribedRooms = new Set<string>();
|
|
||||||
|
|
||||||
function notifyRealtimeStatusChange(connected: boolean, transport: RealtimeTransport) {
|
|
||||||
isRealtimeConnectedState = connected;
|
|
||||||
activeTransport = transport;
|
|
||||||
realtimeStatusListeners.forEach((fn) => {
|
|
||||||
try {
|
try {
|
||||||
fn(connected, transport);
|
fn(connected);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Realtime status listener error', e);
|
console.error('WS status listener error', e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.dispatchEvent(new CustomEvent('mindsift:ws:status', { detail: { connected, transport } }));
|
window.dispatchEvent(new CustomEvent('mindsift:ws:status', { detail: { connected } }));
|
||||||
}
|
|
||||||
|
|
||||||
function switchToSSE(reason: string) {
|
|
||||||
console.warn(`[MindSift Realtime] ${reason} -> Schalte sofort und dauerhaft auf Server-Sent Events (SSE) um.`);
|
|
||||||
isWsBlockedByProxy = true;
|
|
||||||
try {
|
|
||||||
sessionStorage.setItem('mindsift_ws_blocked', 'true');
|
|
||||||
} catch {}
|
|
||||||
clearTimeout(wsConnectionWatchdog);
|
|
||||||
clearTimeout(wsReconnectTimer);
|
|
||||||
if (activeGlobalWS) {
|
|
||||||
try {
|
|
||||||
activeGlobalWS.onclose = null;
|
|
||||||
activeGlobalWS.onerror = null;
|
|
||||||
activeGlobalWS.close();
|
|
||||||
} catch {}
|
|
||||||
activeGlobalWS = null;
|
|
||||||
}
|
|
||||||
connectSSE();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function connectSSE(rooms?: string[]): void {
|
|
||||||
if (rooms) {
|
|
||||||
rooms.forEach((r) => globalSubscribedRooms.add(r));
|
|
||||||
}
|
|
||||||
clearTimeout(sseReconnectTimer);
|
|
||||||
clearTimeout(wsReconnectTimer);
|
|
||||||
clearTimeout(wsConnectionWatchdog);
|
|
||||||
|
|
||||||
if (activeGlobalSSE) {
|
|
||||||
try { activeGlobalSSE.close(); } catch {}
|
|
||||||
activeGlobalSSE = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const url = buildSSEURL(undefined, undefined, Array.from(globalSubscribedRooms));
|
|
||||||
const es = new EventSource(url);
|
|
||||||
activeGlobalSSE = es;
|
|
||||||
|
|
||||||
es.onopen = () => {
|
|
||||||
sseReconnectDelay = 2000;
|
|
||||||
notifyRealtimeStatusChange(true, 'sse');
|
|
||||||
if (activeSSEId && globalSubscribedRooms.size > 0) {
|
|
||||||
globalSubscribedRooms.forEach((room) => {
|
|
||||||
api.joinSSERoom(activeSSEId!, room, 'join').catch(() => {});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
es.onmessage = (event) => {
|
|
||||||
try {
|
|
||||||
const msg = JSON.parse(event.data) as WSMessage;
|
|
||||||
if (msg.event === 'SSE_CONNECTED') {
|
|
||||||
activeSSEId = msg.payload?.sseId || null;
|
|
||||||
if (activeSSEId && globalSubscribedRooms.size > 0) {
|
|
||||||
globalSubscribedRooms.forEach((room) => {
|
|
||||||
api.joinSSERoom(activeSSEId!, room, 'join').catch(() => {});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wsListeners.forEach((fn) => {
|
|
||||||
try {
|
|
||||||
fn(msg);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('SSE listener error', e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
window.dispatchEvent(new CustomEvent('mindsift:ws', { detail: msg }));
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to parse SSE message', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
es.onerror = (e) => {
|
|
||||||
console.warn('[MindSift Realtime] SSE Verbindungsfehler:', e);
|
|
||||||
if (activeTransport === 'sse') {
|
|
||||||
notifyRealtimeStatusChange(false, 'none');
|
|
||||||
}
|
|
||||||
try { es.close(); } catch {}
|
|
||||||
activeGlobalSSE = null;
|
|
||||||
if (!manualDisconnect && getToken()) {
|
|
||||||
clearTimeout(sseReconnectTimer);
|
|
||||||
const delay = sseReconnectDelay;
|
|
||||||
sseReconnectDelay = Math.min(30000, Math.round(sseReconnectDelay * 1.5));
|
|
||||||
sseReconnectTimer = setTimeout(() => {
|
|
||||||
if (!manualDisconnect && getToken()) {
|
|
||||||
connectSSE();
|
|
||||||
}
|
|
||||||
}, delay);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to initialize EventSource SSE', err);
|
|
||||||
notifyRealtimeStatusChange(false, 'none');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function connectWebSocket(): void {
|
export function connectWebSocket(): void {
|
||||||
@@ -1251,47 +1088,18 @@ export function connectWebSocket(): void {
|
|||||||
if (!token) return;
|
if (!token) return;
|
||||||
manualDisconnect = false;
|
manualDisconnect = false;
|
||||||
|
|
||||||
// If proxy blocked WebSocket previously, do not attempt failing WebSocket; stay on SSE
|
|
||||||
if (isWsBlockedByProxy) {
|
|
||||||
connectSSE();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeGlobalWS && (activeGlobalWS.readyState === WebSocket.OPEN || activeGlobalWS.readyState === WebSocket.CONNECTING)) {
|
if (activeGlobalWS && (activeGlobalWS.readyState === WebSocket.OPEN || activeGlobalWS.readyState === WebSocket.CONNECTING)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearTimeout(wsConnectionWatchdog);
|
|
||||||
clearTimeout(wsReconnectTimer);
|
|
||||||
clearTimeout(sseReconnectTimer);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = buildWebSocketURL();
|
const url = buildWebSocketURL();
|
||||||
const ws = new WebSocket(url);
|
const ws = new WebSocket(url);
|
||||||
activeGlobalWS = ws;
|
activeGlobalWS = ws;
|
||||||
|
|
||||||
// 2.5s watchdog for corporate proxies silently stripping Upgrade header or hanging
|
|
||||||
wsConnectionWatchdog = setTimeout(() => {
|
|
||||||
if (ws && ws.readyState !== WebSocket.OPEN) {
|
|
||||||
switchToSSE('WebSocket Timeout nach 2.5s (Proxy Upgrade Header blockiert)');
|
|
||||||
}
|
|
||||||
}, 2500);
|
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
clearTimeout(wsConnectionWatchdog);
|
|
||||||
if (activeGlobalSSE) {
|
|
||||||
try { activeGlobalSSE.close(); } catch {}
|
|
||||||
activeGlobalSSE = null;
|
|
||||||
}
|
|
||||||
wsReconnectDelay = 2000;
|
wsReconnectDelay = 2000;
|
||||||
notifyRealtimeStatusChange(true, 'ws');
|
notifyStatusChange(true);
|
||||||
if (globalSubscribedRooms.size > 0) {
|
|
||||||
globalSubscribedRooms.forEach((room) => {
|
|
||||||
try {
|
|
||||||
ws.send(JSON.stringify({ event: 'JOIN_ROOM', room }));
|
|
||||||
} catch {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = (event) => {
|
ws.onmessage = (event) => {
|
||||||
@@ -1311,98 +1119,61 @@ export function connectWebSocket(): void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = (evt: CloseEvent) => {
|
ws.onclose = (evt: CloseEvent) => {
|
||||||
clearTimeout(wsConnectionWatchdog);
|
|
||||||
activeGlobalWS = null;
|
activeGlobalWS = null;
|
||||||
|
console.warn('[MindSift Global WS] Closed with code:', evt?.code, 'reason:', evt?.reason);
|
||||||
// In corporate environments, blocked WebSockets close abruptly without clean handshake
|
notifyStatusChange(false);
|
||||||
if (!evt.wasClean || evt.code === 1006 || evt.code === 1002 || evt.code === 1008 || evt.code === 1005) {
|
if (!manualDisconnect && getToken()) {
|
||||||
switchToSSE(`WebSocket unsauber beendet (Code ${evt.code}, wasClean=${evt.wasClean})`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeTransport === 'ws') {
|
|
||||||
notifyRealtimeStatusChange(false, 'none');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!manualDisconnect && getToken() && activeTransport !== 'sse') {
|
|
||||||
clearTimeout(wsReconnectTimer);
|
clearTimeout(wsReconnectTimer);
|
||||||
const delay = wsReconnectDelay;
|
const delay = wsReconnectDelay;
|
||||||
wsReconnectDelay = Math.min(30000, Math.round(wsReconnectDelay * 1.5));
|
wsReconnectDelay = Math.min(30000, Math.round(wsReconnectDelay * 1.5));
|
||||||
wsReconnectTimer = setTimeout(() => {
|
wsReconnectTimer = setTimeout(() => {
|
||||||
if (!manualDisconnect && getToken()) {
|
|
||||||
connectWebSocket();
|
connectWebSocket();
|
||||||
}
|
|
||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = (e) => {
|
ws.onerror = (e) => {
|
||||||
clearTimeout(wsConnectionWatchdog);
|
console.warn('[MindSift Global WS] Error:', e);
|
||||||
switchToSSE('WebSocket Fehler (Handshake/Verbindung verweigert)');
|
notifyStatusChange(false);
|
||||||
|
try {
|
||||||
|
ws.close();
|
||||||
|
} catch {}
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
switchToSSE('WebSocket Exception beim Initialisieren');
|
console.error('Failed to connect WebSocket', e);
|
||||||
|
notifyStatusChange(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure reconnect when browser recovers from sleep or tab visibility
|
// Ensure reconnect when browser recovers from sleep or tab visibility
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
window.addEventListener('online', () => {
|
window.addEventListener('online', () => {
|
||||||
if (getToken() && !isRealtimeConnected()) {
|
if (getToken() && !isWebSocketConnected()) {
|
||||||
if (isWsBlockedByProxy) {
|
|
||||||
connectSSE();
|
|
||||||
} else {
|
|
||||||
connectWebSocket();
|
connectWebSocket();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
document.addEventListener('visibilitychange', () => {
|
document.addEventListener('visibilitychange', () => {
|
||||||
if (document.visibilityState === 'visible' && getToken() && !isRealtimeConnected()) {
|
if (document.visibilityState === 'visible' && getToken() && !isWebSocketConnected()) {
|
||||||
if (isWsBlockedByProxy) {
|
|
||||||
connectSSE();
|
|
||||||
} else {
|
|
||||||
connectWebSocket();
|
connectWebSocket();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function disconnectWebSocket(): void {
|
export function disconnectWebSocket(): void {
|
||||||
manualDisconnect = true;
|
manualDisconnect = true;
|
||||||
clearTimeout(wsReconnectTimer);
|
clearTimeout(wsReconnectTimer);
|
||||||
clearTimeout(wsConnectionWatchdog);
|
|
||||||
clearTimeout(sseReconnectTimer);
|
|
||||||
if (activeGlobalWS) {
|
if (activeGlobalWS) {
|
||||||
try {
|
try {
|
||||||
activeGlobalWS.close();
|
activeGlobalWS.close();
|
||||||
} catch {}
|
} catch {}
|
||||||
activeGlobalWS = null;
|
activeGlobalWS = null;
|
||||||
}
|
}
|
||||||
if (activeGlobalSSE) {
|
notifyStatusChange(false);
|
||||||
try {
|
|
||||||
activeGlobalSSE.close();
|
|
||||||
} catch {}
|
|
||||||
activeGlobalSSE = null;
|
|
||||||
}
|
|
||||||
notifyRealtimeStatusChange(false, 'none');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendWebSocketMessage(msg: any): void {
|
export function sendWebSocketMessage(msg: any): void {
|
||||||
if (activeGlobalWS && activeGlobalWS.readyState === WebSocket.OPEN) {
|
if (activeGlobalWS && activeGlobalWS.readyState === WebSocket.OPEN) {
|
||||||
activeGlobalWS.send(typeof msg === 'string' ? msg : JSON.stringify(msg));
|
activeGlobalWS.send(typeof msg === 'string' ? msg : JSON.stringify(msg));
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SSE Fallback: dispatch via REST endpoints
|
|
||||||
try {
|
|
||||||
const parsed = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
|
||||||
if (parsed.event === 'JOIN_ROOM' && parsed.room) {
|
|
||||||
if (activeSSEId) api.joinSSERoom(activeSSEId, parsed.room, 'join').catch(() => {});
|
|
||||||
} else if (parsed.event === 'LEAVE_ROOM' && parsed.room) {
|
|
||||||
if (activeSSEId) api.joinSSERoom(activeSSEId, parsed.room, 'leave').catch(() => {});
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error dispatching fallback REST message for SSE:', err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1412,86 +1183,3 @@ export function onWebSocketMessage(callback: (msg: WSMessage) => void): () => vo
|
|||||||
wsListeners = wsListeners.filter((fn) => fn !== callback);
|
wsListeners = wsListeners.filter((fn) => fn !== callback);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createRealtimeConnection(options: {
|
|
||||||
listId?: string;
|
|
||||||
docId?: string;
|
|
||||||
rooms?: string[];
|
|
||||||
onMessage?: (msg: WSMessage) => void;
|
|
||||||
onStatusChange?: (status: { connected: boolean; transport: RealtimeTransport; reason?: string }) => void;
|
|
||||||
}) {
|
|
||||||
let isClosed = false;
|
|
||||||
|
|
||||||
const joinedRooms: string[] = [];
|
|
||||||
if (options.docId) joinedRooms.push(`doc:${options.docId}`);
|
|
||||||
if (options.listId) joinedRooms.push(options.listId);
|
|
||||||
if (options.rooms) {
|
|
||||||
options.rooms.forEach((r) => {
|
|
||||||
if (!joinedRooms.includes(r)) joinedRooms.push(r);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
joinedRooms.forEach((r) => globalSubscribedRooms.add(r));
|
|
||||||
|
|
||||||
// Subscribe to status changes
|
|
||||||
const unsubStatus = onRealtimeStatus((connected, transport) => {
|
|
||||||
if (isClosed) return;
|
|
||||||
options.onStatusChange?.({
|
|
||||||
connected,
|
|
||||||
transport,
|
|
||||||
reason: connected ? undefined : 'Verbindung getrennt',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Subscribe to messages
|
|
||||||
let unsubMsg: (() => void) | null = null;
|
|
||||||
if (options.onMessage) {
|
|
||||||
unsubMsg = onWebSocketMessage((msg) => {
|
|
||||||
if (isClosed) return;
|
|
||||||
options.onMessage?.(msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Join rooms on the active connection
|
|
||||||
const joinAll = () => {
|
|
||||||
joinedRooms.forEach((r) => {
|
|
||||||
sendWebSocketMessage({ event: 'JOIN_ROOM', room: r });
|
|
||||||
if (activeSSEId) {
|
|
||||||
api.joinSSERoom(activeSSEId, r, 'join').catch(() => {});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (isRealtimeConnected()) {
|
|
||||||
joinAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsubRejoin = onRealtimeStatus((connected) => {
|
|
||||||
if (isClosed) return;
|
|
||||||
if (connected) {
|
|
||||||
joinAll();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
getTransport: () => activeTransport,
|
|
||||||
isConnected: () => isRealtimeConnected(),
|
|
||||||
send: (msg: any) => {
|
|
||||||
if (isClosed) return;
|
|
||||||
sendWebSocketMessage(msg);
|
|
||||||
},
|
|
||||||
close: () => {
|
|
||||||
isClosed = true;
|
|
||||||
unsubStatus();
|
|
||||||
unsubRejoin();
|
|
||||||
if (unsubMsg) unsubMsg();
|
|
||||||
joinedRooms.forEach((r) => {
|
|
||||||
globalSubscribedRooms.delete(r);
|
|
||||||
sendWebSocketMessage({ event: 'LEAVE_ROOM', room: r });
|
|
||||||
if (activeSSEId) {
|
|
||||||
api.joinSSERoom(activeSSEId, r, 'leave').catch(() => {});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,228 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses inline markdown:
|
|
||||||
* - **bold** or __bold__
|
|
||||||
* - *italic* or _italic_
|
|
||||||
* - ~~strikethrough~~
|
|
||||||
* - `code`
|
|
||||||
* - [label](url)
|
|
||||||
*/
|
|
||||||
function renderInlineTokens(text: string): React.ReactNode[] {
|
|
||||||
if (!text) return [];
|
|
||||||
|
|
||||||
const regex = /(`[^`]+`|\*\*[^*]+\*\*|__[^_]+__|~~[^~]+~~|\*[^*]+\*|_[^_]+_|\[([^\]]+)\]\(([^)]+)\))/g;
|
|
||||||
|
|
||||||
const elements: React.ReactNode[] = [];
|
|
||||||
let lastIndex = 0;
|
|
||||||
let match: RegExpExecArray | null;
|
|
||||||
|
|
||||||
while ((match = regex.exec(text)) !== null) {
|
|
||||||
if (match.index > lastIndex) {
|
|
||||||
elements.push(text.slice(lastIndex, match.index));
|
|
||||||
}
|
|
||||||
const token = match[0];
|
|
||||||
const key = `${match.index}-${token}`;
|
|
||||||
|
|
||||||
if (token.startsWith('`') && token.endsWith('`')) {
|
|
||||||
elements.push(
|
|
||||||
<code key={key} className="px-1.5 py-0.5 rounded bg-panel-elevated text-accent font-mono text-[0.9em] border border-border/50">
|
|
||||||
{token.slice(1, -1)}
|
|
||||||
</code>
|
|
||||||
);
|
|
||||||
} else if (
|
|
||||||
(token.startsWith('**') && token.endsWith('**')) ||
|
|
||||||
(token.startsWith('__') && token.endsWith('__'))
|
|
||||||
) {
|
|
||||||
elements.push(
|
|
||||||
<strong key={key} className="font-semibold text-main">
|
|
||||||
{token.slice(2, -2)}
|
|
||||||
</strong>
|
|
||||||
);
|
|
||||||
} else if (
|
|
||||||
(token.startsWith('*') && token.endsWith('*')) ||
|
|
||||||
(token.startsWith('_') && token.endsWith('_'))
|
|
||||||
) {
|
|
||||||
elements.push(
|
|
||||||
<em key={key} className="italic text-main/90">
|
|
||||||
{token.slice(1, -1)}
|
|
||||||
</em>
|
|
||||||
);
|
|
||||||
} else if (token.startsWith('~~') && token.endsWith('~~')) {
|
|
||||||
elements.push(
|
|
||||||
<del key={key} className="line-through text-muted/80">
|
|
||||||
{token.slice(2, -2)}
|
|
||||||
</del>
|
|
||||||
);
|
|
||||||
} else if (token.startsWith('[') && match[2] && match[3]) {
|
|
||||||
const label = match[2];
|
|
||||||
const url = match[3];
|
|
||||||
elements.push(
|
|
||||||
<a
|
|
||||||
key={key}
|
|
||||||
href={url}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="text-accent underline hover:opacity-80 transition-opacity"
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
elements.push(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
lastIndex = regex.lastIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastIndex < text.length) {
|
|
||||||
elements.push(text.slice(lastIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses inline markdown and fenced code blocks:
|
|
||||||
* - ```lang\ncode\n```
|
|
||||||
* - **bold** or __bold__
|
|
||||||
* - *italic* or _italic_
|
|
||||||
* - ~~strikethrough~~
|
|
||||||
* - `code`
|
|
||||||
* - [label](url)
|
|
||||||
*/
|
|
||||||
export function renderInlineMarkdown(text: string): React.ReactNode[] {
|
|
||||||
if (!text) return [];
|
|
||||||
|
|
||||||
if (text.includes('```')) {
|
|
||||||
const codeBlockRegex = /(```[a-zA-Z0-9_-]*\r?\n[\s\S]*?```|```[\s\S]*?```)/g;
|
|
||||||
const parts = text.split(codeBlockRegex);
|
|
||||||
const nodes: React.ReactNode[] = [];
|
|
||||||
|
|
||||||
parts.forEach((part, partIdx) => {
|
|
||||||
if (part.startsWith('```') && part.endsWith('```')) {
|
|
||||||
const lines = part.split(/\r?\n/);
|
|
||||||
const firstLine = lines[0].slice(3).trim();
|
|
||||||
const codeLines = lines.slice(1, lines.length - 1);
|
|
||||||
const code = codeLines.join('\n');
|
|
||||||
nodes.push(
|
|
||||||
<div
|
|
||||||
key={`fenced-${partIdx}`}
|
|
||||||
className="p-2.5 my-2 rounded bg-code text-accent font-mono text-xs overflow-x-auto border border-border/60 select-text"
|
|
||||||
>
|
|
||||||
{firstLine && (
|
|
||||||
<div className="text-[10px] text-faint uppercase font-sans pb-1 select-none">
|
|
||||||
{firstLine}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<pre className="whitespace-pre overflow-x-auto font-mono text-status-ok leading-relaxed">
|
|
||||||
<code>{code}</code>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
} else if (part) {
|
|
||||||
nodes.push(...renderInlineTokens(part));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
return renderInlineTokens(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function MarkdownViewer({ content, className = '' }: { content: string; className?: string }) {
|
|
||||||
if (!content) return null;
|
|
||||||
|
|
||||||
const lines = content.split('\n');
|
|
||||||
const renderedNodes: React.ReactNode[] = [];
|
|
||||||
let inCodeBlock = false;
|
|
||||||
let codeBlockLines: string[] = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < lines.length; i++) {
|
|
||||||
const line = lines[i];
|
|
||||||
|
|
||||||
if (line.trim().startsWith('```')) {
|
|
||||||
if (inCodeBlock) {
|
|
||||||
renderedNodes.push(
|
|
||||||
<pre key={`code-${i}`} className="p-2.5 my-2 rounded bg-panel-elevated text-accent font-mono text-xs overflow-x-auto border border-border/60">
|
|
||||||
<code>{codeBlockLines.join('\n')}</code>
|
|
||||||
</pre>
|
|
||||||
);
|
|
||||||
codeBlockLines = [];
|
|
||||||
inCodeBlock = false;
|
|
||||||
} else {
|
|
||||||
inCodeBlock = true;
|
|
||||||
codeBlockLines = [];
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inCodeBlock) {
|
|
||||||
codeBlockLines.push(line);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const trimmed = line.trim();
|
|
||||||
|
|
||||||
if (trimmed.startsWith('### ')) {
|
|
||||||
renderedNodes.push(
|
|
||||||
<h3 key={i} className="text-sm font-bold text-main mt-2 mb-1">
|
|
||||||
{renderInlineMarkdown(trimmed.slice(4))}
|
|
||||||
</h3>
|
|
||||||
);
|
|
||||||
} else if (trimmed.startsWith('## ')) {
|
|
||||||
renderedNodes.push(
|
|
||||||
<h2 key={i} className="text-base font-bold text-main mt-3 mb-1">
|
|
||||||
{renderInlineMarkdown(trimmed.slice(3))}
|
|
||||||
</h2>
|
|
||||||
);
|
|
||||||
} else if (trimmed.startsWith('# ')) {
|
|
||||||
renderedNodes.push(
|
|
||||||
<h1 key={i} className="text-lg font-bold text-main mt-3 mb-1.5">
|
|
||||||
{renderInlineMarkdown(trimmed.slice(2))}
|
|
||||||
</h1>
|
|
||||||
);
|
|
||||||
} else if (trimmed.startsWith('> ')) {
|
|
||||||
renderedNodes.push(
|
|
||||||
<blockquote key={i} className="border-l-2 border-accent pl-2.5 my-1 text-muted italic">
|
|
||||||
{renderInlineMarkdown(trimmed.slice(2))}
|
|
||||||
</blockquote>
|
|
||||||
);
|
|
||||||
} else if (trimmed.startsWith('- ') || trimmed.startsWith('* ')) {
|
|
||||||
renderedNodes.push(
|
|
||||||
<div key={i} className="flex items-start gap-1.5 my-0.5">
|
|
||||||
<span className="text-accent mt-0.5">•</span>
|
|
||||||
<span className="flex-1 text-main">{renderInlineMarkdown(trimmed.slice(2))}</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
} else if (/^\d+\.\s/.test(trimmed)) {
|
|
||||||
const matchNum = trimmed.match(/^(\d+)\.\s(.*)$/);
|
|
||||||
renderedNodes.push(
|
|
||||||
<div key={i} className="flex items-start gap-1.5 my-0.5">
|
|
||||||
<span className="text-muted text-[11px] font-mono mt-0.5">{matchNum ? matchNum[1] + '.' : '•'}</span>
|
|
||||||
<span className="flex-1 text-main">{renderInlineMarkdown(matchNum ? matchNum[2] : trimmed)}</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
} else if (trimmed === '') {
|
|
||||||
renderedNodes.push(<div key={i} className="h-2" />);
|
|
||||||
} else {
|
|
||||||
renderedNodes.push(
|
|
||||||
<div key={i} className="my-0.5 text-main leading-relaxed">
|
|
||||||
{renderInlineMarkdown(line)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inCodeBlock && codeBlockLines.length > 0) {
|
|
||||||
renderedNodes.push(
|
|
||||||
<pre key="code-end" className="p-2.5 my-2 rounded bg-panel-elevated text-accent font-mono text-xs overflow-x-auto border border-border/60">
|
|
||||||
<code>{codeBlockLines.join('\n')}</code>
|
|
||||||
</pre>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <div className={`markdown-body text-xs ${className}`}>{renderedNodes}</div>;
|
|
||||||
}
|
|
||||||
@@ -53,10 +53,8 @@ export interface Thought {
|
|||||||
source: 'manual' | 'voice' | 'webhook';
|
source: 'manual' | 'voice' | 'webhook';
|
||||||
status: ThoughtStatus;
|
status: ThoughtStatus;
|
||||||
isCompleted: boolean;
|
isCompleted: boolean;
|
||||||
convertedType?: 'task' | 'document' | 'list_item' | 'document_block';
|
convertedType?: 'task' | 'document' | 'list_item';
|
||||||
convertedRefId?: string;
|
convertedRefId?: string;
|
||||||
docId?: string;
|
|
||||||
blockId?: string;
|
|
||||||
dueDate?: string;
|
dueDate?: string;
|
||||||
taskListId?: string;
|
taskListId?: string;
|
||||||
kanbanStatus?: string;
|
kanbanStatus?: string;
|
||||||
@@ -83,7 +81,6 @@ export interface TaskListShare {
|
|||||||
targetName?: string;
|
targetName?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
avatarUrl?: string;
|
avatarUrl?: string;
|
||||||
permission?: 'editor' | 'viewer';
|
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +102,6 @@ export interface TaskList {
|
|||||||
ownerId?: string;
|
ownerId?: string;
|
||||||
ownerName?: string;
|
ownerName?: string;
|
||||||
isOwner?: boolean;
|
isOwner?: boolean;
|
||||||
permission?: 'owner' | 'editor' | 'viewer';
|
|
||||||
members?: TaskListMember[];
|
members?: TaskListMember[];
|
||||||
shares?: TaskListShare[];
|
shares?: TaskListShare[];
|
||||||
columns?: KanbanColumn[];
|
columns?: KanbanColumn[];
|
||||||
@@ -157,22 +153,16 @@ export interface SystemSettings {
|
|||||||
smtpConfiguredViaEnv?: boolean;
|
smtpConfiguredViaEnv?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BlockType = 'h1' | 'h2' | 'h3' | 'paragraph' | 'text' | 'todo' | 'bullet' | 'code' | 'callout' | 'divider' | 'table' | 'progress';
|
export type BlockType = 'h1' | 'h2' | 'h3' | 'paragraph' | 'todo' | 'bullet' | 'code' | 'callout' | 'divider' | 'table' | 'progress';
|
||||||
|
|
||||||
export interface DocumentBlock {
|
export interface DocumentBlock {
|
||||||
id: string;
|
id: string;
|
||||||
docId?: string;
|
|
||||||
documentId?: string;
|
|
||||||
taskId?: string;
|
|
||||||
type: BlockType;
|
type: BlockType;
|
||||||
content: string;
|
content: string;
|
||||||
checked?: boolean;
|
checked?: boolean;
|
||||||
lang?: string;
|
lang?: string;
|
||||||
level?: number;
|
level?: number;
|
||||||
position?: number;
|
|
||||||
collapsed?: boolean;
|
collapsed?: boolean;
|
||||||
sortOrder?: number;
|
|
||||||
updatedAt?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DocBlocksPatchRequest {
|
export interface DocBlocksPatchRequest {
|
||||||
@@ -205,14 +195,19 @@ export interface DocShare {
|
|||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DocLockInfo {
|
||||||
|
docId: string;
|
||||||
|
userId: string;
|
||||||
|
userName: string;
|
||||||
|
expiresAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Document {
|
export interface Document {
|
||||||
id: string;
|
id: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
spaceId?: string;
|
spaceId?: string;
|
||||||
title: string;
|
title: string;
|
||||||
icon: string;
|
icon: string;
|
||||||
folderId?: string;
|
|
||||||
markdownCache?: string;
|
|
||||||
content: string;
|
content: string;
|
||||||
blocks: DocumentBlock[];
|
blocks: DocumentBlock[];
|
||||||
tags: string[];
|
tags: string[];
|
||||||
|
|||||||
+103
-303
@@ -4,11 +4,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log/slog"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -47,7 +45,6 @@ func (s *Server) Router() http.Handler {
|
|||||||
|
|
||||||
r.Use(middleware.RealIP)
|
r.Use(middleware.RealIP)
|
||||||
r.Use(middleware.Recoverer)
|
r.Use(middleware.Recoverer)
|
||||||
r.Use(s.apiLoggingMiddleware)
|
|
||||||
r.Use(cors.Handler(cors.Options{
|
r.Use(cors.Handler(cors.Options{
|
||||||
AllowedOrigins: []string{"*"},
|
AllowedOrigins: []string{"*"},
|
||||||
AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
|
AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
|
||||||
@@ -68,16 +65,12 @@ func (s *Server) Router() http.Handler {
|
|||||||
r.Get("/api/v1/ws", s.handleWebSocket)
|
r.Get("/api/v1/ws", s.handleWebSocket)
|
||||||
r.Get("/api/v1/ws/spaces/{spaceId}", s.handleWebSocket)
|
r.Get("/api/v1/ws/spaces/{spaceId}", s.handleWebSocket)
|
||||||
r.Get("/api/v1/ws/lists/{listId}", s.handleWebSocket)
|
r.Get("/api/v1/ws/lists/{listId}", s.handleWebSocket)
|
||||||
r.Get("/api/v1/events", s.handleSSE)
|
|
||||||
r.Post("/api/v1/events/rooms", s.handleSSERooms)
|
|
||||||
|
|
||||||
// Authenticated API Routes
|
// Authenticated API Routes
|
||||||
r.Group(func(r chi.Router) {
|
r.Group(func(r chi.Router) {
|
||||||
r.Use(s.authMiddleware)
|
r.Use(s.authMiddleware)
|
||||||
|
|
||||||
r.Get("/api/v1/auth/me", s.handleMe)
|
r.Get("/api/v1/auth/me", s.handleMe)
|
||||||
r.Post("/api/v1/auth/logout", s.handleLogout)
|
|
||||||
r.Post("/api/v1/auth/revoke-all", s.handleRevokeAllSessions)
|
|
||||||
r.Patch("/api/v1/auth/settings", s.handleUpdateUserSettings)
|
r.Patch("/api/v1/auth/settings", s.handleUpdateUserSettings)
|
||||||
r.Post("/api/v1/auth/alarms/test", s.handleTestUserAlarm)
|
r.Post("/api/v1/auth/alarms/test", s.handleTestUserAlarm)
|
||||||
r.Get("/api/v1/users/directory", s.handleGetUsersDirectory)
|
r.Get("/api/v1/users/directory", s.handleGetUsersDirectory)
|
||||||
@@ -89,7 +82,6 @@ func (s *Server) Router() http.Handler {
|
|||||||
// Instant Capture & Thoughts
|
// Instant Capture & Thoughts
|
||||||
r.Post("/api/v1/inbox", s.handleCaptureInbox)
|
r.Post("/api/v1/inbox", s.handleCaptureInbox)
|
||||||
r.Get("/api/v1/thoughts", s.handleGetThoughts)
|
r.Get("/api/v1/thoughts", s.handleGetThoughts)
|
||||||
r.Get("/api/v1/thoughts/{id}", s.handleGetThought)
|
|
||||||
r.Patch("/api/v1/thoughts/{id}", s.handleUpdateThought)
|
r.Patch("/api/v1/thoughts/{id}", s.handleUpdateThought)
|
||||||
r.Delete("/api/v1/thoughts/{id}", s.handleDeleteThought)
|
r.Delete("/api/v1/thoughts/{id}", s.handleDeleteThought)
|
||||||
r.Delete("/api/v1/thoughts/discarded/purge", s.handlePurgeDiscarded)
|
r.Delete("/api/v1/thoughts/discarded/purge", s.handlePurgeDiscarded)
|
||||||
@@ -98,7 +90,6 @@ func (s *Server) Router() http.Handler {
|
|||||||
r.Get("/api/v1/triage/deck", s.handleGetTriageDeck)
|
r.Get("/api/v1/triage/deck", s.handleGetTriageDeck)
|
||||||
r.Patch("/api/v1/triage/{id}", s.handleTriageAction)
|
r.Patch("/api/v1/triage/{id}", s.handleTriageAction)
|
||||||
r.Get("/api/v1/tasks", s.handleGetTasks)
|
r.Get("/api/v1/tasks", s.handleGetTasks)
|
||||||
r.Post("/api/v1/tasks/{id}/unlink", s.handleUnlinkEnhancedTask)
|
|
||||||
r.Post("/api/v1/tasks/reorder", s.handleReorderTasks)
|
r.Post("/api/v1/tasks/reorder", s.handleReorderTasks)
|
||||||
r.Post("/api/v1/task-lists/{id}/tasks/reorder", s.handleReorderTasks)
|
r.Post("/api/v1/task-lists/{id}/tasks/reorder", s.handleReorderTasks)
|
||||||
|
|
||||||
@@ -138,13 +129,18 @@ func (s *Server) Router() http.Handler {
|
|||||||
r.Patch("/api/v1/documents/{id}/blocks", s.handlePatchDocumentBlocks)
|
r.Patch("/api/v1/documents/{id}/blocks", s.handlePatchDocumentBlocks)
|
||||||
r.Put("/api/v1/documents/{id}/move", s.handleMoveDocument)
|
r.Put("/api/v1/documents/{id}/move", s.handleMoveDocument)
|
||||||
r.Delete("/api/v1/documents/{id}", s.handleDeleteDocument)
|
r.Delete("/api/v1/documents/{id}", s.handleDeleteDocument)
|
||||||
r.Post("/api/v1/documents/{id}/blocks/{blockId}/enhanced-task", s.handleCreateEnhancedTask)
|
|
||||||
|
|
||||||
// Document Sharing & Collaboration
|
// Document Sharing & Collaboration
|
||||||
r.Get("/api/v1/documents/{id}/shares", s.handleGetDocShares)
|
r.Get("/api/v1/documents/{id}/shares", s.handleGetDocShares)
|
||||||
r.Post("/api/v1/documents/{id}/shares", s.handleCreateDocShare)
|
r.Post("/api/v1/documents/{id}/shares", s.handleCreateDocShare)
|
||||||
r.Delete("/api/v1/documents/{id}/shares/{userId}", s.handleDeleteDocShare)
|
r.Delete("/api/v1/documents/{id}/shares/{userId}", s.handleDeleteDocShare)
|
||||||
|
|
||||||
|
// Document Locking
|
||||||
|
r.Get("/api/v1/documents/{id}/lock", s.handleGetDocLock)
|
||||||
|
r.Post("/api/v1/documents/{id}/lock", s.handleLockDoc)
|
||||||
|
r.Post("/api/v1/documents/{id}/lock/heartbeat", s.handleHeartbeatDocLock)
|
||||||
|
r.Delete("/api/v1/documents/{id}/lock", s.handleUnlockDoc)
|
||||||
|
|
||||||
// Shared Lists & Realtime Collaboration
|
// Shared Lists & Realtime Collaboration
|
||||||
r.Get("/api/v1/lists", s.handleGetAllLists)
|
r.Get("/api/v1/lists", s.handleGetAllLists)
|
||||||
r.Post("/api/v1/lists", s.handleCreateList)
|
r.Post("/api/v1/lists", s.handleCreateList)
|
||||||
@@ -155,7 +151,6 @@ func (s *Server) Router() http.Handler {
|
|||||||
r.Delete("/api/v1/lists/{id}/shares/{shareId}", s.handleDeleteListShare)
|
r.Delete("/api/v1/lists/{id}/shares/{shareId}", s.handleDeleteListShare)
|
||||||
r.Post("/api/v1/lists/{id}/items", s.handleCreateListItem)
|
r.Post("/api/v1/lists/{id}/items", s.handleCreateListItem)
|
||||||
r.Patch("/api/v1/lists/{id}/items/{itemId}", s.handleToggleListItem)
|
r.Patch("/api/v1/lists/{id}/items/{itemId}", s.handleToggleListItem)
|
||||||
r.Put("/api/v1/lists/{id}/items/{itemId}", s.handleUpdateListItem)
|
|
||||||
r.Delete("/api/v1/lists/{id}/items/{itemId}", s.handleDeleteListItem)
|
r.Delete("/api/v1/lists/{id}/items/{itemId}", s.handleDeleteListItem)
|
||||||
r.Post("/api/v1/lists/{id}/items/reorder", s.handleReorderListItems)
|
r.Post("/api/v1/lists/{id}/items/reorder", s.handleReorderListItems)
|
||||||
r.Put("/api/v1/lists/{id}/items/reorder", s.handleReorderListItems)
|
r.Put("/api/v1/lists/{id}/items/reorder", s.handleReorderListItems)
|
||||||
@@ -244,63 +239,6 @@ func writeError(w http.ResponseWriter, status int, message string) {
|
|||||||
writeJSON(w, status, map[string]string{"error": message})
|
writeJSON(w, status, map[string]string{"error": message})
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeStoreError maps read-only task list violations to 403 and everything else to the given fallback status.
|
|
||||||
func writeStoreError(w http.ResponseWriter, fallbackStatus int, err error) {
|
|
||||||
if errors.Is(err, storage.ErrTaskListReadOnly) {
|
|
||||||
writeError(w, http.StatusForbidden, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
writeError(w, fallbackStatus, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) apiLoggingMiddleware(next http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// Only log API requests (/api/...)
|
|
||||||
if !strings.HasPrefix(r.URL.Path, "/api") {
|
|
||||||
next.ServeHTTP(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
start := time.Now()
|
|
||||||
ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
|
|
||||||
|
|
||||||
next.ServeHTTP(ww, r)
|
|
||||||
|
|
||||||
duration := time.Since(start)
|
|
||||||
durationMs := float64(duration.Microseconds()) / 1000.0
|
|
||||||
status := ww.Status()
|
|
||||||
if status == 0 {
|
|
||||||
status = http.StatusOK
|
|
||||||
}
|
|
||||||
|
|
||||||
method := r.Method
|
|
||||||
path := r.URL.Path
|
|
||||||
|
|
||||||
if status >= 500 {
|
|
||||||
slog.Error("HTTP request failed",
|
|
||||||
"method", method,
|
|
||||||
"path", path,
|
|
||||||
"status", status,
|
|
||||||
"duration_ms", durationMs,
|
|
||||||
)
|
|
||||||
} else if status >= 400 {
|
|
||||||
slog.Warn("HTTP request warning",
|
|
||||||
"method", method,
|
|
||||||
"path", path,
|
|
||||||
"status", status,
|
|
||||||
"duration_ms", durationMs,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
slog.Debug("HTTP request completed",
|
|
||||||
"method", method,
|
|
||||||
"path", path,
|
|
||||||
"status", status,
|
|
||||||
"duration_ms", durationMs,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) authMiddleware(next http.Handler) http.Handler {
|
func (s *Server) authMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 1. Check Authorization Bearer Token
|
// 1. Check Authorization Bearer Token
|
||||||
@@ -316,17 +254,13 @@ func (s *Server) authMiddleware(next http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
claims, err := auth.ValidateToken(s.cfg.JWTSecret, tokenStr)
|
claims, err := auth.ValidateToken(s.cfg.JWTSecret, tokenStr)
|
||||||
if err == nil && claims != nil {
|
if err == nil && claims != nil {
|
||||||
if !s.store.IsTokenRevoked(tokenStr) {
|
|
||||||
user, userErr := s.store.GetUserByID(claims.UserID)
|
user, userErr := s.store.GetUserByID(claims.UserID)
|
||||||
if userErr == nil && user != nil && user.IsActive {
|
if userErr == nil && user != nil && user.IsActive {
|
||||||
if claims.TokenVersion == 0 || claims.TokenVersion == user.TokenVersion {
|
|
||||||
next.ServeHTTP(w, r.WithContext(auth.WithUserID(r.Context(), user.ID)))
|
next.ServeHTTP(w, r.WithContext(auth.WithUserID(r.Context(), user.ID)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Check X-API-Key Header
|
// 2. Check X-API-Key Header
|
||||||
apiKey := r.Header.Get("X-API-Key")
|
apiKey := r.Header.Get("X-API-Key")
|
||||||
@@ -459,7 +393,7 @@ func (s *Server) handleFirstBootSetup(w http.ResponseWriter, r *http.Request) {
|
|||||||
_ = s.store.SeedStarterContent(user)
|
_ = s.store.SeedStarterContent(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := auth.GenerateToken(s.cfg.JWTSecret, user.ID, user.Email, user.DisplayName, user.TokenVersion)
|
token, err := auth.GenerateToken(s.cfg.JWTSecret, user.ID, user.Email, user.DisplayName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, "Token konnte nicht erstellt werden")
|
writeError(w, http.StatusInternalServerError, "Token konnte nicht erstellt werden")
|
||||||
return
|
return
|
||||||
@@ -535,7 +469,7 @@ func (s *Server) handleRegister(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := auth.GenerateToken(s.cfg.JWTSecret, user.ID, user.Email, user.DisplayName, user.TokenVersion)
|
token, err := auth.GenerateToken(s.cfg.JWTSecret, user.ID, user.Email, user.DisplayName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, "Token konnte nicht erstellt werden")
|
writeError(w, http.StatusInternalServerError, "Token konnte nicht erstellt werden")
|
||||||
return
|
return
|
||||||
@@ -573,31 +507,21 @@ func (s *Server) handleLogin(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user, err := s.store.GetUserByLogin(identifier)
|
user, err := s.store.GetUserByLogin(identifier)
|
||||||
if err != nil {
|
if err != nil || !auth.CheckPassword(req.Password, user.PasswordHash) {
|
||||||
slog.Warn("Login fehlgeschlagen: Benutzer existiert nicht", "login", identifier, "remote_addr", r.RemoteAddr)
|
|
||||||
writeError(w, http.StatusUnauthorized, "Benutzername/E-Mail oder Passwort ungültig")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !auth.CheckPassword(req.Password, user.PasswordHash) {
|
|
||||||
slog.Warn("Login fehlgeschlagen: Falsches Passwort", "login", identifier, "user_id", user.ID, "display_name", user.DisplayName, "remote_addr", r.RemoteAddr)
|
|
||||||
writeError(w, http.StatusUnauthorized, "Benutzername/E-Mail oder Passwort ungültig")
|
writeError(w, http.StatusUnauthorized, "Benutzername/E-Mail oder Passwort ungültig")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !user.IsActive {
|
if !user.IsActive {
|
||||||
slog.Warn("Login verweigert: Benutzerkonto ist deaktiviert", "login", identifier, "user_id", user.ID, "display_name", user.DisplayName, "remote_addr", r.RemoteAddr)
|
|
||||||
writeError(w, http.StatusForbidden, "Dieses Benutzerkonto ist deaktiviert")
|
writeError(w, http.StatusForbidden, "Dieses Benutzerkonto ist deaktiviert")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := auth.GenerateToken(s.cfg.JWTSecret, user.ID, user.Email, user.DisplayName, user.TokenVersion)
|
token, err := auth.GenerateToken(s.cfg.JWTSecret, user.ID, user.Email, user.DisplayName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Login-Token konnte nicht erstellt werden", "login", identifier, "user_id", user.ID, "error", err)
|
|
||||||
writeError(w, http.StatusInternalServerError, "Token konnte nicht erstellt werden")
|
writeError(w, http.StatusInternalServerError, "Token konnte nicht erstellt werden")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("Login erfolgreich", "login", identifier, "user_id", user.ID, "display_name", user.DisplayName, "role", user.Role, "remote_addr", r.RemoteAddr)
|
|
||||||
|
|
||||||
writeJSON(w, http.StatusOK, map[string]interface{}{
|
writeJSON(w, http.StatusOK, map[string]interface{}{
|
||||||
"token": token,
|
"token": token,
|
||||||
"user": user,
|
"user": user,
|
||||||
@@ -683,7 +607,7 @@ func (s *Server) handleCaptureInbox(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
thought, err := s.store.CreateThoughtWithDetails(userID, req.Content, req.Priority, source, dueDate, taskListID, "todo", "")
|
thought, err := s.store.CreateThoughtWithDetails(userID, req.Content, req.Priority, source, dueDate, taskListID, "todo", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeStoreError(w, http.StatusBadRequest, err)
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -714,17 +638,6 @@ func (s *Server) handleGetThoughts(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, thoughts)
|
writeJSON(w, http.StatusOK, thoughts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleGetThought(w http.ResponseWriter, r *http.Request) {
|
|
||||||
userID := auth.GetUserID(r.Context())
|
|
||||||
thoughtID := chi.URLParam(r, "id")
|
|
||||||
thought, err := s.store.GetThoughtByID(userID, thoughtID)
|
|
||||||
if err != nil || thought == nil {
|
|
||||||
writeError(w, http.StatusNotFound, "Aufgabe nicht gefunden")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, thought)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) handleGetTriageDeck(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleGetTriageDeck(w http.ResponseWriter, r *http.Request) {
|
||||||
userID := auth.GetUserID(r.Context())
|
userID := auth.GetUserID(r.Context())
|
||||||
thoughts, err := s.store.GetThoughts(userID, "inbox", 100)
|
thoughts, err := s.store.GetThoughts(userID, "inbox", 100)
|
||||||
@@ -774,7 +687,7 @@ func (s *Server) handleTriageAction(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
updated, err := s.store.UpdateThoughtTriage(userID, thoughtID, req.Action, convertTo, targetListID, dueDate, taskListID)
|
updated, err := s.store.UpdateThoughtTriage(userID, thoughtID, req.Action, convertTo, targetListID, dueDate, taskListID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeStoreError(w, http.StatusBadRequest, err)
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -815,17 +728,6 @@ func (s *Server) handleReorderTasks(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if taskListID != "" && !s.store.CanEditTaskList(userID, taskListID) {
|
|
||||||
writeError(w, http.StatusForbidden, storage.ErrTaskListReadOnly.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, it := range req.Items {
|
|
||||||
if th, err := s.store.GetThoughtByID(userID, it.ID); err == nil && th.TaskListID != "" && !s.store.CanEditTaskList(userID, th.TaskListID) {
|
|
||||||
writeError(w, http.StatusForbidden, storage.ErrTaskListReadOnly.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.store.ReorderTasks(taskListID, req.Items); err != nil {
|
if err := s.store.ReorderTasks(taskListID, req.Items); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, err.Error())
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
@@ -861,31 +763,18 @@ func (s *Server) handleUpdateThought(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
updated, err := s.store.UpdateThoughtDetails(userID, thoughtID, req.Content, req.IsCompleted, req.DueDate, req.Priority, req.TaskListID, req.KanbanStatus, req.Notes, req.Subtasks, req.Tags)
|
updated, err := s.store.UpdateThoughtDetails(userID, thoughtID, req.Content, req.IsCompleted, req.DueDate, req.Priority, req.TaskListID, req.KanbanStatus, req.Notes, req.Subtasks, req.Tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeStoreError(w, http.StatusBadRequest, err)
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.store.SyncDocBlockAndTask(userID, thoughtID, updated.IsCompleted)
|
|
||||||
s.wsHub.BroadcastToAll("TASK_UPDATED", updated)
|
s.wsHub.BroadcastToAll("TASK_UPDATED", updated)
|
||||||
writeJSON(w, http.StatusOK, updated)
|
writeJSON(w, http.StatusOK, updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleUnlinkEnhancedTask(w http.ResponseWriter, r *http.Request) {
|
|
||||||
userID := auth.GetUserID(r.Context())
|
|
||||||
thoughtID := chi.URLParam(r, "id")
|
|
||||||
s.store.UnlinkTaskFromDocBlock(userID, thoughtID)
|
|
||||||
writeJSON(w, http.StatusOK, map[string]bool{"unlinked": true})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) handleDeleteThought(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleDeleteThought(w http.ResponseWriter, r *http.Request) {
|
||||||
userID := auth.GetUserID(r.Context())
|
userID := auth.GetUserID(r.Context())
|
||||||
thoughtID := chi.URLParam(r, "id")
|
thoughtID := chi.URLParam(r, "id")
|
||||||
if th, err := s.store.GetThoughtByID(userID, thoughtID); err == nil && th.TaskListID != "" && !s.store.CanEditTaskList(userID, th.TaskListID) {
|
|
||||||
writeError(w, http.StatusForbidden, storage.ErrTaskListReadOnly.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
s.store.UnlinkTaskFromDocBlock(userID, thoughtID)
|
|
||||||
if err := s.store.DeleteThought(userID, thoughtID); err != nil {
|
if err := s.store.DeleteThought(userID, thoughtID); err != nil {
|
||||||
writeStoreError(w, http.StatusInternalServerError, err)
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.wsHub.BroadcastToAll("TASK_DELETED", map[string]string{"id": thoughtID})
|
s.wsHub.BroadcastToAll("TASK_DELETED", map[string]string{"id": thoughtID})
|
||||||
@@ -909,18 +798,11 @@ func (s *Server) broadcastDocToAuthorizedUsers(docID, event string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var firstDoc *domain.Document
|
|
||||||
for _, uid := range users {
|
for _, uid := range users {
|
||||||
if userDoc, err := s.store.GetDocumentByID(uid, docID); err == nil && userDoc != nil {
|
if userDoc, err := s.store.GetDocumentByID(uid, docID); err == nil && userDoc != nil {
|
||||||
if firstDoc == nil {
|
|
||||||
firstDoc = userDoc
|
|
||||||
}
|
|
||||||
s.wsHub.BroadcastToUser(uid, event, userDoc)
|
s.wsHub.BroadcastToUser(uid, event, userDoc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s.wsHub != nil && firstDoc != nil {
|
|
||||||
s.wsHub.BroadcastRoom("doc:"+docID, event, firstDoc, nil)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleGetDocuments(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleGetDocuments(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -954,6 +836,7 @@ func (s *Server) handleCreateDocument(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeError(w, http.StatusBadRequest, err.Error())
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.wsHub.BroadcastDocEvent(doc.ID, "DOC_CREATED", doc)
|
||||||
s.broadcastDocToAuthorizedUsers(doc.ID, "DOC_CREATED")
|
s.broadcastDocToAuthorizedUsers(doc.ID, "DOC_CREATED")
|
||||||
writeJSON(w, http.StatusCreated, doc)
|
writeJSON(w, http.StatusCreated, doc)
|
||||||
}
|
}
|
||||||
@@ -973,6 +856,16 @@ func (s *Server) handleUpdateDocument(w http.ResponseWriter, r *http.Request) {
|
|||||||
userID := auth.GetUserID(r.Context())
|
userID := auth.GetUserID(r.Context())
|
||||||
docID := chi.URLParam(r, "id")
|
docID := chi.URLParam(r, "id")
|
||||||
|
|
||||||
|
// Check document lock
|
||||||
|
if lock := s.wsHub.GetDocLock(docID); lock != nil && lock.UserID != userID {
|
||||||
|
w.WriteHeader(http.StatusLocked)
|
||||||
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
|
"error": "Dokument wird aktuell bearbeitet von " + lock.UserName,
|
||||||
|
"currentLock": lock,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var req struct {
|
var req struct {
|
||||||
Title *string `json:"title"`
|
Title *string `json:"title"`
|
||||||
Icon *string `json:"icon"`
|
Icon *string `json:"icon"`
|
||||||
@@ -992,6 +885,7 @@ func (s *Server) handleUpdateDocument(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.Title != nil || req.Icon != nil || req.FolderPath != nil || req.Blocks != nil || req.Tags != nil {
|
if req.Title != nil || req.Icon != nil || req.FolderPath != nil || req.Blocks != nil || req.Tags != nil {
|
||||||
|
s.wsHub.BroadcastDocEvent(docID, "DOC_UPDATED", doc)
|
||||||
s.broadcastDocToAuthorizedUsers(docID, "DOC_UPDATED")
|
s.broadcastDocToAuthorizedUsers(docID, "DOC_UPDATED")
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, doc)
|
writeJSON(w, http.StatusOK, doc)
|
||||||
@@ -1001,6 +895,16 @@ func (s *Server) handlePatchDocumentBlocks(w http.ResponseWriter, r *http.Reques
|
|||||||
userID := auth.GetUserID(r.Context())
|
userID := auth.GetUserID(r.Context())
|
||||||
docID := chi.URLParam(r, "id")
|
docID := chi.URLParam(r, "id")
|
||||||
|
|
||||||
|
// Check document lock
|
||||||
|
if lock := s.wsHub.GetDocLock(docID); lock != nil && lock.UserID != userID {
|
||||||
|
w.WriteHeader(http.StatusLocked)
|
||||||
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
|
"error": "Dokument wird aktuell bearbeitet von " + lock.UserName,
|
||||||
|
"currentLock": lock,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var req domain.DocBlocksPatchRequest
|
var req domain.DocBlocksPatchRequest
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "Ungültiges JSON")
|
writeError(w, http.StatusBadRequest, "Ungültiges JSON")
|
||||||
@@ -1034,42 +938,14 @@ func (s *Server) handlePatchDocumentBlocks(w http.ResponseWriter, r *http.Reques
|
|||||||
func (s *Server) handleDeleteDocument(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleDeleteDocument(w http.ResponseWriter, r *http.Request) {
|
||||||
userID := auth.GetUserID(r.Context())
|
userID := auth.GetUserID(r.Context())
|
||||||
docID := chi.URLParam(r, "id")
|
docID := chi.URLParam(r, "id")
|
||||||
authorizedUsers, _ := s.store.GetAuthorizedDocUsers(docID)
|
|
||||||
|
|
||||||
if err := s.store.DeleteDocument(userID, docID); err != nil {
|
if err := s.store.DeleteDocument(userID, docID); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, err.Error())
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, uid := range authorizedUsers {
|
s.wsHub.BroadcastDocEvent(docID, "DOC_DELETED", map[string]string{"id": docID})
|
||||||
s.wsHub.BroadcastToUser(uid, "DOC_DELETED", map[string]string{"id": docID})
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, map[string]bool{"deleted": true})
|
writeJSON(w, http.StatusOK, map[string]bool{"deleted": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleCreateEnhancedTask(w http.ResponseWriter, r *http.Request) {
|
|
||||||
userID := auth.GetUserID(r.Context())
|
|
||||||
docID := chi.URLParam(r, "id")
|
|
||||||
blockID := chi.URLParam(r, "blockId")
|
|
||||||
|
|
||||||
var req struct {
|
|
||||||
Content string `json:"content"`
|
|
||||||
Checked bool `json:"checked"`
|
|
||||||
}
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
writeError(w, http.StatusBadRequest, "Ungültiges JSON")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
thought, err := s.store.CreateTaskFromDocBlock(userID, docID, blockID, req.Content, req.Checked)
|
|
||||||
if err != nil {
|
|
||||||
writeError(w, http.StatusBadRequest, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s.wsHub.BroadcastToUser(userID, "TASK_CREATED", thought)
|
|
||||||
writeJSON(w, http.StatusCreated, thought)
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- WORKSPACE FOLDERS ---
|
// --- WORKSPACE FOLDERS ---
|
||||||
|
|
||||||
func (s *Server) handleGetFolders(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleGetFolders(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -1115,6 +991,7 @@ func (s *Server) handleDeleteFolder(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, docID := range deletedDocIDs {
|
for _, docID := range deletedDocIDs {
|
||||||
|
s.wsHub.ReleaseDocLock(docID, userID, true)
|
||||||
s.wsHub.BroadcastDocEvent(docID, "DOC_DELETED", map[string]string{"id": docID})
|
s.wsHub.BroadcastDocEvent(docID, "DOC_DELETED", map[string]string{"id": docID})
|
||||||
}
|
}
|
||||||
s.wsHub.BroadcastDocEvent("", "WORKSPACE_FOLDERS_UPDATED", map[string]string{"path": folderPath})
|
s.wsHub.BroadcastDocEvent("", "WORKSPACE_FOLDERS_UPDATED", map[string]string{"path": folderPath})
|
||||||
@@ -1274,11 +1151,6 @@ func (s *Server) handleCreateFolderShare(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.wsHub.BroadcastDocEvent("", "WORKSPACE_FOLDERS_UPDATED", share)
|
s.wsHub.BroadcastDocEvent("", "WORKSPACE_FOLDERS_UPDATED", share)
|
||||||
if docIDs, err := s.store.GetSharedFolderDocIDs(folderID); err == nil {
|
|
||||||
for _, docID := range docIDs {
|
|
||||||
s.broadcastDocToAuthorizedUsers(docID, "DOC_CREATED")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusCreated, share)
|
writeJSON(w, http.StatusCreated, share)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1286,16 +1158,11 @@ func (s *Server) handleDeleteFolderShare(w http.ResponseWriter, r *http.Request)
|
|||||||
userID := auth.GetUserID(r.Context())
|
userID := auth.GetUserID(r.Context())
|
||||||
folderID := chi.URLParam(r, "id")
|
folderID := chi.URLParam(r, "id")
|
||||||
shareID := chi.URLParam(r, "shareId")
|
shareID := chi.URLParam(r, "shareId")
|
||||||
docIDs, _ := s.store.GetSharedFolderDocIDs(folderID)
|
|
||||||
if err := s.store.DeleteFolderShare(userID, folderID, shareID); err != nil {
|
if err := s.store.DeleteFolderShare(userID, folderID, shareID); err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, err.Error())
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.wsHub.BroadcastDocEvent("", "WORKSPACE_FOLDERS_UPDATED", map[string]string{"folderId": folderID, "shareId": shareID})
|
s.wsHub.BroadcastDocEvent("", "WORKSPACE_FOLDERS_UPDATED", map[string]string{"folderId": folderID, "shareId": shareID})
|
||||||
for _, docID := range docIDs {
|
|
||||||
s.wsHub.BroadcastToUser(shareID, "DOC_DELETED", map[string]string{"id": docID})
|
|
||||||
s.broadcastDocToAuthorizedUsers(docID, "DOC_UPDATED")
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, map[string]bool{"deleted": true})
|
writeJSON(w, http.StatusOK, map[string]bool{"deleted": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1445,30 +1312,65 @@ func (s *Server) handleGetCollaborators(w http.ResponseWriter, r *http.Request)
|
|||||||
writeJSON(w, http.StatusOK, users)
|
writeJSON(w, http.StatusOK, users)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) authenticateUserFromReq(r *http.Request) string {
|
// --- DOCUMENT LOCKING ---
|
||||||
token := r.URL.Query().Get("token")
|
|
||||||
if token == "" {
|
func (s *Server) handleGetDocLock(w http.ResponseWriter, r *http.Request) {
|
||||||
if authHdr := r.Header.Get("Authorization"); strings.HasPrefix(authHdr, "Bearer ") {
|
docID := chi.URLParam(r, "id")
|
||||||
token = strings.TrimPrefix(authHdr, "Bearer ")
|
lock := s.wsHub.GetDocLock(docID)
|
||||||
|
if lock == nil {
|
||||||
|
writeJSON(w, http.StatusOK, map[string]interface{}{"locked": false})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
writeJSON(w, http.StatusOK, map[string]interface{}{"locked": true, "lock": lock})
|
||||||
}
|
}
|
||||||
if token != "" {
|
|
||||||
if strings.HasPrefix(token, "mindsift_sec_") {
|
func (s *Server) handleLockDoc(w http.ResponseWriter, r *http.Request) {
|
||||||
if user, err := s.store.ValidateAPIKeyAndGetUser(token); err == nil && user != nil && user.IsActive {
|
userID := auth.GetUserID(r.Context())
|
||||||
return user.ID
|
docID := chi.URLParam(r, "id")
|
||||||
|
|
||||||
|
user, err := s.store.GetUserByID(userID)
|
||||||
|
userName := "Ein Benutzer"
|
||||||
|
if err == nil && user != nil && user.DisplayName != "" {
|
||||||
|
userName = user.DisplayName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info, acquired, currentLock := s.wsHub.AcquireDocLock(docID, userID, userName, 20*time.Second)
|
||||||
|
if !acquired {
|
||||||
|
w.WriteHeader(http.StatusLocked)
|
||||||
|
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||||
|
"locked": true,
|
||||||
|
"acquired": false,
|
||||||
|
"currentLock": currentLock,
|
||||||
|
"message": "Wird aktuell bearbeitet von " + currentLock.UserName,
|
||||||
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if claims, err := auth.ValidateToken(s.cfg.JWTSecret, token); err == nil && claims != nil {
|
|
||||||
if !s.store.IsTokenRevoked(token) {
|
s.wsHub.BroadcastDocEvent(docID, "DOC_LOCKED", info)
|
||||||
if user, err := s.store.GetUserByID(claims.UserID); err == nil && user != nil && user.IsActive {
|
writeJSON(w, http.StatusOK, map[string]interface{}{
|
||||||
if claims.TokenVersion == 0 || claims.TokenVersion == user.TokenVersion {
|
"locked": true,
|
||||||
return claims.UserID
|
"acquired": true,
|
||||||
|
"lock": info,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) handleHeartbeatDocLock(w http.ResponseWriter, r *http.Request) {
|
||||||
|
userID := auth.GetUserID(r.Context())
|
||||||
|
docID := chi.URLParam(r, "id")
|
||||||
|
ok := s.wsHub.HeartbeatDocLock(docID, userID, 20*time.Second)
|
||||||
|
writeJSON(w, http.StatusOK, map[string]bool{"extended": ok})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) handleUnlockDoc(w http.ResponseWriter, r *http.Request) {
|
||||||
|
userID := auth.GetUserID(r.Context())
|
||||||
|
docID := chi.URLParam(r, "id")
|
||||||
|
user, _ := s.store.GetUserByID(userID)
|
||||||
|
isAdmin := user != nil && user.Role == "admin"
|
||||||
|
released := s.wsHub.ReleaseDocLock(docID, userID, isAdmin)
|
||||||
|
if released {
|
||||||
|
s.wsHub.BroadcastDocEvent(docID, "DOC_UNLOCKED", map[string]string{"docId": docID, "doc_id": docID})
|
||||||
}
|
}
|
||||||
}
|
writeJSON(w, http.StatusOK, map[string]bool{"unlocked": released})
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- REALTIME LISTS & SHARING ---
|
// --- REALTIME LISTS & SHARING ---
|
||||||
@@ -1647,30 +1549,6 @@ func (s *Server) handleToggleListItem(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, item)
|
writeJSON(w, http.StatusOK, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleUpdateListItem(w http.ResponseWriter, r *http.Request) {
|
|
||||||
listID := chi.URLParam(r, "id")
|
|
||||||
itemID := chi.URLParam(r, "itemId")
|
|
||||||
|
|
||||||
var req struct {
|
|
||||||
Content *string `json:"content"`
|
|
||||||
Category *string `json:"category"`
|
|
||||||
Quantity *string `json:"quantity"`
|
|
||||||
}
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
writeError(w, http.StatusBadRequest, "Ungültiges JSON")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
item, err := s.store.UpdateListItem(itemID, req.Content, req.Category, req.Quantity)
|
|
||||||
if err != nil {
|
|
||||||
writeError(w, http.StatusBadRequest, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s.wsHub.BroadcastListEvent(listID, "ITEM_UPDATED", item)
|
|
||||||
writeJSON(w, http.StatusOK, item)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) handleDeleteListItem(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleDeleteListItem(w http.ResponseWriter, r *http.Request) {
|
||||||
listID := chi.URLParam(r, "id")
|
listID := chi.URLParam(r, "id")
|
||||||
itemID := chi.URLParam(r, "itemId")
|
itemID := chi.URLParam(r, "itemId")
|
||||||
@@ -1749,67 +1627,21 @@ func (s *Server) handleWebSocket(w http.ResponseWriter, r *http.Request) {
|
|||||||
roomID = r.URL.Query().Get("spaceId")
|
roomID = r.URL.Query().Get("spaceId")
|
||||||
}
|
}
|
||||||
|
|
||||||
userID := s.authenticateUserFromReq(r)
|
token := r.URL.Query().Get("token")
|
||||||
if userID == "" {
|
if token == "" {
|
||||||
userID = "anonymous"
|
if authHdr := r.Header.Get("Authorization"); strings.HasPrefix(authHdr, "Bearer ") {
|
||||||
|
token = strings.TrimPrefix(authHdr, "Bearer ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
userID := "anonymous"
|
||||||
|
if token != "" {
|
||||||
|
if claims, err := auth.ValidateToken(s.cfg.JWTSecret, token); err == nil {
|
||||||
|
userID = claims.UserID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
s.wsHub.ServeWS(w, r, roomID, userID)
|
s.wsHub.ServeWS(w, r, roomID, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleSSE(w http.ResponseWriter, r *http.Request) {
|
|
||||||
roomID := r.URL.Query().Get("listId")
|
|
||||||
if roomID == "" {
|
|
||||||
roomID = r.URL.Query().Get("spaceId")
|
|
||||||
}
|
|
||||||
|
|
||||||
userID := s.authenticateUserFromReq(r)
|
|
||||||
if userID == "" {
|
|
||||||
userID = "anonymous"
|
|
||||||
}
|
|
||||||
|
|
||||||
var initialRooms []string
|
|
||||||
if roomsParam := r.URL.Query().Get("rooms"); roomsParam != "" {
|
|
||||||
for _, rm := range strings.Split(roomsParam, ",") {
|
|
||||||
rm = strings.TrimSpace(rm)
|
|
||||||
if rm != "" {
|
|
||||||
initialRooms = append(initialRooms, rm)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if docID := r.URL.Query().Get("docId"); docID != "" {
|
|
||||||
initialRooms = append(initialRooms, "doc:"+strings.TrimSpace(docID))
|
|
||||||
}
|
|
||||||
|
|
||||||
s.wsHub.ServeSSE(w, r, roomID, userID, initialRooms)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) handleSSERooms(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var req struct {
|
|
||||||
SSEID string `json:"sseId"`
|
|
||||||
Room string `json:"room"`
|
|
||||||
DocID string `json:"docId"`
|
|
||||||
Action string `json:"action"` // "join" or "leave"
|
|
||||||
}
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
writeError(w, http.StatusBadRequest, "Ungültiges JSON")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.Room == "" && req.DocID != "" {
|
|
||||||
req.Room = "doc:" + req.DocID
|
|
||||||
}
|
|
||||||
if req.SSEID == "" || req.Room == "" {
|
|
||||||
writeError(w, http.StatusBadRequest, "sseId und room erforderlich")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.Action == "leave" {
|
|
||||||
s.wsHub.LeaveSSERoomByID(req.SSEID, req.Room)
|
|
||||||
} else {
|
|
||||||
s.wsHub.JoinSSERoomByID(req.SSEID, req.Room)
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, map[string]bool{"success": true})
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- API KEYS & WEBHOOK INGESTION ---
|
// --- API KEYS & WEBHOOK INGESTION ---
|
||||||
|
|
||||||
func (s *Server) handleGetAPIKeys(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleGetAPIKeys(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -1980,33 +1812,6 @@ func (s *Server) handleExport(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// --- USER SETTINGS & ALARMS ---
|
// --- USER SETTINGS & ALARMS ---
|
||||||
|
|
||||||
func (s *Server) handleLogout(w http.ResponseWriter, r *http.Request) {
|
|
||||||
userID := auth.GetUserID(r.Context())
|
|
||||||
authHeader := r.Header.Get("Authorization")
|
|
||||||
if strings.HasPrefix(authHeader, "Bearer ") {
|
|
||||||
tokenStr := strings.TrimPrefix(authHeader, "Bearer ")
|
|
||||||
if claims, err := auth.ValidateToken(s.cfg.JWTSecret, tokenStr); err == nil && claims != nil {
|
|
||||||
var exp time.Time
|
|
||||||
if claims.ExpiresAt != nil {
|
|
||||||
exp = claims.ExpiresAt.Time
|
|
||||||
} else {
|
|
||||||
exp = time.Now().Add(30 * 24 * time.Hour)
|
|
||||||
}
|
|
||||||
_ = s.store.RevokeToken(tokenStr, userID, exp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, map[string]bool{"success": true})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) handleRevokeAllSessions(w http.ResponseWriter, r *http.Request) {
|
|
||||||
userID := auth.GetUserID(r.Context())
|
|
||||||
if err := s.store.RevokeAllUserTokens(userID); err != nil {
|
|
||||||
writeError(w, http.StatusInternalServerError, "Sitzungen konnten nicht beendet werden")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, map[string]bool{"success": true})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) handleUpdateUserSettings(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleUpdateUserSettings(w http.ResponseWriter, r *http.Request) {
|
||||||
userID := auth.GetUserID(r.Context())
|
userID := auth.GetUserID(r.Context())
|
||||||
var req struct {
|
var req struct {
|
||||||
@@ -2182,7 +1987,7 @@ func (s *Server) handleUpdateTaskList(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
tl, err := s.store.UpdateTaskList(userID, listID, req.Title, req.Icon, req.Color, req.TeamID, req.SpaceID, req.Columns)
|
tl, err := s.store.UpdateTaskList(userID, listID, req.Title, req.Icon, req.Color, req.TeamID, req.SpaceID, req.Columns)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeStoreError(w, http.StatusBadRequest, err)
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.wsHub.BroadcastToAll("TASK_LIST_UPDATED", tl)
|
s.wsHub.BroadcastToAll("TASK_LIST_UPDATED", tl)
|
||||||
@@ -2230,17 +2035,12 @@ func (s *Server) handleCreateTaskListShare(w http.ResponseWriter, r *http.Reques
|
|||||||
var req struct {
|
var req struct {
|
||||||
TargetType string `json:"targetType"` // team | user
|
TargetType string `json:"targetType"` // team | user
|
||||||
TargetID string `json:"targetId"`
|
TargetID string `json:"targetId"`
|
||||||
Permission string `json:"permission"` // editor | viewer
|
|
||||||
}
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
writeError(w, http.StatusBadRequest, "Ungültiges JSON")
|
writeError(w, http.StatusBadRequest, "Ungültiges JSON")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
permission := strings.ToLower(strings.TrimSpace(req.Permission))
|
share, err := s.store.AddTaskListShare(listID, req.TargetType, req.TargetID, userID)
|
||||||
if permission != "viewer" {
|
|
||||||
permission = "editor"
|
|
||||||
}
|
|
||||||
share, err := s.store.AddTaskListShare(listID, req.TargetType, req.TargetID, permission, userID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusBadRequest, err.Error())
|
writeError(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
+5
-467
@@ -2,7 +2,6 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@@ -10,7 +9,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/sandrodach/mindsift/internal/auth"
|
"github.com/sandrodach/mindsift/internal/auth"
|
||||||
"github.com/sandrodach/mindsift/internal/config"
|
"github.com/sandrodach/mindsift/internal/config"
|
||||||
@@ -45,7 +43,7 @@ func setupTestServer(t *testing.T) (*Server, *storage.Store, string) {
|
|||||||
hub := ws.NewHub()
|
hub := ws.NewHub()
|
||||||
srv := NewServer(cfg, store, hub, nil)
|
srv := NewServer(cfg, store, hub, nil)
|
||||||
|
|
||||||
token, err := auth.GenerateToken(cfg.JWTSecret, user.ID, user.Email, user.DisplayName, user.TokenVersion)
|
token, err := auth.GenerateToken(cfg.JWTSecret, user.ID, user.Email, user.DisplayName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to generate token: %v", err)
|
t.Fatalf("failed to generate token: %v", err)
|
||||||
}
|
}
|
||||||
@@ -219,7 +217,7 @@ func TestQuickDumpToTriageAndDirectTargets(t *testing.T) {
|
|||||||
router := srv.Router()
|
router := srv.Router()
|
||||||
|
|
||||||
// Verify stale token from non-existent user is rejected (401)
|
// Verify stale token from non-existent user is rejected (401)
|
||||||
staleToken, _ := auth.GenerateToken("test-jwt-secret-key", "usr_non_existent", "old@mindsift.local", "Old", 1)
|
staleToken, _ := auth.GenerateToken("test-jwt-secret-key", "usr_non_existent", "old@mindsift.local", "Old")
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/me", nil)
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/auth/me", nil)
|
||||||
req.Header.Set("Authorization", "Bearer "+staleToken)
|
req.Header.Set("Authorization", "Bearer "+staleToken)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
@@ -548,11 +546,11 @@ func TestSpaceMembersDirectInvitationAPI(t *testing.T) {
|
|||||||
t.Fatalf("failed to get normal user: %v", err)
|
t.Fatalf("failed to get normal user: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
adminToken, err := auth.GenerateToken(cfg.JWTSecret, adminUser.ID, adminUser.Email, adminUser.DisplayName, adminUser.TokenVersion)
|
adminToken, err := auth.GenerateToken(cfg.JWTSecret, adminUser.ID, adminUser.Email, adminUser.DisplayName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to generate token: %v", err)
|
t.Fatalf("failed to generate token: %v", err)
|
||||||
}
|
}
|
||||||
userToken, err := auth.GenerateToken(cfg.JWTSecret, normalUser.ID, normalUser.Email, normalUser.DisplayName, normalUser.TokenVersion)
|
userToken, err := auth.GenerateToken(cfg.JWTSecret, normalUser.ID, normalUser.Email, normalUser.DisplayName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to generate token: %v", err)
|
t.Fatalf("failed to generate token: %v", err)
|
||||||
}
|
}
|
||||||
@@ -663,7 +661,7 @@ func TestWorkspaceTagsAPI(t *testing.T) {
|
|||||||
router := srv.Router()
|
router := srv.Router()
|
||||||
|
|
||||||
user, _ := store.CreateUser("api_tag_user@example.com", "hash", "API Tag User", "member")
|
user, _ := store.CreateUser("api_tag_user@example.com", "hash", "API Tag User", "member")
|
||||||
token, _ := auth.GenerateToken(srv.cfg.JWTSecret, user.ID, user.Email, user.DisplayName, user.TokenVersion)
|
token, _ := auth.GenerateToken(srv.cfg.JWTSecret, user.ID, user.Email, user.DisplayName)
|
||||||
|
|
||||||
// Create document with hashtags
|
// Create document with hashtags
|
||||||
blocks := []domain.DocumentBlock{
|
blocks := []domain.DocumentBlock{
|
||||||
@@ -840,463 +838,3 @@ func TestWebhookTriageBadgeAndIngestion(t *testing.T) {
|
|||||||
t.Fatalf("expected thought content to contain 'Waschmaschine', got '%s'", ingestResp.Thought.Content)
|
t.Fatalf("expected thought content to contain 'Waschmaschine', got '%s'", ingestResp.Thought.Content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSSEGlobalEndpoint(t *testing.T) {
|
|
||||||
dbPath := filepath.Join(t.TempDir(), "test_sse.db")
|
|
||||||
store, err := storage.NewStore(dbPath)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to init store: %v", err)
|
|
||||||
}
|
|
||||||
defer store.Close()
|
|
||||||
|
|
||||||
hub := ws.NewHub()
|
|
||||||
cfg := &config.Config{
|
|
||||||
JWTSecret: "test-jwt-secret-key",
|
|
||||||
AllowRegistration: false,
|
|
||||||
}
|
|
||||||
srv := NewServer(cfg, store, hub, nil)
|
|
||||||
router := srv.Router()
|
|
||||||
|
|
||||||
setupBody := []byte(`{
|
|
||||||
"email": "sse_user@example.com",
|
|
||||||
"password": "secretpassword",
|
|
||||||
"displayName": "SSE User",
|
|
||||||
"instanceName": "MindSift SSE",
|
|
||||||
"allowRegistration": false,
|
|
||||||
"seedSampleData": false
|
|
||||||
}`)
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/auth/setup", bytes.NewReader(setupBody))
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec := httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusCreated {
|
|
||||||
t.Fatalf("setup failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
var authResp struct {
|
|
||||||
Token string `json:"token"`
|
|
||||||
User *domain.User `json:"user"`
|
|
||||||
}
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &authResp)
|
|
||||||
token := authResp.Token
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/events?token="+token, nil).WithContext(ctx)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
cancel()
|
|
||||||
}()
|
|
||||||
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
|
|
||||||
contentType := rec.Header().Get("Content-Type")
|
|
||||||
if !strings.Contains(contentType, "text/event-stream") {
|
|
||||||
t.Fatalf("expected Content-Type text/event-stream, got %s", contentType)
|
|
||||||
}
|
|
||||||
bodyStr := rec.Body.String()
|
|
||||||
if !strings.Contains(bodyStr, "SSE_CONNECTED") {
|
|
||||||
t.Fatalf("expected SSE_CONNECTED event in body, got: %s", bodyStr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDecoupledFolderSharingAPI(t *testing.T) {
|
|
||||||
srv, store, tokenA := setupTestServer(t)
|
|
||||||
router := srv.Router()
|
|
||||||
|
|
||||||
userB, err := store.CreateUser("user_b@example.com", "hash", "User B", "member")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create user B: %v", err)
|
|
||||||
}
|
|
||||||
tokenB, err := auth.GenerateToken(srv.cfg.JWTSecret, userB.ID, userB.Email, userB.DisplayName, userB.TokenVersion)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to generate token B: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. User A creates a shared folder "TeamProjekt"
|
|
||||||
shPayload := map[string]string{"name": "TeamProjekt", "mountPath": "TeamProjekt"}
|
|
||||||
b, _ := json.Marshal(shPayload)
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/workspace/folders/shared", bytes.NewReader(b))
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenA)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec := httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusCreated {
|
|
||||||
t.Fatalf("create shared folder failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
var shFolder domain.SharedFolder
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &shFolder)
|
|
||||||
|
|
||||||
// 2. User A creates a document inside "TeamProjekt"
|
|
||||||
docPayload := map[string]interface{}{
|
|
||||||
"title": "Spezifikation",
|
|
||||||
"folderPath": "TeamProjekt",
|
|
||||||
"blocks": []domain.DocumentBlock{
|
|
||||||
{ID: "blk_1", Type: "text", Content: "Projekt Details", Level: 0, Position: 1000},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
b, _ = json.Marshal(docPayload)
|
|
||||||
req = httptest.NewRequest(http.MethodPost, "/api/v1/documents", bytes.NewReader(b))
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenA)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusCreated {
|
|
||||||
t.Fatalf("create doc failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
var createdDoc domain.Document
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &createdDoc)
|
|
||||||
|
|
||||||
// 3. User A shares the folder with User B (write permission)
|
|
||||||
sharePayload := map[string]interface{}{
|
|
||||||
"userId": userB.ID,
|
|
||||||
"targetType": "user",
|
|
||||||
"permission": "write",
|
|
||||||
}
|
|
||||||
b, _ = json.Marshal(sharePayload)
|
|
||||||
req = httptest.NewRequest(http.MethodPost, "/api/v1/workspace/folders/shared/"+shFolder.ID+"/shares", bytes.NewReader(b))
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenA)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusCreated {
|
|
||||||
t.Fatalf("share folder failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. User B gets their documents list -> must see the document in "TeamProjekt"
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/documents", nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenB)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("get docs userB failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
var docsB []domain.Document
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &docsB)
|
|
||||||
var foundDocB *domain.Document
|
|
||||||
for i := range docsB {
|
|
||||||
if docsB[i].ID == createdDoc.ID {
|
|
||||||
foundDocB = &docsB[i]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if foundDocB == nil {
|
|
||||||
t.Fatalf("User B did not see shared document!")
|
|
||||||
}
|
|
||||||
if foundDocB.FolderPath != "TeamProjekt" {
|
|
||||||
t.Fatalf("expected User B initial folderPath 'TeamProjekt', got %q", foundDocB.FolderPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. User B moves their mount point to "MeineOrdner/TeamProjekt"
|
|
||||||
movePayload := map[string]string{
|
|
||||||
"sourcePath": "TeamProjekt",
|
|
||||||
"targetParentPath": "MeineOrdner",
|
|
||||||
}
|
|
||||||
b, _ = json.Marshal(movePayload)
|
|
||||||
req = httptest.NewRequest(http.MethodPost, "/api/v1/folders/move", bytes.NewReader(b))
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenB)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("User B move folder failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. DECOUPLED CHECK:
|
|
||||||
// User B's document path must now be "MeineOrdner/TeamProjekt"
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/documents/"+createdDoc.ID, nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenB)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("User B get doc failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
var docBAfterMove domain.Document
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &docBAfterMove)
|
|
||||||
if docBAfterMove.FolderPath != "MeineOrdner/TeamProjekt" {
|
|
||||||
t.Fatalf("expected User B folderPath 'MeineOrdner/TeamProjekt', got %q", docBAfterMove.FolderPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// User A's document path must STILL be "TeamProjekt" (completely decoupled!)
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/documents/"+createdDoc.ID, nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenA)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("User A get doc failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
var docAAfterMove domain.Document
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &docAAfterMove)
|
|
||||||
if docAAfterMove.FolderPath != "TeamProjekt" {
|
|
||||||
t.Fatalf("User A's folder hierarchy was altered! Expected 'TeamProjekt', got %q", docAAfterMove.FolderPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 7. Synchronous contents check:
|
|
||||||
// User B (read-only recipient) cannot move documents within the shared folder:
|
|
||||||
moveDocPayload := map[string]string{
|
|
||||||
"folderPath": "MeineOrdner/TeamProjekt/Archiv",
|
|
||||||
}
|
|
||||||
b, _ = json.Marshal(moveDocPayload)
|
|
||||||
req = httptest.NewRequest(http.MethodPut, "/api/v1/documents/"+createdDoc.ID+"/move", bytes.NewReader(b))
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenB)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusBadRequest {
|
|
||||||
t.Fatalf("Expected User B move doc in read-only shared folder to fail, got %d", rec.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// User A (the owner) moves the document into a subfolder: "TeamProjekt/Archiv"
|
|
||||||
moveDocPayload = map[string]string{
|
|
||||||
"folderPath": "TeamProjekt/Archiv",
|
|
||||||
}
|
|
||||||
b, _ = json.Marshal(moveDocPayload)
|
|
||||||
req = httptest.NewRequest(http.MethodPut, "/api/v1/documents/"+createdDoc.ID+"/move", bytes.NewReader(b))
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenA)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("User A move doc into subfolder failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// User B must now see the document synchronized at "MeineOrdner/TeamProjekt/Archiv"!
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/documents/"+createdDoc.ID, nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenB)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("User B get doc failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
var docBSynced domain.Document
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &docBSynced)
|
|
||||||
if docBSynced.FolderPath != "MeineOrdner/TeamProjekt/Archiv" {
|
|
||||||
t.Fatalf("expected User B to see subfolder sync at 'MeineOrdner/TeamProjekt/Archiv', got %q", docBSynced.FolderPath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTokenBlacklistingAndTokenVersionRevocation(t *testing.T) {
|
|
||||||
srv, store, _ := setupTestServer(t)
|
|
||||||
router := srv.Router()
|
|
||||||
|
|
||||||
// 1. Create a fresh user with known password
|
|
||||||
password := "initialPassword123"
|
|
||||||
hash, _ := auth.HashPassword(password)
|
|
||||||
user, err := store.CreateUser("revocation_test@example.com", hash, "Revocation Tester", "member")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create user: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Perform login to get initial JWT
|
|
||||||
loginBody, _ := json.Marshal(map[string]string{
|
|
||||||
"login": user.Email,
|
|
||||||
"password": password,
|
|
||||||
})
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/auth/login", bytes.NewReader(loginBody))
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec := httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("login failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
var loginResp struct {
|
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &loginResp)
|
|
||||||
token1 := loginResp.Token
|
|
||||||
if token1 == "" {
|
|
||||||
t.Fatalf("expected token in login response")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Verify token1 works
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/auth/me", nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token1)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("token1 should be valid, got %d", rec.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Test explicit logout (blacklists token1)
|
|
||||||
req = httptest.NewRequest(http.MethodPost, "/api/v1/auth/logout", nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token1)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("logout failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Token1 must now be blacklisted and rejected (401)
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/auth/me", nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token1)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusUnauthorized {
|
|
||||||
t.Fatalf("expected 401 Unauthorized for blacklisted token1, got %d", rec.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also check authenticateUserFromReq rejects token1
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/ws?token="+token1, nil)
|
|
||||||
if uid := srv.authenticateUserFromReq(req); uid != "" {
|
|
||||||
t.Fatalf("authenticateUserFromReq should reject blacklisted token1, got uid %q", uid)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. Login again to get token2
|
|
||||||
req = httptest.NewRequest(http.MethodPost, "/api/v1/auth/login", bytes.NewReader(loginBody))
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
var loginResp2 struct {
|
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &loginResp2)
|
|
||||||
token2 := loginResp2.Token
|
|
||||||
|
|
||||||
// Token2 works
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/auth/me", nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token2)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("token2 should be valid, got %d", rec.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. Change password via UpdateUserPassword -> increments token_version
|
|
||||||
newPassword := "newSecretPassword456"
|
|
||||||
newHash, _ := auth.HashPassword(newPassword)
|
|
||||||
if err := store.UpdateUserPassword(user.ID, newHash); err != nil {
|
|
||||||
t.Fatalf("failed to update password: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Token2 must now be REJECTED (401) because its token_version is outdated!
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/auth/me", nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token2)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusUnauthorized {
|
|
||||||
t.Fatalf("expected 401 Unauthorized for token2 after password change, got %d", rec.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 7. Login with new password to get token3
|
|
||||||
loginNewBody, _ := json.Marshal(map[string]string{
|
|
||||||
"login": user.Email,
|
|
||||||
"password": newPassword,
|
|
||||||
})
|
|
||||||
req = httptest.NewRequest(http.MethodPost, "/api/v1/auth/login", bytes.NewReader(loginNewBody))
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
var loginResp3 struct {
|
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
|
||||||
_ = json.Unmarshal(rec.Body.Bytes(), &loginResp3)
|
|
||||||
token3 := loginResp3.Token
|
|
||||||
|
|
||||||
// Token3 works
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/auth/me", nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token3)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("token3 should be valid, got %d", rec.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 8. Test revoke-all endpoint -> increments token_version and invalidates all existing sessions
|
|
||||||
req = httptest.NewRequest(http.MethodPost, "/api/v1/auth/revoke-all", nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token3)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("revoke-all failed: %s", rec.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Token3 must now be REJECTED (401)
|
|
||||||
req = httptest.NewRequest(http.MethodGet, "/api/v1/auth/me", nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token3)
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusUnauthorized {
|
|
||||||
t.Fatalf("expected 401 Unauthorized for token3 after revoke-all, got %d", rec.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocumentSharingStrictlyReadOnly(t *testing.T) {
|
|
||||||
srv, store, _ := setupTestServer(t)
|
|
||||||
router := srv.Router()
|
|
||||||
|
|
||||||
userA, _ := store.CreateUser("user_a_ro@example.com", "hash", "User A", "member")
|
|
||||||
tokenA, _ := auth.GenerateToken(srv.cfg.JWTSecret, userA.ID, userA.Email, userA.DisplayName, userA.TokenVersion)
|
|
||||||
|
|
||||||
userB, _ := store.CreateUser("user_b_ro@example.com", "hash", "User B", "member")
|
|
||||||
tokenB, _ := auth.GenerateToken(srv.cfg.JWTSecret, userB.ID, userB.Email, userB.DisplayName, userB.TokenVersion)
|
|
||||||
|
|
||||||
// Create document owned by User A
|
|
||||||
blocks := []domain.DocumentBlock{
|
|
||||||
{ID: "b1", Type: "bullet", Content: "Row 1", Level: 0},
|
|
||||||
{ID: "b2", Type: "bullet", Content: "Row 2", Level: 0},
|
|
||||||
}
|
|
||||||
doc, err := store.CreateDocument(userA.ID, "", "Read Only Test Doc", "📝", "", blocks, nil, false)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("CreateDocument failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Share with User B (forced read-only)
|
|
||||||
_, err = store.CreateDocShare(userA.ID, doc.ID, userB.ID, "read")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("CreateDocShare failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. User B can read document
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/v1/documents/"+doc.ID, nil)
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenB)
|
|
||||||
rec := httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("User B should be able to read doc, got status: %d", rec.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. User B tries to update document via PUT -> must fail (not owner)
|
|
||||||
newTitle := "Hacked Title"
|
|
||||||
updateBody, _ := json.Marshal(map[string]interface{}{"title": newTitle})
|
|
||||||
req = httptest.NewRequest(http.MethodPut, "/api/v1/documents/"+doc.ID, bytes.NewReader(updateBody))
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenB)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code == http.StatusOK {
|
|
||||||
t.Fatalf("expected error for User B updating document, got 200 OK")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. User B tries to patch document blocks -> must fail (not owner)
|
|
||||||
patchBody, _ := json.Marshal(domain.DocBlocksPatchRequest{
|
|
||||||
Upserted: []domain.DocumentBlock{{ID: "b2", Content: "Hacked by User B"}},
|
|
||||||
})
|
|
||||||
req = httptest.NewRequest(http.MethodPatch, "/api/v1/documents/"+doc.ID+"/blocks", bytes.NewReader(patchBody))
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenB)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code == http.StatusOK {
|
|
||||||
t.Fatalf("expected error for User B patching document blocks, got 200 OK")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. User A (owner) can successfully update document
|
|
||||||
ownerTitle := "Owner Updated Title"
|
|
||||||
ownerBody, _ := json.Marshal(map[string]interface{}{"title": ownerTitle})
|
|
||||||
req = httptest.NewRequest(http.MethodPut, "/api/v1/documents/"+doc.ID, bytes.NewReader(ownerBody))
|
|
||||||
req.Header.Set("Authorization", "Bearer "+tokenA)
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
rec = httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(rec, req)
|
|
||||||
if rec.Code != http.StatusOK {
|
|
||||||
t.Fatalf("owner should be able to update document, got %d", rec.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+3
-14
@@ -21,7 +21,6 @@ type Claims struct {
|
|||||||
UserID string `json:"userId"`
|
UserID string `json:"userId"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
DisplayName string `json:"displayName"`
|
DisplayName string `json:"displayName"`
|
||||||
TokenVersion int `json:"tokenVersion"`
|
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,24 +34,14 @@ func CheckPassword(password, hash string) bool {
|
|||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateToken(secret, userID, email, displayName string, tokenVersion int) (string, error) {
|
func GenerateToken(secret, userID, email, displayName string) (string, error) {
|
||||||
if tokenVersion <= 0 {
|
|
||||||
tokenVersion = 1
|
|
||||||
}
|
|
||||||
b := make([]byte, 16)
|
|
||||||
_, _ = rand.Read(b)
|
|
||||||
jti := hex.EncodeToString(b)
|
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
claims := &Claims{
|
claims := &Claims{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Email: email,
|
Email: email,
|
||||||
DisplayName: displayName,
|
DisplayName: displayName,
|
||||||
TokenVersion: tokenVersion,
|
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
ID: jti,
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(30 * 24 * time.Hour)),
|
||||||
ExpiresAt: jwt.NewNumericDate(now.Add(30 * 24 * time.Hour)),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
IssuedAt: jwt.NewNumericDate(now),
|
|
||||||
Issuer: "mindsift",
|
Issuer: "mindsift",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -15,7 +14,6 @@ type Config struct {
|
|||||||
BaseURL string
|
BaseURL string
|
||||||
AllowRegistration bool
|
AllowRegistration bool
|
||||||
LogLevel string
|
LogLevel string
|
||||||
Debug bool
|
|
||||||
DemoMode bool
|
DemoMode bool
|
||||||
|
|
||||||
// Optional SMTP environment variables (can also be overridden/configured in DB system_settings)
|
// Optional SMTP environment variables (can also be overridden/configured in DB system_settings)
|
||||||
@@ -42,14 +40,7 @@ func Load() *Config {
|
|||||||
jwtSecret := getEnv("JWT_SECRET", "mindsift-default-selfhosted-jwt-secret-key-2026")
|
jwtSecret := getEnv("JWT_SECRET", "mindsift-default-selfhosted-jwt-secret-key-2026")
|
||||||
baseURL := getEnv("BASE_URL", "http://localhost:"+port)
|
baseURL := getEnv("BASE_URL", "http://localhost:"+port)
|
||||||
allowReg := strings.ToLower(getEnv("ALLOW_REGISTRATION", "false")) == "true"
|
allowReg := strings.ToLower(getEnv("ALLOW_REGISTRATION", "false")) == "true"
|
||||||
|
logLevel := getEnv("LOG_LEVEL", "info")
|
||||||
debugVal := strings.ToLower(getEnv("DEBUG", "false"))
|
|
||||||
debug := debugVal == "true" || debugVal == "1" || debugVal == "yes" || debugVal == "on"
|
|
||||||
|
|
||||||
logLevel := strings.ToLower(getEnv("LOG_LEVEL", "info"))
|
|
||||||
if debug {
|
|
||||||
logLevel = "debug"
|
|
||||||
}
|
|
||||||
|
|
||||||
demoVal := strings.ToLower(getEnv("MINDA_DEMO", getEnv("MINDSIFT_DEMO", getEnv("DEMO_MODE", "false"))))
|
demoVal := strings.ToLower(getEnv("MINDA_DEMO", getEnv("MINDSIFT_DEMO", getEnv("DEMO_MODE", "false"))))
|
||||||
demoMode := demoVal == "true" || demoVal == "1" || demoVal == "yes" || demoVal == "on"
|
demoMode := demoVal == "true" || demoVal == "1" || demoVal == "yes" || demoVal == "on"
|
||||||
@@ -69,7 +60,6 @@ func Load() *Config {
|
|||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
AllowRegistration: allowReg,
|
AllowRegistration: allowReg,
|
||||||
LogLevel: logLevel,
|
LogLevel: logLevel,
|
||||||
Debug: debug,
|
|
||||||
DemoMode: demoMode,
|
DemoMode: demoMode,
|
||||||
SMTPHost: smtpHost,
|
SMTPHost: smtpHost,
|
||||||
SMTPPort: smtpPort,
|
SMTPPort: smtpPort,
|
||||||
@@ -80,20 +70,6 @@ func Load() *Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SlogLevel parses Config.LogLevel into a standard slog.Level.
|
|
||||||
func (c *Config) SlogLevel() slog.Level {
|
|
||||||
switch strings.ToLower(strings.TrimSpace(c.LogLevel)) {
|
|
||||||
case "debug":
|
|
||||||
return slog.LevelDebug
|
|
||||||
case "warn", "warning":
|
|
||||||
return slog.LevelWarn
|
|
||||||
case "error":
|
|
||||||
return slog.LevelError
|
|
||||||
default:
|
|
||||||
return slog.LevelInfo
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getEnv(key, fallback string) string {
|
func getEnv(key, fallback string) string {
|
||||||
if val, ok := os.LookupEnv(key); ok && strings.TrimSpace(val) != "" {
|
if val, ok := os.LookupEnv(key); ok && strings.TrimSpace(val) != "" {
|
||||||
return strings.TrimSpace(val)
|
return strings.TrimSpace(val)
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log/slog"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestConfigLogLevelAndDebug(t *testing.T) {
|
|
||||||
os.Setenv("PORT", "9090")
|
|
||||||
defer os.Unsetenv("PORT")
|
|
||||||
|
|
||||||
// 1. Default info
|
|
||||||
os.Unsetenv("LOG_LEVEL")
|
|
||||||
os.Unsetenv("DEBUG")
|
|
||||||
cfg := Load()
|
|
||||||
if cfg.SlogLevel() != slog.LevelInfo {
|
|
||||||
t.Fatalf("expected LevelInfo, got %v", cfg.SlogLevel())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. LOG_LEVEL=debug
|
|
||||||
os.Setenv("LOG_LEVEL", "debug")
|
|
||||||
cfg = Load()
|
|
||||||
if cfg.SlogLevel() != slog.LevelDebug {
|
|
||||||
t.Fatalf("expected LevelDebug, got %v", cfg.SlogLevel())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. LOG_LEVEL=warn
|
|
||||||
os.Setenv("LOG_LEVEL", "warn")
|
|
||||||
cfg = Load()
|
|
||||||
if cfg.SlogLevel() != slog.LevelWarn {
|
|
||||||
t.Fatalf("expected LevelWarn, got %v", cfg.SlogLevel())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. LOG_LEVEL=error
|
|
||||||
os.Setenv("LOG_LEVEL", "error")
|
|
||||||
cfg = Load()
|
|
||||||
if cfg.SlogLevel() != slog.LevelError {
|
|
||||||
t.Fatalf("expected LevelError, got %v", cfg.SlogLevel())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. DEBUG=true overrides LOG_LEVEL
|
|
||||||
os.Setenv("LOG_LEVEL", "error")
|
|
||||||
os.Setenv("DEBUG", "true")
|
|
||||||
cfg = Load()
|
|
||||||
if cfg.SlogLevel() != slog.LevelDebug {
|
|
||||||
t.Fatalf("expected LevelDebug when DEBUG=true, got %v", cfg.SlogLevel())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. DEBUG=1 overrides LOG_LEVEL
|
|
||||||
os.Setenv("DEBUG", "1")
|
|
||||||
cfg = Load()
|
|
||||||
if cfg.SlogLevel() != slog.LevelDebug {
|
|
||||||
t.Fatalf("expected LevelDebug when DEBUG=1, got %v", cfg.SlogLevel())
|
|
||||||
}
|
|
||||||
os.Unsetenv("DEBUG")
|
|
||||||
os.Unsetenv("LOG_LEVEL")
|
|
||||||
}
|
|
||||||
@@ -101,7 +101,6 @@ type User struct {
|
|||||||
AvatarURL string `json:"avatarUrl,omitempty"`
|
AvatarURL string `json:"avatarUrl,omitempty"`
|
||||||
Role string `json:"role"` // admin | member
|
Role string `json:"role"` // admin | member
|
||||||
IsActive bool `json:"isActive"`
|
IsActive bool `json:"isActive"`
|
||||||
TokenVersion int `json:"tokenVersion"`
|
|
||||||
AlarmChannels []string `json:"alarmChannels"` // email | discord | webhook
|
AlarmChannels []string `json:"alarmChannels"` // email | discord | webhook
|
||||||
AlarmEmail string `json:"alarmEmail"`
|
AlarmEmail string `json:"alarmEmail"`
|
||||||
DiscordWebhookURL string `json:"discordWebhookUrl"`
|
DiscordWebhookURL string `json:"discordWebhookUrl"`
|
||||||
@@ -148,10 +147,8 @@ type Thought struct {
|
|||||||
Source string `json:"source"` // manual | voice | webhook
|
Source string `json:"source"` // manual | voice | webhook
|
||||||
Status ThoughtStatus `json:"status"`
|
Status ThoughtStatus `json:"status"`
|
||||||
IsCompleted bool `json:"isCompleted"`
|
IsCompleted bool `json:"isCompleted"`
|
||||||
ConvertedType string `json:"convertedType,omitempty"` // task | document | list_item | document_block
|
ConvertedType string `json:"convertedType,omitempty"` // task | document | list_item
|
||||||
ConvertedRefID string `json:"convertedRefId,omitempty"` // referenced entity ID
|
ConvertedRefID string `json:"convertedRefId,omitempty"` // referenced entity ID
|
||||||
DocID string `json:"docId,omitempty"`
|
|
||||||
BlockID string `json:"blockId,omitempty"`
|
|
||||||
DueDate string `json:"dueDate,omitempty"`
|
DueDate string `json:"dueDate,omitempty"`
|
||||||
TaskListID string `json:"taskListId,omitempty"`
|
TaskListID string `json:"taskListId,omitempty"`
|
||||||
KanbanStatus string `json:"kanbanStatus,omitempty"` // todo | in_progress | done
|
KanbanStatus string `json:"kanbanStatus,omitempty"` // todo | in_progress | done
|
||||||
@@ -184,7 +181,6 @@ type TaskListShare struct {
|
|||||||
TargetName string `json:"targetName,omitempty"`
|
TargetName string `json:"targetName,omitempty"`
|
||||||
Email string `json:"email,omitempty"`
|
Email string `json:"email,omitempty"`
|
||||||
AvatarURL string `json:"avatarUrl,omitempty"`
|
AvatarURL string `json:"avatarUrl,omitempty"`
|
||||||
Permission string `json:"permission"` // editor | viewer
|
|
||||||
CreatedAt string `json:"createdAt"`
|
CreatedAt string `json:"createdAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +208,6 @@ type TaskList struct {
|
|||||||
TeamName string `json:"teamName,omitempty"`
|
TeamName string `json:"teamName,omitempty"`
|
||||||
OwnerName string `json:"ownerName,omitempty"`
|
OwnerName string `json:"ownerName,omitempty"`
|
||||||
IsOwner bool `json:"isOwner"`
|
IsOwner bool `json:"isOwner"`
|
||||||
Permission string `json:"permission,omitempty"` // owner | editor | viewer
|
|
||||||
Members []TaskListMember `json:"members,omitempty"`
|
Members []TaskListMember `json:"members,omitempty"`
|
||||||
Shares []TaskListShare `json:"shares,omitempty"`
|
Shares []TaskListShare `json:"shares,omitempty"`
|
||||||
Columns []KanbanColumn `json:"columns,omitempty"`
|
Columns []KanbanColumn `json:"columns,omitempty"`
|
||||||
@@ -266,47 +261,12 @@ type SystemSettings struct {
|
|||||||
|
|
||||||
type DocumentBlock struct {
|
type DocumentBlock struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
DocumentID string `json:"documentId,omitempty"`
|
|
||||||
Type string `json:"type"` // h1 | h2 | h3 | paragraph | todo | bullet | code | callout | divider | table | progress
|
Type string `json:"type"` // h1 | h2 | h3 | paragraph | todo | bullet | code | callout | divider | table | progress
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Checked bool `json:"checked,omitempty"`
|
Checked bool `json:"checked,omitempty"`
|
||||||
Lang string `json:"lang,omitempty"`
|
Lang string `json:"lang,omitempty"`
|
||||||
Level int `json:"level"`
|
Level int `json:"level,omitempty"`
|
||||||
Position float64 `json:"position"`
|
|
||||||
Collapsed bool `json:"collapsed,omitempty"`
|
Collapsed bool `json:"collapsed,omitempty"`
|
||||||
TaskID string `json:"taskId,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func CompileBlocksToMarkdown(blocks []DocumentBlock) string {
|
|
||||||
var sb strings.Builder
|
|
||||||
for _, b := range blocks {
|
|
||||||
lvl := b.Level
|
|
||||||
if lvl < 0 {
|
|
||||||
lvl = 0
|
|
||||||
}
|
|
||||||
indent := strings.Repeat(" ", lvl)
|
|
||||||
switch b.Type {
|
|
||||||
case "h1":
|
|
||||||
sb.WriteString(indent + "- # " + b.Content + "\n")
|
|
||||||
case "h2":
|
|
||||||
sb.WriteString(indent + "- ## " + b.Content + "\n")
|
|
||||||
case "h3":
|
|
||||||
sb.WriteString(indent + "- ### " + b.Content + "\n")
|
|
||||||
case "todo":
|
|
||||||
mark := "[ ]"
|
|
||||||
if b.Checked {
|
|
||||||
mark = "[x]"
|
|
||||||
}
|
|
||||||
sb.WriteString(indent + "- " + mark + " " + b.Content + "\n")
|
|
||||||
case "code":
|
|
||||||
sb.WriteString(indent + "- ```" + b.Lang + "\n" + b.Content + "\n" + indent + " ```\n")
|
|
||||||
case "divider":
|
|
||||||
sb.WriteString(indent + "- ---\n")
|
|
||||||
default:
|
|
||||||
sb.WriteString(indent + "- " + b.Content + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocBlocksPatchRequest struct {
|
type DocBlocksPatchRequest struct {
|
||||||
@@ -342,6 +302,13 @@ type DocShare struct {
|
|||||||
CreatedAt string `json:"createdAt"`
|
CreatedAt string `json:"createdAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DocLockInfo struct {
|
||||||
|
DocID string `json:"docId"`
|
||||||
|
UserID string `json:"userId"`
|
||||||
|
UserName string `json:"userName"`
|
||||||
|
ExpiresAt string `json:"expiresAt"`
|
||||||
|
}
|
||||||
|
|
||||||
type Document struct {
|
type Document struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
UserID string `json:"userId"`
|
UserID string `json:"userId"`
|
||||||
@@ -349,10 +316,8 @@ type Document struct {
|
|||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Icon string `json:"icon"`
|
Icon string `json:"icon"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
MarkdownCache string `json:"markdownCache,omitempty"`
|
|
||||||
Blocks []DocumentBlock `json:"blocks"`
|
Blocks []DocumentBlock `json:"blocks"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
FolderID string `json:"folderId,omitempty"`
|
|
||||||
FolderPath string `json:"folderPath,omitempty"`
|
FolderPath string `json:"folderPath,omitempty"`
|
||||||
IsPinned bool `json:"isPinned"`
|
IsPinned bool `json:"isPinned"`
|
||||||
IsArchived bool `json:"isArchived"`
|
IsArchived bool `json:"isArchived"`
|
||||||
|
|||||||
+135
-599
File diff suppressed because it is too large.
Load diff
+32
-118
@@ -1,7 +1,7 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ func TestStoreLifecycle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test TaskList Sharing with Team
|
// Test TaskList Sharing with Team
|
||||||
shareTeam, err := store.AddTaskListShare(taskList.ID, "team", team.ID, "editor", user.ID)
|
shareTeam, err := store.AddTaskListShare(taskList.ID, "team", team.ID, user.ID)
|
||||||
if err != nil || shareTeam.ID == "" {
|
if err != nil || shareTeam.ID == "" {
|
||||||
t.Fatalf("AddTaskListShare team failed: %v", err)
|
t.Fatalf("AddTaskListShare team failed: %v", err)
|
||||||
}
|
}
|
||||||
@@ -148,45 +148,6 @@ func TestStoreLifecycle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("CreateUser collab failed: %v", err)
|
t.Fatalf("CreateUser collab failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test read-only TaskList share
|
|
||||||
ownerTask, err := store.CreateThoughtWithDetails(user.ID, "Rasen mähen", "normal", "manual", "", taskList.ID, "todo", "")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("CreateThoughtWithDetails in own list failed: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := store.UpdateThoughtTriage(user.ID, ownerTask.ID, "keep", "task", "", "", taskList.ID); err != nil {
|
|
||||||
t.Fatalf("UpdateThoughtTriage in own list failed: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := store.AddTaskListShare(taskList.ID, "user", user2.ID, "viewer", user.ID); err != nil {
|
|
||||||
t.Fatalf("AddTaskListShare viewer failed: %v", err)
|
|
||||||
}
|
|
||||||
if perm := store.GetTaskListPermission(user2.ID, taskList.ID); perm != "viewer" {
|
|
||||||
t.Fatalf("expected viewer permission, got %q", perm)
|
|
||||||
}
|
|
||||||
viewerTasks, err := store.GetTasks(user2.ID, taskList.ID)
|
|
||||||
if err != nil || len(viewerTasks) == 0 {
|
|
||||||
t.Fatalf("viewer should see tasks of shared list: %v", err)
|
|
||||||
}
|
|
||||||
done := true
|
|
||||||
if _, err := store.UpdateThoughtDetails(user2.ID, ownerTask.ID, nil, &done, nil, nil, nil, nil, nil, nil, nil); !errors.Is(err, ErrTaskListReadOnly) {
|
|
||||||
t.Fatalf("viewer must not update tasks, got %v", err)
|
|
||||||
}
|
|
||||||
if _, err := store.CreateThoughtWithDetails(user2.ID, "Hack", "normal", "manual", "", taskList.ID, "todo", ""); !errors.Is(err, ErrTaskListReadOnly) {
|
|
||||||
t.Fatalf("viewer must not create tasks, got %v", err)
|
|
||||||
}
|
|
||||||
if err := store.DeleteThought(user2.ID, ownerTask.ID); !errors.Is(err, ErrTaskListReadOnly) {
|
|
||||||
t.Fatalf("viewer must not delete tasks, got %v", err)
|
|
||||||
}
|
|
||||||
newTitle := "Umbenannt"
|
|
||||||
if _, err := store.UpdateTaskList(user2.ID, taskList.ID, &newTitle, nil, nil, nil, nil, nil); !errors.Is(err, ErrTaskListReadOnly) {
|
|
||||||
t.Fatalf("viewer must not update task list, got %v", err)
|
|
||||||
}
|
|
||||||
if _, err := store.AddTaskListShare(taskList.ID, "user", user2.ID, "editor", user.ID); err != nil {
|
|
||||||
t.Fatalf("upgrading share to editor failed: %v", err)
|
|
||||||
}
|
|
||||||
if !store.CanEditTaskList(user2.ID, taskList.ID) {
|
|
||||||
t.Fatalf("editor share should allow editing")
|
|
||||||
}
|
|
||||||
newDoc, err := store.CreateDocument(user.ID, "", "Test Note", "📄", "", []domain.DocumentBlock{
|
newDoc, err := store.CreateDocument(user.ID, "", "Test Note", "📄", "", []domain.DocumentBlock{
|
||||||
{ID: "blk_1", Type: "bullet", Content: "Geheim", Level: 0},
|
{ID: "blk_1", Type: "bullet", Content: "Geheim", Level: 0},
|
||||||
}, []string{"test"}, false)
|
}, []string{"test"}, false)
|
||||||
@@ -213,10 +174,16 @@ func TestStoreLifecycle(t *testing.T) {
|
|||||||
t.Fatalf("expected UpdateDocument to fail for read-only user, but succeeded")
|
t.Fatalf("expected UpdateDocument to fail for read-only user, but succeeded")
|
||||||
}
|
}
|
||||||
|
|
||||||
// user2 is a read-only collaborator -> editing must fail
|
// Upgrade to write permission
|
||||||
|
_, err = store.CreateDocShare(user.ID, newDoc.ID, user2.ID, "write")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Upgrade CreateDocShare failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// user2 edits writeable doc -> must succeed
|
||||||
_, err = store.UpdateDocument(user2.ID, newDoc.ID, &updatedTitle, nil, nil, nil, nil, nil)
|
_, err = store.UpdateDocument(user2.ID, newDoc.ID, &updatedTitle, nil, nil, nil, nil, nil)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
t.Fatalf("expected UpdateDocument to fail for read-only collaborator, but succeeded")
|
t.Fatalf("UpdateDocument failed for write collaborator: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove share
|
// Remove share
|
||||||
@@ -365,6 +332,7 @@ func TestEnsureDemoAccountsAndLoginLookup(t *testing.T) {
|
|||||||
func TestFolderManagementAndDeletion(t *testing.T) {
|
func TestFolderManagementAndDeletion(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
dbPath := filepath.Join(tmpDir, "folder_test.db")
|
dbPath := filepath.Join(tmpDir, "folder_test.db")
|
||||||
|
docDir := filepath.Join(tmpDir, "workspace")
|
||||||
|
|
||||||
store, err := NewStore(dbPath)
|
store, err := NewStore(dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -377,7 +345,7 @@ func TestFolderManagementAndDeletion(t *testing.T) {
|
|||||||
t.Fatalf("CreateUser failed: %v", err)
|
t.Fatalf("CreateUser failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Create folders
|
// 1. Create folders on disk
|
||||||
f1, err := store.CreateFolder(user.ID, "Projekte/MindSift")
|
f1, err := store.CreateFolder(user.ID, "Projekte/MindSift")
|
||||||
if err != nil || f1 != "Projekte/MindSift" {
|
if err != nil || f1 != "Projekte/MindSift" {
|
||||||
t.Fatalf("CreateFolder failed: %v, f1=%s", err, f1)
|
t.Fatalf("CreateFolder failed: %v, f1=%s", err, f1)
|
||||||
@@ -433,6 +401,12 @@ func TestFolderManagementAndDeletion(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected doc2 to be deleted")
|
t.Fatalf("expected doc2 to be deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify disk directory was deleted
|
||||||
|
diskFolder := filepath.Join(docDir, user.ID, "Projekte/MindSift")
|
||||||
|
if _, err := os.Stat(diskFolder); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("expected directory %s to be deleted on disk", diskFolder)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWorkspaceBlockHashtagsAndDetails(t *testing.T) {
|
func TestWorkspaceBlockHashtagsAndDetails(t *testing.T) {
|
||||||
@@ -585,7 +559,8 @@ func TestDatabaseFirstWorkspaceArchitecture(t *testing.T) {
|
|||||||
t.Fatalf("MoveDocument by userB failed: %v", err)
|
t.Fatalf("MoveDocument by userB failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// User B is a read-only collaborator -> PatchDocumentBlocks must fail
|
// User B edits the document via PatchDocumentBlocks (modifying b2 and adding b3)
|
||||||
|
// Simultaneously, User A edits b1 and adds b4 using a slightly stale order
|
||||||
_, _, err = store.PatchDocumentBlocks(userB.ID, doc.ID, domain.DocBlocksPatchRequest{
|
_, _, err = store.PatchDocumentBlocks(userB.ID, doc.ID, domain.DocBlocksPatchRequest{
|
||||||
Upserted: []domain.DocumentBlock{
|
Upserted: []domain.DocumentBlock{
|
||||||
{ID: "b2", Type: "bullet", Content: "Zeile 2 von B bearbeitet", Level: 0},
|
{ID: "b2", Type: "bullet", Content: "Zeile 2 von B bearbeitet", Level: 0},
|
||||||
@@ -593,8 +568,8 @@ func TestDatabaseFirstWorkspaceArchitecture(t *testing.T) {
|
|||||||
},
|
},
|
||||||
BlockOrder: []string{"b1", "b2", "b3"},
|
BlockOrder: []string{"b1", "b2", "b3"},
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
t.Fatalf("expected PatchDocumentBlocks by read-only userB to fail, but succeeded")
|
t.Fatalf("PatchDocumentBlocks by userB failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// User A's client only knew about b1, b2 when sending its patch (adds b4)
|
// User A's client only knew about b1, b2 when sending its patch (adds b4)
|
||||||
@@ -609,9 +584,9 @@ func TestDatabaseFirstWorkspaceArchitecture(t *testing.T) {
|
|||||||
t.Fatalf("PatchDocumentBlocks by userA failed: %v", err)
|
t.Fatalf("PatchDocumentBlocks by userA failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify User A's blocks are preserved: b1, b2, b4 (3 blocks)
|
// Verify NO blocks were lost! All 4 blocks (b1, b2, b3, b4) must exist with both users' edits preserved
|
||||||
if len(patchedDocA.Blocks) != 3 {
|
if len(patchedDocA.Blocks) != 4 {
|
||||||
t.Fatalf("expected 3 blocks after patch, got %d: %+v", len(patchedDocA.Blocks), patchedDocA.Blocks)
|
t.Fatalf("expected 4 blocks after concurrent patches, got %d: %+v", len(patchedDocA.Blocks), patchedDocA.Blocks)
|
||||||
}
|
}
|
||||||
blockContent := make(map[string]string)
|
blockContent := make(map[string]string)
|
||||||
for _, b := range patchedDocA.Blocks {
|
for _, b := range patchedDocA.Blocks {
|
||||||
@@ -620,6 +595,12 @@ func TestDatabaseFirstWorkspaceArchitecture(t *testing.T) {
|
|||||||
if blockContent["b1"] != "Zeile 1 von A bearbeitet" {
|
if blockContent["b1"] != "Zeile 1 von A bearbeitet" {
|
||||||
t.Fatalf("expected b1 updated by A, got %q", blockContent["b1"])
|
t.Fatalf("expected b1 updated by A, got %q", blockContent["b1"])
|
||||||
}
|
}
|
||||||
|
if blockContent["b2"] != "Zeile 2 von B bearbeitet" {
|
||||||
|
t.Fatalf("expected b2 updated by B to be preserved, got %q", blockContent["b2"])
|
||||||
|
}
|
||||||
|
if blockContent["b3"] != "Zeile 3 neu von B" {
|
||||||
|
t.Fatalf("expected b3 added by B to be preserved even with stale order from A, got %q", blockContent["b3"])
|
||||||
|
}
|
||||||
if blockContent["b4"] != "Zeile 4 neu von A" {
|
if blockContent["b4"] != "Zeile 4 neu von A" {
|
||||||
t.Fatalf("expected b4 added by A, got %q", blockContent["b4"])
|
t.Fatalf("expected b4 added by A, got %q", blockContent["b4"])
|
||||||
}
|
}
|
||||||
@@ -710,70 +691,3 @@ func TestDatabaseFirstWorkspaceArchitecture(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlushDocumentStateAndSchema(t *testing.T) {
|
|
||||||
tmpDir := t.TempDir()
|
|
||||||
dbPath := filepath.Join(tmpDir, "tabula_rasa_test.db")
|
|
||||||
|
|
||||||
store, err := NewStore(dbPath)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("NewStore failed: %v", err)
|
|
||||||
}
|
|
||||||
defer store.Close()
|
|
||||||
|
|
||||||
user, err := store.CreateUser("outliner@example.com", "hash", "Outliner User", "member")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("CreateUser failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
doc, err := store.CreateDocument(user.ID, "", "Initial Note", "📝", "Projekte", nil, nil, false)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("CreateDocument failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
blocks := []domain.DocumentBlock{
|
|
||||||
{
|
|
||||||
ID: "blk_root_1",
|
|
||||||
Type: "text",
|
|
||||||
Content: "Architektur Übersicht #backend #go",
|
|
||||||
Level: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ID: "blk_child_1",
|
|
||||||
Type: "todo",
|
|
||||||
Content: "SQLite WAL Modus aktivieren #sqlite",
|
|
||||||
Level: 1,
|
|
||||||
Checked: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := store.FlushDocumentState(doc.ID, "Architektur Notiz", blocks); err != nil {
|
|
||||||
t.Fatalf("FlushDocumentState failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
updatedDoc, err := store.GetDocumentByID(user.ID, doc.ID)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("GetDocumentByID failed: %v", err)
|
|
||||||
}
|
|
||||||
if updatedDoc.Title != "Architektur Notiz" {
|
|
||||||
t.Fatalf("expected title 'Architektur Notiz', got '%s'", updatedDoc.Title)
|
|
||||||
}
|
|
||||||
if len(updatedDoc.Blocks) != 2 {
|
|
||||||
t.Fatalf("expected 2 blocks, got %d", len(updatedDoc.Blocks))
|
|
||||||
}
|
|
||||||
if updatedDoc.Blocks[1].Level != 1 || updatedDoc.Blocks[1].Position != 2000 {
|
|
||||||
t.Fatalf("expected block[1] level=1 position=2000, got level=%d position=%v", updatedDoc.Blocks[1].Level, updatedDoc.Blocks[1].Position)
|
|
||||||
}
|
|
||||||
if updatedDoc.MarkdownCache == "" {
|
|
||||||
t.Fatalf("expected markdown_cache to be populated")
|
|
||||||
}
|
|
||||||
|
|
||||||
tags, err := store.GetWorkspaceTags(user.ID)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("GetWorkspaceTags failed: %v", err)
|
|
||||||
}
|
|
||||||
if len(tags) != 3 {
|
|
||||||
t.Fatalf("expected 3 extracted tags in block_tags (#backend, #go, #sqlite), got %d: %+v", len(tags), tags)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
+149
-377
@@ -2,10 +2,8 @@ package ws
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"log"
|
||||||
"log/slog"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -14,8 +12,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var upgrader = websocket.Upgrader{
|
var upgrader = websocket.Upgrader{
|
||||||
ReadBufferSize: 4096,
|
ReadBufferSize: 2048,
|
||||||
WriteBufferSize: 4096,
|
WriteBufferSize: 2048,
|
||||||
CheckOrigin: func(r *http.Request) bool {
|
CheckOrigin: func(r *http.Request) bool {
|
||||||
return true // Self-hosted reverse proxy compatible
|
return true // Self-hosted reverse proxy compatible
|
||||||
},
|
},
|
||||||
@@ -27,61 +25,14 @@ type Client struct {
|
|||||||
roomID string
|
roomID string
|
||||||
userID string
|
userID string
|
||||||
send chan []byte
|
send chan []byte
|
||||||
subscribedRooms map[string]bool
|
|
||||||
sendMu sync.RWMutex
|
|
||||||
closed bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) closeSend() {
|
type docLockItem struct {
|
||||||
c.sendMu.Lock()
|
docID string
|
||||||
defer c.sendMu.Unlock()
|
|
||||||
if !c.closed {
|
|
||||||
c.closed = true
|
|
||||||
close(c.send)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) trySend(data []byte) {
|
|
||||||
c.sendMu.RLock()
|
|
||||||
defer c.sendMu.RUnlock()
|
|
||||||
if c.closed {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case c.send <- data:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type SSEClient struct {
|
|
||||||
id string
|
|
||||||
userID string
|
userID string
|
||||||
roomID string
|
userName string
|
||||||
send chan []byte
|
lockedAt time.Time
|
||||||
subscribedRooms map[string]bool
|
expiresAt time.Time
|
||||||
sendMu sync.RWMutex
|
|
||||||
closed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *SSEClient) closeSend() {
|
|
||||||
c.sendMu.Lock()
|
|
||||||
defer c.sendMu.Unlock()
|
|
||||||
if !c.closed {
|
|
||||||
c.closed = true
|
|
||||||
close(c.send)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *SSEClient) trySend(data []byte) {
|
|
||||||
c.sendMu.RLock()
|
|
||||||
defer c.sendMu.RUnlock()
|
|
||||||
if c.closed {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case c.send <- data:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Hub struct {
|
type Hub struct {
|
||||||
@@ -89,21 +40,18 @@ type Hub struct {
|
|||||||
rooms map[string]map[*Client]bool
|
rooms map[string]map[*Client]bool
|
||||||
userRooms map[string]map[*Client]bool
|
userRooms map[string]map[*Client]bool
|
||||||
allClients map[*Client]bool
|
allClients map[*Client]bool
|
||||||
sseClients map[*SSEClient]bool
|
locks map[string]*docLockItem
|
||||||
sseUserRooms map[string]map[*SSEClient]bool
|
|
||||||
sseRooms map[string]map[*SSEClient]bool
|
|
||||||
closed bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHub() *Hub {
|
func NewHub() *Hub {
|
||||||
return &Hub{
|
h := &Hub{
|
||||||
rooms: make(map[string]map[*Client]bool),
|
rooms: make(map[string]map[*Client]bool),
|
||||||
userRooms: make(map[string]map[*Client]bool),
|
userRooms: make(map[string]map[*Client]bool),
|
||||||
allClients: make(map[*Client]bool),
|
allClients: make(map[*Client]bool),
|
||||||
sseClients: make(map[*SSEClient]bool),
|
locks: make(map[string]*docLockItem),
|
||||||
sseUserRooms: make(map[string]map[*SSEClient]bool),
|
|
||||||
sseRooms: make(map[string]map[*SSEClient]bool),
|
|
||||||
}
|
}
|
||||||
|
go h.cleanupLocksLoop()
|
||||||
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) Register(c *Client) {
|
func (h *Hub) Register(c *Client) {
|
||||||
@@ -121,7 +69,7 @@ func (h *Hub) Register(c *Client) {
|
|||||||
}
|
}
|
||||||
h.userRooms[c.userID][c] = true
|
h.userRooms[c.userID][c] = true
|
||||||
}
|
}
|
||||||
onlineCount := len(h.allClients) + len(h.sseClients)
|
onlineCount := len(h.allClients)
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
if c.roomID != "" {
|
if c.roomID != "" {
|
||||||
@@ -142,164 +90,151 @@ func (h *Hub) Unregister(c *Client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
userRemaining := 0
|
||||||
if c.subscribedRooms != nil {
|
|
||||||
for rID := range c.subscribedRooms {
|
|
||||||
if room, ok := h.rooms[rID]; ok {
|
|
||||||
delete(room, c)
|
|
||||||
if len(room) == 0 {
|
|
||||||
delete(h.rooms, rID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.userID != "" && c.userID != "anonymous" {
|
if c.userID != "" && c.userID != "anonymous" {
|
||||||
if uRoom, ok := h.userRooms[c.userID]; ok {
|
if uRoom, ok := h.userRooms[c.userID]; ok {
|
||||||
delete(uRoom, c)
|
delete(uRoom, c)
|
||||||
if len(uRoom) == 0 {
|
userRemaining = len(uRoom)
|
||||||
|
if userRemaining == 0 {
|
||||||
delete(h.userRooms, c.userID)
|
delete(h.userRooms, c.userID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.closeSend()
|
close(c.send)
|
||||||
h.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Hub) RegisterSSE(c *SSEClient) {
|
// If this user has no other active client connections, release their document locks
|
||||||
h.mu.Lock()
|
var releasedDocIDs []string
|
||||||
h.sseClients[c] = true
|
if userRemaining == 0 && c.userID != "" {
|
||||||
if c.roomID != "" {
|
now := time.Now()
|
||||||
if h.sseRooms[c.roomID] == nil {
|
for docID, l := range h.locks {
|
||||||
h.sseRooms[c.roomID] = make(map[*SSEClient]bool)
|
if l.userID == c.userID || l.expiresAt.Before(now) {
|
||||||
|
releasedDocIDs = append(releasedDocIDs, docID)
|
||||||
|
delete(h.locks, docID)
|
||||||
}
|
}
|
||||||
h.sseRooms[c.roomID][c] = true
|
|
||||||
}
|
|
||||||
if c.userID != "" && c.userID != "anonymous" {
|
|
||||||
if h.sseUserRooms[c.userID] == nil {
|
|
||||||
h.sseUserRooms[c.userID] = make(map[*SSEClient]bool)
|
|
||||||
}
|
|
||||||
h.sseUserRooms[c.userID][c] = true
|
|
||||||
}
|
|
||||||
if c.subscribedRooms != nil {
|
|
||||||
for rID := range c.subscribedRooms {
|
|
||||||
if h.sseRooms[rID] == nil {
|
|
||||||
h.sseRooms[rID] = make(map[*SSEClient]bool)
|
|
||||||
}
|
|
||||||
h.sseRooms[rID][c] = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onlineCount := len(h.allClients) + len(h.sseClients)
|
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
if c.roomID != "" {
|
// Broadcast unlock events for released locks
|
||||||
h.Broadcast(c.roomID, "", "USER_PRESENCE", map[string]interface{}{
|
for _, docID := range releasedDocIDs {
|
||||||
"onlineCount": onlineCount,
|
h.BroadcastToAll("DOC_UNLOCKED", map[string]string{"docId": docID, "doc_id": docID})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) UnregisterSSE(c *SSEClient) {
|
// Document Locking Methods
|
||||||
h.mu.Lock()
|
|
||||||
delete(h.sseClients, c)
|
|
||||||
if c.roomID != "" {
|
|
||||||
if room, ok := h.sseRooms[c.roomID]; ok {
|
|
||||||
delete(room, c)
|
|
||||||
if len(room) == 0 {
|
|
||||||
delete(h.sseRooms, c.roomID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if c.subscribedRooms != nil {
|
|
||||||
for rID := range c.subscribedRooms {
|
|
||||||
if room, ok := h.sseRooms[rID]; ok {
|
|
||||||
delete(room, c)
|
|
||||||
if len(room) == 0 {
|
|
||||||
delete(h.sseRooms, rID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if c.userID != "" && c.userID != "anonymous" {
|
|
||||||
if uRoom, ok := h.sseUserRooms[c.userID]; ok {
|
|
||||||
delete(uRoom, c)
|
|
||||||
if len(uRoom) == 0 {
|
|
||||||
delete(h.sseUserRooms, c.userID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.closeSend()
|
|
||||||
h.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Hub) JoinSSERoomByID(sseID, roomID string) bool {
|
func (h *Hub) AcquireDocLock(docID, userID, userName string, ttl time.Duration) (*domain.DocLockInfo, bool, *domain.DocLockInfo) {
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
defer h.mu.Unlock()
|
defer h.mu.Unlock()
|
||||||
for client := range h.sseClients {
|
|
||||||
if client.id == sseID {
|
now := time.Now()
|
||||||
if h.sseRooms[roomID] == nil {
|
existing, exists := h.locks[docID]
|
||||||
h.sseRooms[roomID] = make(map[*SSEClient]bool)
|
if exists && existing.expiresAt.After(now) {
|
||||||
|
if existing.userID != userID {
|
||||||
|
// Locked by another user
|
||||||
|
info := &domain.DocLockInfo{
|
||||||
|
DocID: existing.docID,
|
||||||
|
UserID: existing.userID,
|
||||||
|
UserName: existing.userName,
|
||||||
|
ExpiresAt: existing.expiresAt.Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
h.sseRooms[roomID][client] = true
|
return nil, false, info
|
||||||
if client.subscribedRooms == nil {
|
|
||||||
client.subscribedRooms = make(map[string]bool)
|
|
||||||
}
|
}
|
||||||
client.subscribedRooms[roomID] = true
|
// Same user extending lock
|
||||||
|
existing.expiresAt = now.Add(ttl)
|
||||||
|
if userName != "" {
|
||||||
|
existing.userName = userName
|
||||||
|
}
|
||||||
|
info := &domain.DocLockInfo{
|
||||||
|
DocID: existing.docID,
|
||||||
|
UserID: existing.userID,
|
||||||
|
UserName: existing.userName,
|
||||||
|
ExpiresAt: existing.expiresAt.Format(time.RFC3339),
|
||||||
|
}
|
||||||
|
return info, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create fresh lock
|
||||||
|
item := &docLockItem{
|
||||||
|
docID: docID,
|
||||||
|
userID: userID,
|
||||||
|
userName: userName,
|
||||||
|
lockedAt: now,
|
||||||
|
expiresAt: now.Add(ttl),
|
||||||
|
}
|
||||||
|
h.locks[docID] = item
|
||||||
|
info := &domain.DocLockInfo{
|
||||||
|
DocID: item.docID,
|
||||||
|
UserID: item.userID,
|
||||||
|
UserName: item.userName,
|
||||||
|
ExpiresAt: item.expiresAt.Format(time.RFC3339),
|
||||||
|
}
|
||||||
|
return info, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Hub) HeartbeatDocLock(docID, userID string, ttl time.Duration) bool {
|
||||||
|
h.mu.Lock()
|
||||||
|
defer h.mu.Unlock()
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
item, ok := h.locks[docID]
|
||||||
|
if !ok || item.userID != userID || item.expiresAt.Before(now) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
item.expiresAt = now.Add(ttl)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Hub) ReleaseDocLock(docID, userID string, isAdmin bool) bool {
|
||||||
|
h.mu.Lock()
|
||||||
|
defer h.mu.Unlock()
|
||||||
|
|
||||||
|
item, ok := h.locks[docID]
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if item.userID == userID || isAdmin || userID == "admin" {
|
||||||
|
delete(h.locks, docID)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) LeaveSSERoomByID(sseID, roomID string) bool {
|
func (h *Hub) GetDocLock(docID string) *domain.DocLockInfo {
|
||||||
|
h.mu.RLock()
|
||||||
|
defer h.mu.RUnlock()
|
||||||
|
|
||||||
|
item, ok := h.locks[docID]
|
||||||
|
if !ok || item.expiresAt.Before(time.Now()) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &domain.DocLockInfo{
|
||||||
|
DocID: item.docID,
|
||||||
|
UserID: item.userID,
|
||||||
|
UserName: item.userName,
|
||||||
|
ExpiresAt: item.expiresAt.Format(time.RFC3339),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Hub) cleanupLocksLoop() {
|
||||||
|
ticker := time.NewTicker(2 * time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
for range ticker.C {
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
defer h.mu.Unlock()
|
now := time.Now()
|
||||||
for client := range h.sseClients {
|
var expiredDocIDs []string
|
||||||
if client.id == sseID {
|
for docID, l := range h.locks {
|
||||||
if room, ok := h.sseRooms[roomID]; ok {
|
if l.expiresAt.Before(now) {
|
||||||
delete(room, client)
|
expiredDocIDs = append(expiredDocIDs, docID)
|
||||||
if len(room) == 0 {
|
delete(h.locks, docID)
|
||||||
delete(h.sseRooms, roomID)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if client.subscribedRooms != nil {
|
|
||||||
delete(client.subscribedRooms, roomID)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Close gracefully disconnects all WebSocket and SSE connections so HTTP shutdown completes immediately.
|
|
||||||
func (h *Hub) Close() {
|
|
||||||
h.mu.Lock()
|
|
||||||
if h.closed {
|
|
||||||
h.mu.Unlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
h.closed = true
|
|
||||||
|
|
||||||
allWsClients := make([]*Client, 0, len(h.allClients))
|
|
||||||
for c := range h.allClients {
|
|
||||||
allWsClients = append(allWsClients, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
allSSEClients := make([]*SSEClient, 0, len(h.sseClients))
|
|
||||||
for c := range h.sseClients {
|
|
||||||
allSSEClients = append(allSSEClients, c)
|
|
||||||
}
|
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
|
|
||||||
for _, c := range allWsClients {
|
for _, docID := range expiredDocIDs {
|
||||||
_ = c.conn.Close()
|
h.BroadcastToAll("DOC_UNLOCKED", map[string]string{"docId": docID, "doc_id": docID})
|
||||||
c.closeSend()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range allSSEClients {
|
|
||||||
c.closeSend()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,17 +252,13 @@ func (h *Hub) BroadcastToAll(event string, payload interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mu.RLock()
|
h.mu.RLock()
|
||||||
if h.closed {
|
|
||||||
h.mu.RUnlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer h.mu.RUnlock()
|
defer h.mu.RUnlock()
|
||||||
|
|
||||||
for client := range h.allClients {
|
for client := range h.allClients {
|
||||||
client.trySend(data)
|
select {
|
||||||
|
case client.send <- data:
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
for sseClient := range h.sseClients {
|
|
||||||
sseClient.trySend(data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,21 +274,15 @@ func (h *Hub) BroadcastToUser(userID, event string, payload interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mu.RLock()
|
h.mu.RLock()
|
||||||
if h.closed {
|
|
||||||
h.mu.RUnlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer h.mu.RUnlock()
|
defer h.mu.RUnlock()
|
||||||
|
|
||||||
if room, ok := h.userRooms[userID]; ok {
|
if room, ok := h.userRooms[userID]; ok {
|
||||||
for client := range room {
|
for client := range room {
|
||||||
client.trySend(data)
|
select {
|
||||||
|
case client.send <- data:
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sseRoom, ok := h.sseUserRooms[userID]; ok {
|
|
||||||
for sseClient := range sseRoom {
|
|
||||||
sseClient.trySend(data)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,12 +291,8 @@ func (h *Hub) BroadcastTaskEvent(userID, event string, payload interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) BroadcastDocEvent(docID, event string, payload interface{}) {
|
func (h *Hub) BroadcastDocEvent(docID, event string, payload interface{}) {
|
||||||
if docID != "" {
|
|
||||||
h.BroadcastRoom("doc:"+docID, event, payload, nil)
|
|
||||||
} else {
|
|
||||||
h.BroadcastToAll(event, payload)
|
h.BroadcastToAll(event, payload)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Hub) Broadcast(spaceID, listID, event string, payload interface{}) {
|
func (h *Hub) Broadcast(spaceID, listID, event string, payload interface{}) {
|
||||||
msg := domain.WSMessage{
|
msg := domain.WSMessage{
|
||||||
@@ -386,10 +307,6 @@ func (h *Hub) Broadcast(spaceID, listID, event string, payload interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.mu.RLock()
|
h.mu.RLock()
|
||||||
if h.closed {
|
|
||||||
h.mu.RUnlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer h.mu.RUnlock()
|
defer h.mu.RUnlock()
|
||||||
|
|
||||||
targetRoom := listID
|
targetRoom := listID
|
||||||
@@ -399,13 +316,12 @@ func (h *Hub) Broadcast(spaceID, listID, event string, payload interface{}) {
|
|||||||
|
|
||||||
if room, ok := h.rooms[targetRoom]; ok {
|
if room, ok := h.rooms[targetRoom]; ok {
|
||||||
for client := range room {
|
for client := range room {
|
||||||
client.trySend(data)
|
select {
|
||||||
|
case client.send <- data:
|
||||||
|
default:
|
||||||
|
// Slow client buffer full
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sseRoom, ok := h.sseRooms[targetRoom]; ok {
|
|
||||||
for sseClient := range sseRoom {
|
|
||||||
sseClient.trySend(data)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,82 +329,10 @@ func (h *Hub) BroadcastListEvent(listID, event string, payload interface{}) {
|
|||||||
h.Broadcast("", listID, event, payload)
|
h.Broadcast("", listID, event, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) JoinRoom(c *Client, roomID string) {
|
|
||||||
h.mu.Lock()
|
|
||||||
defer h.mu.Unlock()
|
|
||||||
if h.rooms[roomID] == nil {
|
|
||||||
h.rooms[roomID] = make(map[*Client]bool)
|
|
||||||
}
|
|
||||||
h.rooms[roomID][c] = true
|
|
||||||
if c.subscribedRooms == nil {
|
|
||||||
c.subscribedRooms = make(map[string]bool)
|
|
||||||
}
|
|
||||||
c.subscribedRooms[roomID] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Hub) LeaveRoom(c *Client, roomID string) {
|
|
||||||
h.mu.Lock()
|
|
||||||
defer h.mu.Unlock()
|
|
||||||
if room, ok := h.rooms[roomID]; ok {
|
|
||||||
delete(room, c)
|
|
||||||
if len(room) == 0 {
|
|
||||||
delete(h.rooms, roomID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if c.subscribedRooms != nil {
|
|
||||||
delete(c.subscribedRooms, roomID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Hub) BroadcastRoom(roomID, event string, payload interface{}, excludeClient *Client) {
|
|
||||||
msg := domain.WSMessage{
|
|
||||||
Event: event,
|
|
||||||
Payload: payload,
|
|
||||||
Timestamp: domain.NowISO(),
|
|
||||||
}
|
|
||||||
data, err := json.Marshal(msg)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
h.mu.RLock()
|
|
||||||
if h.closed {
|
|
||||||
h.mu.RUnlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer h.mu.RUnlock()
|
|
||||||
|
|
||||||
if room, ok := h.rooms[roomID]; ok {
|
|
||||||
for client := range room {
|
|
||||||
if excludeClient != nil && client == excludeClient {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
client.trySend(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if sseRoom, ok := h.sseRooms[roomID]; ok {
|
|
||||||
for sseClient := range sseRoom {
|
|
||||||
sseClient.trySend(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) SendEvent(event string, payload interface{}) {
|
|
||||||
msg := domain.WSMessage{
|
|
||||||
Event: event,
|
|
||||||
Payload: payload,
|
|
||||||
Timestamp: domain.NowISO(),
|
|
||||||
}
|
|
||||||
data, err := json.Marshal(msg)
|
|
||||||
if err == nil {
|
|
||||||
c.trySend(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Hub) ServeWS(w http.ResponseWriter, r *http.Request, roomID, userID string) {
|
func (h *Hub) ServeWS(w http.ResponseWriter, r *http.Request, roomID, userID string) {
|
||||||
conn, err := upgrader.Upgrade(w, r, nil)
|
conn, err := upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("WebSocket upgrade error", "room_id", roomID, "user_id", userID, "error", err)
|
log.Printf("[ws] upgrade error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,80 +349,13 @@ func (h *Hub) ServeWS(w http.ResponseWriter, r *http.Request, roomID, userID str
|
|||||||
go client.readPump()
|
go client.readPump()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) ServeSSE(w http.ResponseWriter, r *http.Request, roomID, userID string, initialRooms []string) {
|
|
||||||
flusher, ok := w.(http.Flusher)
|
|
||||||
if !ok {
|
|
||||||
http.Error(w, "Streaming unsupported!", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/event-stream")
|
|
||||||
w.Header().Set("Cache-Control", "no-cache, no-transform")
|
|
||||||
w.Header().Set("Connection", "keep-alive")
|
|
||||||
w.Header().Set("X-Accel-Buffering", "no")
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
|
|
||||||
client := &SSEClient{
|
|
||||||
id: domain.NewID("sse"),
|
|
||||||
userID: userID,
|
|
||||||
roomID: roomID,
|
|
||||||
send: make(chan []byte, 128),
|
|
||||||
subscribedRooms: make(map[string]bool),
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, room := range initialRooms {
|
|
||||||
if strings.TrimSpace(room) != "" {
|
|
||||||
client.subscribedRooms[strings.TrimSpace(room)] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
h.RegisterSSE(client)
|
|
||||||
defer h.UnregisterSSE(client)
|
|
||||||
|
|
||||||
// Send initial connected comment and event
|
|
||||||
fmt.Fprintf(w, ": connected (transport: sse, id: %s)\n\n", client.id)
|
|
||||||
connectedMsg, _ := json.Marshal(domain.WSMessage{
|
|
||||||
Event: "SSE_CONNECTED",
|
|
||||||
Payload: map[string]interface{}{
|
|
||||||
"sseId": client.id,
|
|
||||||
"transport": "sse",
|
|
||||||
"userId": userID,
|
|
||||||
},
|
|
||||||
Timestamp: domain.NowISO(),
|
|
||||||
})
|
|
||||||
fmt.Fprintf(w, "data: %s\n\n", connectedMsg)
|
|
||||||
flusher.Flush()
|
|
||||||
|
|
||||||
ticker := time.NewTicker(15 * time.Second)
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
notify := r.Context().Done()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-notify:
|
|
||||||
return
|
|
||||||
case msg, ok := <-client.send:
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Fprintf(w, "data: %s\n\n", msg)
|
|
||||||
flusher.Flush()
|
|
||||||
case <-ticker.C:
|
|
||||||
// Periodic ping comment to keep HTTP connection alive and prevent proxy timeouts
|
|
||||||
fmt.Fprintf(w, ": ping\n\n")
|
|
||||||
flusher.Flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) readPump() {
|
func (c *Client) readPump() {
|
||||||
defer func() {
|
defer func() {
|
||||||
c.hub.Unregister(c)
|
c.hub.Unregister(c)
|
||||||
_ = c.conn.Close()
|
_ = c.conn.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
c.conn.SetReadLimit(4 * 1024 * 1024) // 4MB for large document CRDT updates
|
c.conn.SetReadLimit(16384)
|
||||||
_ = c.conn.SetReadDeadline(time.Now().Add(60 * time.Second))
|
_ = c.conn.SetReadDeadline(time.Now().Add(60 * time.Second))
|
||||||
c.conn.SetPongHandler(func(string) error {
|
c.conn.SetPongHandler(func(string) error {
|
||||||
_ = c.conn.SetReadDeadline(time.Now().Add(60 * time.Second))
|
_ = c.conn.SetReadDeadline(time.Now().Add(60 * time.Second))
|
||||||
@@ -591,11 +368,10 @@ func (c *Client) readPump() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle client-initiated lock, CRDT, room subscription, and presence messages
|
// Handle client-initiated lock and unlock messages
|
||||||
var incoming struct {
|
var incoming struct {
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
DocID string `json:"docId"`
|
DocID string `json:"docId"`
|
||||||
Room string `json:"room"`
|
|
||||||
Payload json.RawMessage `json:"payload"`
|
Payload json.RawMessage `json:"payload"`
|
||||||
}
|
}
|
||||||
if json.Unmarshal(message, &incoming) == nil && c.userID != "" && c.userID != "anonymous" {
|
if json.Unmarshal(message, &incoming) == nil && c.userID != "" && c.userID != "anonymous" {
|
||||||
@@ -608,22 +384,18 @@ func (c *Client) readPump() {
|
|||||||
docID = p.DocID
|
docID = p.DocID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Room subscription without requiring docID
|
if docID != "" {
|
||||||
if incoming.Event == "JOIN_ROOM" {
|
switch incoming.Event {
|
||||||
room := incoming.Room
|
case "LOCK_DOC":
|
||||||
if room == "" {
|
if info, ok, _ := c.hub.AcquireDocLock(docID, c.userID, "", 30*time.Second); ok && info != nil {
|
||||||
room = docID
|
c.hub.BroadcastDocEvent(docID, "DOC_LOCKED", info)
|
||||||
}
|
}
|
||||||
if room != "" {
|
case "HEARTBEAT_DOC":
|
||||||
c.hub.JoinRoom(c, room)
|
c.hub.HeartbeatDocLock(docID, c.userID, 30*time.Second)
|
||||||
|
case "UNLOCK_DOC":
|
||||||
|
if c.hub.ReleaseDocLock(docID, c.userID, false) {
|
||||||
|
c.hub.BroadcastDocEvent(docID, "DOC_UNLOCKED", map[string]string{"docId": docID, "doc_id": docID})
|
||||||
}
|
}
|
||||||
} else if incoming.Event == "LEAVE_ROOM" {
|
|
||||||
room := incoming.Room
|
|
||||||
if room == "" {
|
|
||||||
room = docID
|
|
||||||
}
|
|
||||||
if room != "" {
|
|
||||||
c.hub.LeaveRoom(c, room)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
package ws
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHubCloseAndGracefulShutdown(t *testing.T) {
|
|
||||||
hub := NewHub()
|
|
||||||
|
|
||||||
// Register multiple dummy SSE clients
|
|
||||||
var sseClients []*SSEClient
|
|
||||||
for i := 0; i < 5; i++ {
|
|
||||||
client := &SSEClient{
|
|
||||||
id: "sse-test",
|
|
||||||
userID: "user-1",
|
|
||||||
send: make(chan []byte, 10),
|
|
||||||
}
|
|
||||||
hub.RegisterSSE(client)
|
|
||||||
sseClients = append(sseClients, client)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify broadcast works
|
|
||||||
hub.BroadcastToAll("TEST_EVENT", map[string]string{"msg": "hello"})
|
|
||||||
|
|
||||||
// Concurrently invoke Close() and Broadcast() to verify no panics or deadlocks
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
wg.Add(2)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
for i := 0; i < 50; i++ {
|
|
||||||
hub.BroadcastToAll("SPAM", map[string]int{"i": i})
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
time.Sleep(5 * time.Millisecond)
|
|
||||||
hub.Close()
|
|
||||||
}()
|
|
||||||
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// Verify that all SSE client channels are closed
|
|
||||||
for _, c := range sseClients {
|
|
||||||
select {
|
|
||||||
case _, ok := <-c.send:
|
|
||||||
if ok {
|
|
||||||
// Drained a message, check next
|
|
||||||
_, ok = <-c.send
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user