feat: add ZIP import functionality
- Backend: POST /api/import/zip endpoint with validation and rollback - CSV import with ON CONFLICT DO NOTHING for duplicate detection - Photo import with existence check - AI insights import - Frontend: file upload UI in SettingsPage - Import summary showing count per category - Full transaction rollback on error Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
e10e9d7eb9
commit
115d975335
3 files changed
+507
-1
No files matched your search
@@ -502,3 +502,148 @@ count = cur.fetchone()['count'] # Dict key
|
||||
- Prompt-Bearbeitung: PUT-Endpoint für Admins
|
||||
|
||||
**Tool:** Vollständiger Audit via Explore-Agent empfohlen bei größeren Änderungen
|
||||
|
||||
## Export/Import Spezifikation (v9c)
|
||||
|
||||
### ZIP-Export Struktur
|
||||
```
|
||||
mitai-export-{name}-{YYYY-MM-DD}.zip
|
||||
├── README.txt ← Erklärung des Formats + Versionsnummer
|
||||
├── profile.json ← Profildaten (ohne Passwort-Hash)
|
||||
├── data/
|
||||
│ ├── weight.csv ← Gewichtsverlauf
|
||||
│ ├── circumferences.csv ← Umfänge (8 Messpunkte)
|
||||
│ ├── caliper.csv ← Caliper-Messungen
|
||||
│ ├── nutrition.csv ← Ernährungsdaten
|
||||
│ └── activity.csv ← Aktivitäten
|
||||
├── insights/
|
||||
│ └── ai_insights.json ← KI-Auswertungen (alle gespeicherten)
|
||||
└── photos/
|
||||
├── {date}_{id}.jpg ← Progress-Fotos
|
||||
└── ...
|
||||
```
|
||||
|
||||
### CSV Format (alle Dateien)
|
||||
```
|
||||
- Trennzeichen: Semikolon (;) – Excel/LibreOffice kompatibel
|
||||
- Encoding: UTF-8 mit BOM (für Windows Excel)
|
||||
- Datumsformat: YYYY-MM-DD
|
||||
- Dezimaltrennzeichen: Punkt (.)
|
||||
- Erste Zeile: Header
|
||||
- Nullwerte: leer (nicht "null" oder "NULL")
|
||||
```
|
||||
|
||||
### weight.csv Spalten
|
||||
```
|
||||
id;date;weight;note;source;created
|
||||
```
|
||||
|
||||
### circumferences.csv Spalten
|
||||
```
|
||||
id;date;waist;hip;chest;neck;upper_arm;thigh;calf;forearm;note;created
|
||||
```
|
||||
|
||||
### caliper.csv Spalten
|
||||
```
|
||||
id;date;chest;abdomen;thigh;tricep;subscapular;suprailiac;midaxillary;method;bf_percent;note;created
|
||||
```
|
||||
|
||||
### nutrition.csv Spalten
|
||||
```
|
||||
id;date;meal_name;kcal;protein;fat;carbs;fiber;note;source;created
|
||||
```
|
||||
|
||||
### activity.csv Spalten
|
||||
```
|
||||
id;date;name;type;duration_min;kcal;heart_rate_avg;heart_rate_max;distance_km;note;source;created
|
||||
```
|
||||
|
||||
### profile.json Struktur
|
||||
```json
|
||||
{
|
||||
"export_version": "2",
|
||||
"export_date": "2026-03-18",
|
||||
"app": "Mitai Jinkendo",
|
||||
"profile": {
|
||||
"name": "Lars",
|
||||
"email": "lars@stommer.com",
|
||||
"sex": "m",
|
||||
"height": 178,
|
||||
"birth_year": 1980,
|
||||
"goal_weight": 82,
|
||||
"goal_bf_pct": 14,
|
||||
"avatar_color": "#1D9E75",
|
||||
"auth_type": "password",
|
||||
"session_days": 30,
|
||||
"ai_enabled": true,
|
||||
"tier": "selfhosted"
|
||||
},
|
||||
"stats": {
|
||||
"weight_entries": 150,
|
||||
"nutrition_entries": 300,
|
||||
"activity_entries": 45,
|
||||
"photos": 12
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ai_insights.json Struktur
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": "uuid",
|
||||
"scope": "gesamt",
|
||||
"created": "2026-03-18T10:00:00",
|
||||
"result": "KI-Analyse Text..."
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### README.txt Inhalt
|
||||
```
|
||||
Mitai Jinkendo – Datenexport
|
||||
Version: 2
|
||||
Exportiert am: YYYY-MM-DD
|
||||
Profil: {name}
|
||||
|
||||
Inhalt:
|
||||
- profile.json: Profildaten und Einstellungen
|
||||
- data/*.csv: Messdaten (Semikolon-getrennt, UTF-8)
|
||||
- insights/: KI-Auswertungen (JSON)
|
||||
- photos/: Progress-Fotos (JPEG)
|
||||
|
||||
Import:
|
||||
Dieser Export kann in Mitai Jinkendo unter
|
||||
Einstellungen → Import → "Mitai Backup importieren"
|
||||
wieder eingespielt werden.
|
||||
|
||||
Format-Version 2 (ab v9b):
|
||||
Alle CSV-Dateien sind UTF-8 mit BOM kodiert.
|
||||
Trennzeichen: Semikolon (;)
|
||||
Datumsformat: YYYY-MM-DD
|
||||
```
|
||||
|
||||
### Import-Funktion (zu implementieren)
|
||||
**Endpoint:** `POST /api/import/zip`
|
||||
**Verhalten:**
|
||||
- Akzeptiert ZIP-Datei (multipart/form-data)
|
||||
- Erkennt export_version aus profile.json
|
||||
- Importiert nur fehlende Einträge (kein Duplikat)
|
||||
- Fotos werden nicht überschrieben falls bereits vorhanden
|
||||
- Gibt Zusammenfassung zurück: wie viele Einträge je Kategorie importiert
|
||||
- Bei Fehler: vollständiger Rollback (alle oder nichts)
|
||||
|
||||
**Duplikat-Erkennung:**
|
||||
```python
|
||||
# INSERT ... ON CONFLICT (profile_id, date) DO NOTHING
|
||||
# weight: UNIQUE (profile_id, date)
|
||||
# nutrition: UNIQUE (profile_id, date, meal_name)
|
||||
# activity: UNIQUE (profile_id, date, name)
|
||||
# caliper: UNIQUE (profile_id, date)
|
||||
# circumferences: UNIQUE (profile_id, date)
|
||||
```
|
||||
|
||||
**Frontend:** Neuer Button in SettingsPage:
|
||||
```
|
||||
[ZIP exportieren] [JSON exportieren] [Backup importieren]
|
||||
```
|
||||
Reference in new issue
Block a user