feat: Cloud-Sync über Dropbox und Google Drive
- FTP-Sync durch Cloud-Backends ersetzt (Dropbox, Google Drive) - OAuth-Flow mit nutzereigenen Tokens und App-Key-Konfiguration - Zeit-Tooltips für Timeline-Labels und Abschnittsbanner beim Playback - Tests, Build-Konfiguration und Doku aktualisiert
This commit is contained in:
parent
533a12ef1a
commit
74d9d6b61f
36 changed files with 3040 additions and 817 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -35,3 +35,6 @@ docs/.credentials*
|
||||||
# Editor-Swap-Dateien
|
# Editor-Swap-Dateien
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
|
||||||
|
# OAuth-App-Zugaenge (werden per tools/sync_apps_config.sh erzeugt)
|
||||||
|
rinkplanner/sync_apps.cfg
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,5 @@ Planner for Figure Skating free skate
|
||||||
- **3D-Assets:** [`docs/assets.md`](docs/assets.md)
|
- **3D-Assets:** [`docs/assets.md`](docs/assets.md)
|
||||||
- **Rotoscoping:** [`docs/rotoscoping.md`](docs/rotoscoping.md)
|
- **Rotoscoping:** [`docs/rotoscoping.md`](docs/rotoscoping.md)
|
||||||
- **Builds:** [`docs/builds.md`](docs/builds.md)
|
- **Builds:** [`docs/builds.md`](docs/builds.md)
|
||||||
|
- **Kür-Sync (Google Drive/Dropbox):** [`docs/sync.md`](docs/sync.md)
|
||||||
|
- **Cloud-Sync einrichten:** [`docs/cloud-setup.md`](docs/cloud-setup.md)
|
||||||
|
|
|
||||||
|
|
@ -339,14 +339,17 @@ Fahrtrichtung.
|
||||||
sichtbar sind. Punktmarker halten die Ankunftsrichtung, Pirouetten drehen
|
sichtbar sind. Punktmarker halten die Ankunftsrichtung, Pirouetten drehen
|
||||||
den Marker während der Standzeit mit 1,5 Umdrehungen pro Sekunde. Während
|
den Marker während der Standzeit mit 1,5 Umdrehungen pro Sekunde. Während
|
||||||
des Playbacks wird die aktuelle Section hervorgehoben,
|
des Playbacks wird die aktuelle Section hervorgehoben,
|
||||||
ohne die Bearbeitungs-Section zu wechseln. Steuerung: Play/Pause, Reset,
|
ohne die Bearbeitungs-Section zu wechseln. Ein **▶** markiert sie in der
|
||||||
|
Abschnittsliste; ihr Name erscheint kurz oben auf der Eisfläche und blendet
|
||||||
|
sich innerhalb von zwei Sekunden aus. Steuerung: Play/Pause, Reset,
|
||||||
Timeline-Scrubbing und Geschwindigkeit 0,25×–2,0×. Ein optionales
|
Timeline-Scrubbing und Geschwindigkeit 0,25×–2,0×. Ein optionales
|
||||||
Musikstück (MP3/OGG/WAV) liegt neben der Kür-JSON in `user://routines/`
|
Musikstück (MP3/OGG/WAV) liegt neben der Kür-JSON in `user://routines/`
|
||||||
und läuft über einen `AudioStreamPlayer` auf derselben Zeitbasis: Start,
|
und läuft über einen `AudioStreamPlayer` auf derselben Zeitbasis: Start,
|
||||||
Pause, Reset, Scrubbing und Geschwindigkeit wirken auf Bild und Ton. Über
|
Pause, Reset, Scrubbing und Geschwindigkeit wirken auf Bild und Ton. Über
|
||||||
der Timeline liegt eine Label-Spur: Labels von Segmenten und Kürzel von
|
der Timeline liegt eine Label-Spur: Labels von Segmenten und Kürzel von
|
||||||
Elementen ohne Freitext erscheinen schräg an ihrem Startzeitpunkt (auch
|
Elementen ohne Freitext erscheinen schräg an ihrem Startzeitpunkt (auch
|
||||||
Elemente mit 0 s Standzeit); ein Klick in die Spur legt ein eigenes,
|
Elemente mit 0 s Standzeit); beim Überfahren zeigt ein Tooltip den
|
||||||
|
Zeitpunkt im Track. Ein Klick in die Spur legt ein eigenes,
|
||||||
frei beschriftetes Timeline-Label an, das per Klick wieder bearbeitet oder
|
frei beschriftetes Timeline-Label an, das per Klick wieder bearbeitet oder
|
||||||
gelöscht werden kann. Ein Wechsel des aktiven Abschnitts setzt Marker,
|
gelöscht werden kann. Ein Wechsel des aktiven Abschnitts setzt Marker,
|
||||||
Timeline-Slider und Label-Spur an den Anfang dieses Abschnitts; eine
|
Timeline-Slider und Label-Spur an den Anfang dieses Abschnitts; eine
|
||||||
|
|
@ -483,14 +486,17 @@ ggf. eines nach `touchend` (300-ms-Guard).
|
||||||
- **Lokale Daten:** `user://` liegt pro Plattform getrennt (Linux
|
- **Lokale Daten:** `user://` liegt pro Plattform getrennt (Linux
|
||||||
`~/.local/share/godot/app_userdata/Rinkplanner/`, Android im
|
`~/.local/share/godot/app_userdata/Rinkplanner/`, Android im
|
||||||
app-internen Speicher).
|
app-internen Speicher).
|
||||||
- **Kontosync:** manueller FTP-/FTPS-Abgleich der `.json`- und
|
- **Kontosync:** manueller Cloud-Abgleich der `.json`- und
|
||||||
Legacy-`.tres`-Dateien über `FtpClient`, `SyncPlan` und `RoutineSync`;
|
Legacy-`.tres`-Dateien über `RemoteStore`, `DropboxStore`,
|
||||||
Details in `docs/sync.md`. Zugangsdaten liegen in `user://sync.cfg`, der
|
`GoogleDriveStore`, `SyncPlan` und `RoutineSync`; Details in
|
||||||
letzte gemeinsame Stand in `user://sync_state.cfg`. Beim ersten Abgleich
|
`docs/sync.md`, Einrichtung der OAuth-Apps in `docs/cloud-setup.md`.
|
||||||
einer beidseitig vorhandenen Datei übernimmt die Serverfassung den Namen,
|
Jeder Nutzer verbindet sein eigenes Google-Drive- oder Dropbox-Konto;
|
||||||
die lokale bleibt als `(Lokal …)`-Kopie; bei einem echten Konflikt bleibt
|
Refresh-Tokens liegen in `user://sync.cfg`, der letzte gemeinsame Stand in
|
||||||
die lokale Fassung Hauptdatei und die Serverfassung kommt als
|
`user://sync_state.cfg`. Beim ersten Abgleich einer beidseitig vorhandenen
|
||||||
`(Server …)`-Kopie dazu. Konfliktnamen behalten die jeweilige Endung.
|
Datei übernimmt die Cloud-Fassung den Namen, die lokale bleibt als
|
||||||
|
`(Lokal …)`-Kopie; bei einem echten Konflikt bleibt die lokale Fassung
|
||||||
|
Hauptdatei und die Cloud-Fassung kommt als `(Server …)`-Kopie dazu.
|
||||||
|
Konfliktnamen behalten die jeweilige Endung.
|
||||||
|
|
||||||
## 7. Tests
|
## 7. Tests
|
||||||
|
|
||||||
|
|
@ -542,10 +548,10 @@ Aktueller Stand:
|
||||||
- **History:** 53 Assertions für Undo/Redo von Segmenten, Kanten, Labels, Sections,
|
- **History:** 53 Assertions für Undo/Redo von Segmenten, Kanten, Labels, Sections,
|
||||||
Zeichengesten und Griff-Bearbeitung, Toolbar-Buttons, Erhalt der Ansicht
|
Zeichengesten und Griff-Bearbeitung, Toolbar-Buttons, Erhalt der Ansicht
|
||||||
sowie das Zurücksetzen der Historie.
|
sowie das Zurücksetzen der Historie.
|
||||||
- **Playback:** 45 Assertions für Dauer/Timeline, Vorwärts-/Rückwärts-
|
- **Playback:** 99 Assertions für Dauer/Timeline, Vorwärts-/Rückwärts-
|
||||||
Blickrichtung, Section-Hervorhebung, Play/Pause/Reset inklusive
|
Blickrichtung, Section-Hervorhebung und -Banner, Play/Pause/Reset inklusive
|
||||||
Button-Verdrahtung, Scrubbing, Geschwindigkeitswechsel, Standzeiten von
|
Button-Verdrahtung, Scrubbing, Geschwindigkeitswechsel, Standzeiten von
|
||||||
Elementen und die Rotation des Markers in einer Pirouette.
|
Elementen, Markerrotation in einer Pirouette sowie Timeline-Tooltips.
|
||||||
- **Timing:** 41 Assertions für Dauer-/Tempo-Kopplung, Level-Presets,
|
- **Timing:** 41 Assertions für Dauer-/Tempo-Kopplung, Level-Presets,
|
||||||
Kalibrierung, Undo, Persistenz und Schema-1-Migration.
|
Kalibrierung, Undo, Persistenz und Schema-1-Migration.
|
||||||
- **Export:** 31 Assertions für SVG-Struktur, Titel-Escaping, Segment-Labels,
|
- **Export:** 31 Assertions für SVG-Struktur, Titel-Escaping, Segment-Labels,
|
||||||
|
|
@ -558,11 +564,11 @@ Aktueller Stand:
|
||||||
Leistenlayout bei 1024 und 1400 px.
|
Leistenlayout bei 1024 und 1400 px.
|
||||||
- **Performance:** Stresstest mit 480 Segmenten in 12 Sections; die mittlere
|
- **Performance:** Stresstest mit 480 Segmenten in 12 Sections; die mittlere
|
||||||
Redraw-Zeit muss unter 120 ms bleiben (aktuell ca. 7–10 ms).
|
Redraw-Zeit muss unter 120 ms bleiben (aktuell ca. 7–10 ms).
|
||||||
- **Sync:** 34 Assertions für Vergleichsregeln, Konfliktnamen (JSON und
|
- **Sync:** 59 Assertions für Vergleichsregeln, Konfliktnamen (JSON und
|
||||||
Legacy-`.tres`), Zeitstempel, PASV/EPSV/MDTM-Parsing, Sync-Stand und die
|
Legacy-`.tres`), Zeitstempel, URL/PKCE-Helfer, Cloud-Pfade, App-Konfiguration,
|
||||||
Einstellungs-Verdrahtung.
|
Sync-Stand und die Einstellungs-Verdrahtung. Die echten Cloud-APIs werden
|
||||||
Der FTP-Client wurde zusätzlich gegen den echten Zielserver geprüft
|
nicht in den automatischen Tests angesprochen (OAuth erfordert ein
|
||||||
(Upload, Download, Übernahme, Konflikt, Aufräumen).
|
Testkonto); der Ablauf ist in `docs/cloud-setup.md` beschrieben.
|
||||||
- **3D-Assets:** 57 Assertions für Manifest-Schema, Pfade, FTP-Pfade,
|
- **3D-Assets:** 57 Assertions für Manifest-Schema, Pfade, FTP-Pfade,
|
||||||
Platzierung, Rig-Metadaten, Animationen, Hashes und – falls synchronisiert
|
Platzierung, Rig-Metadaten, Animationen, Hashes und – falls synchronisiert
|
||||||
– Größe, SHA-256 sowie die 8-Bone-Gewichte der GLB-Datei.
|
– Größe, SHA-256 sowie die 8-Bone-Gewichte der GLB-Datei.
|
||||||
|
|
@ -615,8 +621,7 @@ Viewport-Screenshot; sie ersetzen die headless Tests nicht.
|
||||||
sich im Praxisbetrieb.
|
sich im Praxisbetrieb.
|
||||||
9. **Dateinamen:** Die Normalisierung ersetzt Leerzeichen und entfernt
|
9. **Dateinamen:** Die Normalisierung ersetzt Leerzeichen und entfernt
|
||||||
Pfadzeichen, transliteriert aber keine Umlaute. Für Windows und den
|
Pfadzeichen, transliteriert aber keine Umlaute. Für Windows und den
|
||||||
geplanten FTP-Sync ist zu prüfen, ob eine ASCII-Normalisierung robuster
|
Cloud-Sync ist zu prüfen, ob eine ASCII-Normalisierung robuster ist.
|
||||||
ist.
|
|
||||||
10. **Snapshot-Clone:** `_clone_routine()` kopiert die Modellfelder manuell.
|
10. **Snapshot-Clone:** `_clone_routine()` kopiert die Modellfelder manuell.
|
||||||
Neue Felder am Modell müssen dort ergänzt werden, sonst fehlen sie in
|
Neue Felder am Modell müssen dort ergänzt werden, sonst fehlen sie in
|
||||||
Undo/Redo-Snapshots.
|
Undo/Redo-Snapshots.
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,11 @@ Texturen in den Exporten liegt (`docs/assets.md`), sind die Builds etwa
|
||||||
Export den Platzhalter.
|
Export den Platzhalter.
|
||||||
- Export-Templates derselben Version unter
|
- Export-Templates derselben Version unter
|
||||||
`~/.local/share/godot/export_templates/4.7.2.stable/`
|
`~/.local/share/godot/export_templates/4.7.2.stable/`
|
||||||
|
- Für den Cloud-Sync: `rinkplanner/sync_apps.cfg` mit den OAuth-App-Zugängen.
|
||||||
|
Die Datei wird aus `docs/credentials.txt` erzeugt:
|
||||||
|
`./tools/sync_apps_config.sh`; Einrichtung in `docs/cloud-setup.md`.
|
||||||
|
Ohne die Datei baut die App, zeigt beim Verbinden aber einen
|
||||||
|
Konfigurationshinweis.
|
||||||
- Für Android zusätzlich JDK 17 + Android SDK (siehe unten)
|
- Für Android zusätzlich JDK 17 + Android SDK (siehe unten)
|
||||||
|
|
||||||
## Desktop bauen
|
## Desktop bauen
|
||||||
|
|
@ -200,7 +205,9 @@ auf `tools/sync_assets.sh --sync` ab. Für einen reinen Starttest ohne
|
||||||
|
|
||||||
## Kontosync
|
## Kontosync
|
||||||
|
|
||||||
Der manuelle Sync über FTP lädt die neuesten `.json`-Dateien
|
Der manuelle Sync über Google Drive oder Dropbox lädt die neuesten
|
||||||
(Legacy-`.tres` weiterhin) je Kür hoch bzw. herunter, Konflikte bleiben als
|
`.json`-Dateien (Legacy-`.tres` weiterhin) je Kür hoch bzw. herunter,
|
||||||
Kopien mit Zeitstempel erhalten. Zugangsdaten liegen in den
|
Konflikte bleiben als Kopien mit Zeitstempel erhalten. Jedes Gerät verbindet
|
||||||
App-Einstellungen (`user://`), nicht im Repository.
|
das eigene Cloud-Konto; Refresh-Tokens liegen in den App-Einstellungen
|
||||||
|
(`user://`), nicht im Repository. Details in `docs/sync.md` und
|
||||||
|
`docs/cloud-setup.md`.
|
||||||
|
|
|
||||||
238
docs/cloud-setup.md
Normal file
238
docs/cloud-setup.md
Normal file
|
|
@ -0,0 +1,238 @@
|
||||||
|
# Cloud-Sync einrichten (Google Drive / Dropbox)
|
||||||
|
|
||||||
|
Rinkplanner speichert Kürdateien und Musik im **eigenen Cloud-Konto jedes
|
||||||
|
Nutzers**. Dafür registriert der Entwickler einmalig eine OAuth-App pro
|
||||||
|
Anbieter. Nutzer melden sich in ihrem Browser mit ihrem eigenen Konto an; die
|
||||||
|
App sieht niemals deren Passwort.
|
||||||
|
|
||||||
|
## Warum keine E-Mail-/Passwort-Anmeldung?
|
||||||
|
|
||||||
|
Google Drive und Dropbox haben die Anmeldung mit Benutzername und Passwort
|
||||||
|
über ihre APIs abgeschaltet. Ein `GOOGLE_PASSWORD` oder `DROPBOX_PASSWORD` in
|
||||||
|
`docs/credentials.txt` kann deshalb nicht verwendet werden. Nötig sind:
|
||||||
|
|
||||||
|
- eine **App-Registrierung** (Client-ID/App-Key) für Rinkplanner,
|
||||||
|
- pro Nutzer ein **Refresh-Token** aus dem OAuth-Flow.
|
||||||
|
|
||||||
|
Die App-Registrierung ist öffentlich (vergleichbar mit einem Paketnamen). Der
|
||||||
|
Refresh-Token ist das eigentliche Geheimnis und bleibt auf dem Gerät des
|
||||||
|
Nutzers in `user://sync.cfg`.
|
||||||
|
|
||||||
|
## Google Drive
|
||||||
|
|
||||||
|
1. In der [Google Cloud Console](https://console.cloud.google.com/) ein
|
||||||
|
Projekt anlegen (z. B. `Rinkplanner`).
|
||||||
|
2. **APIs & Dienste → Bibliothek → Google Drive API** aktivieren.
|
||||||
|
3. **OAuth-Zustimmungsbildschirm** einrichten:
|
||||||
|
- Nutzertyp **Extern**
|
||||||
|
- App-Name `Rinkplanner`, Support- und Entwickler-E-Mail
|
||||||
|
- Scopes:
|
||||||
|
- `https://www.googleapis.com/auth/drive.file`
|
||||||
|
- `openid`
|
||||||
|
- `email`
|
||||||
|
- Solange die App im Status **Testing** ist, müssen Testkonten unter
|
||||||
|
„Testnutzer“ eingetragen werden. Refresh-Tokens aus dem Testing-Status
|
||||||
|
laufen nach sieben Tagen ab; für den Dauerbetrieb die App
|
||||||
|
veröffentlichen („In Produktion“).
|
||||||
|
4. **Anmeldedaten → Anmeldedaten erstellen → OAuth-Client-ID**:
|
||||||
|
- Anwendungstyp **TVs and Limited Input devices** (Device Flow).
|
||||||
|
- Die Client-ID und das Client-Secret notieren.
|
||||||
|
5. Werte in `docs/credentials.txt` eintragen:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
GOOGLE_CLIENT_ID=...
|
||||||
|
GOOGLE_CLIENT_SECRET=...
|
||||||
|
```
|
||||||
|
|
||||||
|
6. `./tools/sync_apps_config.sh` ausführen. Das schreibt die App-Werte nach
|
||||||
|
`rinkplanner/sync_apps.cfg` (gitignored, wird in den Build eingebettet).
|
||||||
|
|
||||||
|
`drive.file` ist ein nicht-sensibler Scope: Die App darf nur Dateien sehen,
|
||||||
|
die sie selbst angelegt hat. Sie kann nicht das übrige Google Drive des
|
||||||
|
Nutzers lesen. Rinkplanner legt dafür den Ordner `Rinkplanner` an.
|
||||||
|
|
||||||
|
## Dropbox
|
||||||
|
|
||||||
|
1. In der [Dropbox App Console](https://www.dropbox.com/developers/apps) eine
|
||||||
|
App anlegen.
|
||||||
|
2. **Zugriffstyp: App folder** (nicht „Full Dropbox“). Damit landet alles in
|
||||||
|
`Apps/<App-Name>/` und Rinkplanner sieht keine anderen Dateien. Der
|
||||||
|
App-Name bestimmt den Ordnernamen; nach der Produktionsfreigabe ist er
|
||||||
|
nicht mehr änderbar.
|
||||||
|
3. **Permissions** setzen:
|
||||||
|
- `files.content.read` (Download)
|
||||||
|
- `files.content.write` (Upload/Überschreiben)
|
||||||
|
- `files.metadata.read` (Ordner auflisten)
|
||||||
|
- `files.metadata.write` (Zielordner anlegen, umbenennen, löschen)
|
||||||
|
- `account_info.read` (nur für die Anzeige der Konto-E-Mail)
|
||||||
|
|
||||||
|
Änderungen mit **Save changes** speichern. Bereits verbundene Konten
|
||||||
|
müssen sich danach neu verbinden, weil der Token die alten Rechte behält.
|
||||||
|
4. **Settings → OAuth 2**:
|
||||||
|
- **Redirect-URI leer lassen** (wir nutzen den Code-Flow ohne Redirect).
|
||||||
|
- **Allow public clients / PKCE** aktivieren, falls vorhanden.
|
||||||
|
5. **App Key** notieren. Ein App Secret ist für den PKCE-Flow nicht nötig;
|
||||||
|
optional kann es ebenfalls eingetragen werden.
|
||||||
|
6. Werte in `docs/credentials.txt` eintragen:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
DROPBOX_APP_KEY=...
|
||||||
|
# optional:
|
||||||
|
DROPBOX_APP_SECRET=...
|
||||||
|
```
|
||||||
|
|
||||||
|
7. `./tools/sync_apps_config.sh` ausführen.
|
||||||
|
8. **Settings → App configuration → Development users**: **Enable additional
|
||||||
|
users** aktivieren, sonst kann nur dein eigenes Dropbox-Konto die App
|
||||||
|
verbinden. In der Development-Phase sind bis zu 500 Nutzer möglich.
|
||||||
|
|
||||||
|
Der Dropbox-Flow nutzt **PKCE ohne Redirect-URI**: Nach der Anmeldung zeigt
|
||||||
|
Dropbox einen Autorisierungscode an, den der Nutzer in Rinkplanner einfügt.
|
||||||
|
Das funktioniert auf Desktop und Android ohne lokalen Callback-Server.
|
||||||
|
|
||||||
|
## Veröffentlichungsstatus: Testing vs. Produktion
|
||||||
|
|
||||||
|
„Veröffentlichen“ ist keine Veröffentlichung im App-Store, sondern der
|
||||||
|
Wechsel der OAuth-App vom Test- in den Produktivstatus beim jeweiligen
|
||||||
|
Anbieter. Das ist nötig, damit Tokens nicht ablaufen und beliebig viele
|
||||||
|
Nutzer das Konto verbinden können.
|
||||||
|
|
||||||
|
### Google Drive
|
||||||
|
|
||||||
|
| | Testing | In Produktion |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| Nutzer | max. 100 Testnutzer | beliebige Google-Konten |
|
||||||
|
| Refresh-Token | **läuft 7 Tage nach der Zustimmung ab** | bleibt gültig, bis der Nutzer den Zugriff widerruft |
|
||||||
|
| Warnung | „Ungeprüfte App“ möglich | für `drive.file` in der Regel keine Scope-Prüfung |
|
||||||
|
|
||||||
|
Die 7-Tage-Regel gilt, weil Rinkplanner neben `openid`/`email` auch
|
||||||
|
`drive.file` anfragt. Die Ausnahme für reine Anmelde-Scopes greift hier
|
||||||
|
nicht.
|
||||||
|
|
||||||
|
**Konkret zu tun:**
|
||||||
|
|
||||||
|
1. Im Google-Cloud-Projekt unter **Google Auth Platform → Branding**:
|
||||||
|
App-Name, Support-E-Mail, Entwicklerkontakt, Startseite, Datenschutz-URL
|
||||||
|
und autorisierte Domain eintragen. Diese Links sind für externe
|
||||||
|
Produktions-Apps erforderlich.
|
||||||
|
2. Unter **Audience** auf **Publish app** klicken. Der Status wechselt zu
|
||||||
|
**In production**.
|
||||||
|
3. Eine **Markenprüfung** kann nötig sein, damit Name und Logo auf dem
|
||||||
|
Zustimmungsbildschirm erscheinen. Sie ist kein Security-Audit und dauert
|
||||||
|
laut Google meist nur Minuten, kann aber einige Tage brauchen.
|
||||||
|
4. Eine **Datenzugriffsprüfung** ist für `drive.file` nicht erforderlich,
|
||||||
|
weil der Scope als nicht-sensibel gilt. Ein teures Security-Assessment
|
||||||
|
ist damit nicht verbunden.
|
||||||
|
5. Nutzer, die schon im Testing-Status verbunden waren, müssen sich nach
|
||||||
|
dem Veröffentlichen **einmal neu verbinden**, damit sie einen
|
||||||
|
langlebigen Refresh-Token erhalten.
|
||||||
|
|
||||||
|
Kosten: keine. Google verlangt für `drive.file` keine Verifikationsgebühr.
|
||||||
|
|
||||||
|
Wenn nur du und ein paar Testgeräte den Sync nutzen, kannst du im
|
||||||
|
Testing-Status bleiben – dann muss jedes Gerät wöchentlich neu verbinden.
|
||||||
|
Für den echten Betrieb ist „In production“ die richtige Wahl.
|
||||||
|
|
||||||
|
### Dropbox
|
||||||
|
|
||||||
|
| | Development | Production |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| Nutzer | bis 500 verbundene Dropbox-Konten | unbegrenzt |
|
||||||
|
| Review | erst ab 50 verbundenen Nutzern (oder early review) | erforderlich |
|
||||||
|
| App-Name | änderbar | **nach der Freigabe nicht mehr änderbar** |
|
||||||
|
|
||||||
|
**Konkret zu tun:**
|
||||||
|
|
||||||
|
1. In der Dropbox App Console unter **Branding** ein App-Icon hinterlegen.
|
||||||
|
2. Unter **Settings → App configuration → Apply for production** den Antrag
|
||||||
|
ausfüllen: wie die App die API nutzt, warum App-Folder-Zugriff reicht,
|
||||||
|
Datenschutz-URL usw.
|
||||||
|
3. Der Antrag wird regulär erst geprüft, wenn die App **50 Nutzer** verbunden
|
||||||
|
hat. Ab 50 Nutzern hast du zwei Wochen Zeit, die Produktionsfreigabe zu
|
||||||
|
erhalten; sonst werden weitere Verbindungen blockiert.
|
||||||
|
4. Nach der Freigabe sind unbegrenzt viele Nutzer möglich. Der App-Name
|
||||||
|
bleibt dann fest.
|
||||||
|
|
||||||
|
Für eine kleine geschlossene Testgruppe reicht Development. Sobald
|
||||||
|
Rinkplanner an mehr als 50 Personen geht, sollte der Produktionsantrag
|
||||||
|
vorbereitet sein.
|
||||||
|
|
||||||
|
Wichtig für die Musik: Dropbox genehmigt keine Apps, die
|
||||||
|
Urheberrechtsverletzungen fördern. Rinkplanner stellt keine Dateien bereit
|
||||||
|
und teilt keine Musik zwischen Nutzern; die App sollte auch im Store-Text
|
||||||
|
nicht so beworben werden. Musik im eigenen Konto des Nutzers ist der
|
||||||
|
vorgesehene Fall.
|
||||||
|
|
||||||
|
## App-Werte ohne Repository-Datei
|
||||||
|
|
||||||
|
`SyncAppConfig` liest die App-Zugänge in dieser Reihenfolge (spätere Quellen
|
||||||
|
überschreiben frühere):
|
||||||
|
|
||||||
|
1. Umgebungsvariablen
|
||||||
|
`RINKPLANNER_GOOGLE_CLIENT_ID`, `RINKPLANNER_GOOGLE_CLIENT_SECRET`,
|
||||||
|
`RINKPLANNER_DROPBOX_APP_KEY`, `RINKPLANNER_DROPBOX_APP_SECRET`
|
||||||
|
2. `res://sync_apps.cfg` (beim Build eingebettet)
|
||||||
|
3. `user://sync_apps.cfg` (lokale Entwickler-Installation)
|
||||||
|
|
||||||
|
Für Release-Builds muss `rinkplanner/sync_apps.cfg` vor dem Export existieren.
|
||||||
|
Fehlt sie, startet die App normal, zeigt beim Verbinden aber einen Hinweis,
|
||||||
|
dass der Cloud-Sync in diesem Build nicht eingerichtet ist.
|
||||||
|
|
||||||
|
Die Datei wird am besten mit `./tools/sync_apps_config.sh` erzeugt. Godots
|
||||||
|
`ConfigFile`-Format erwartet Kommentare mit `;` und Strings in
|
||||||
|
Anführungszeichen (`dropbox_app_key="..."`); `#`-Kommentare oder unquoted
|
||||||
|
Werte führen zu einem Parse-Fehler.
|
||||||
|
|
||||||
|
## Nutzerfluss in der App
|
||||||
|
|
||||||
|
1. **Datei → Sync-Einstellungen…**
|
||||||
|
2. Anbieter wählen (Dropbox oder Google Drive).
|
||||||
|
3. **Verbinden…**:
|
||||||
|
- Google Drive: Rinkplanner zeigt einen Code und öffnet die
|
||||||
|
Google-Anmeldeseite. Nach der Bestätigung schließt sich der Dialog.
|
||||||
|
- Dropbox: Rinkplanner öffnet die Dropbox-Seite. Den dort angezeigten Code
|
||||||
|
in die App einfügen und **Verbinden** drücken.
|
||||||
|
4. Cloud-Ordner festlegen. Bei Dropbox leer lassen, dann liegt alles direkt
|
||||||
|
im App-Ordner `Apps/<App-Name>`. Bei Google Drive legt die App den Ordner
|
||||||
|
`Rinkplanner` an.
|
||||||
|
5. **Speichern**, danach **Datei → Jetzt synchronisieren**.
|
||||||
|
|
||||||
|
Jedes Gerät (Desktop und Tablet) wird einmal verbunden. Beide Geräte können
|
||||||
|
dasselbe Konto verwenden; der Abgleich läuft über den Cloud-Ordner.
|
||||||
|
|
||||||
|
## Lizenzen und Musikdateien
|
||||||
|
|
||||||
|
- Musikdateien werden ausschließlich im Konto des Nutzers gespeichert.
|
||||||
|
Rinkplanner betreibt keinen Speicher und keine zentrale Kopie.
|
||||||
|
- Die App greift bei Google Drive nur auf `drive.file`-Dateien zu, bei Dropbox
|
||||||
|
nur auf den App-Ordner. Es gibt keinen Zugriff auf fremde Konten.
|
||||||
|
- Es gibt kein gemeinsames Rinkplanner-Konto, über das Musik weitergegeben
|
||||||
|
würde. Jeder Nutzer ist für die Rechte an seinen hochgeladenen Dateien
|
||||||
|
selbst verantwortlich.
|
||||||
|
- In der App und in der Datenschutzerklärung sollte dieser Hinweis stehen:
|
||||||
|
„Musikdateien werden im eigenen Cloud-Konto gespeichert. Für die
|
||||||
|
Nutzungsrechte ist der Nutzer verantwortlich.“
|
||||||
|
|
||||||
|
## Sicherheit
|
||||||
|
|
||||||
|
- Nutzerpasswörter werden nie abgefragt und nie gespeichert.
|
||||||
|
- Refresh-Tokens liegen in `user://sync.cfg` (app-privat). Auf Android ist das
|
||||||
|
der interne App-Speicher; auf dem Desktop
|
||||||
|
`~/.local/share/godot/app_userdata/Rinkplanner/`.
|
||||||
|
- **Trennen** in den Sync-Einstellungen löscht den Token auf dem Gerät. Die
|
||||||
|
Cloud-Dateien bleiben erhalten.
|
||||||
|
- Ein widerrufener Zugriff führt beim nächsten Sync zu einer verständlichen
|
||||||
|
Fehlermeldung; anschließend neu verbinden.
|
||||||
|
- Das Google-Client-Secret ist bei installierten Apps nicht geheim. Es
|
||||||
|
identifiziert die App, nicht den Nutzer. Dropbox nutzt PKCE und kommt ohne
|
||||||
|
Secret aus.
|
||||||
|
|
||||||
|
## Veröffentlichung
|
||||||
|
|
||||||
|
- Google: OAuth-Zustimmungsbildschirm veröffentlichen. `drive.file` ist
|
||||||
|
nicht-sensibel; trotzdem können Angaben zu Datenschutz und
|
||||||
|
Entwickleridentität verlangt werden.
|
||||||
|
- Dropbox: Produktionszugriff in der App Console beantragen. App-Folder-Apps
|
||||||
|
haben vor der Freigabe ein Nutzerlimit.
|
||||||
|
- Für Stores eine Datenschutzerklärung hinterlegen, die den Cloud-Zugriff und
|
||||||
|
die Musikverantwortung beschreibt.
|
||||||
|
|
@ -1,15 +1,37 @@
|
||||||
# Vorlage für den FTP-Zugang (nie mit echten Werten einchecken).
|
# Vorlage für Entwickler-Zugänge (nie mit echten Werten einchecken).
|
||||||
# Die echte Datei heißt docs/credentials.txt und ist in .gitignore eingetragen.
|
# Die echte Datei heißt docs/credentials.txt und ist in .gitignore eingetragen.
|
||||||
#
|
#
|
||||||
# Format: KEY=WERT, eine Zuweisung pro Zeile. '#' startet einen Kommentar.
|
# Format: KEY=WERT, eine Zuweisung pro Zeile. '#' startet einen Kommentar.
|
||||||
#
|
#
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# FTP: nur noch für tools/sync_assets.sh --publish (Asset-Verteilung).
|
||||||
|
# Der Kür-Sync der App nutzt FTP nicht mehr.
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
# FTP_URL: Hostname oder URL des FTP-Servers, z. B. ftp.example.org
|
# FTP_URL: Hostname oder URL des FTP-Servers, z. B. ftp.example.org
|
||||||
# (Schema und Port sind optional: ftp://host:21)
|
|
||||||
# FTP_USER: Benutzername des FTP-Kontos
|
# FTP_USER: Benutzername des FTP-Kontos
|
||||||
# FTP_PASSWORD: Passwort des FTP-Kontos
|
# FTP_PASSWORD: Passwort des FTP-Kontos
|
||||||
# FTP_DIRECTORY: Zielverzeichnis relativ zum Login-Verzeichnis, z. B. rinkplanner
|
# FTP_DIRECTORY: Zielverzeichnis relativ zum Login-Verzeichnis, z. B. rinkplanner
|
||||||
|
|
||||||
FTP_URL=ftp.example.org
|
FTP_URL=ftp.example.org
|
||||||
FTP_USER=benutzer
|
FTP_USER=benutzer
|
||||||
FTP_PASSWORD=passwort
|
FTP_PASSWORD=passwort
|
||||||
FTP_DIRECTORY=rinkplanner
|
FTP_DIRECTORY=rinkplanner
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Cloud-Sync: OAuth-Apps von Rinkplanner (eine App je Anbieter, nicht je Nutzer)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Die App-Zugänge werden mit tools/sync_apps_config.sh nach
|
||||||
|
# rinkplanner/sync_apps.cfg übernommen und beim Build eingebettet.
|
||||||
|
# Jeder Nutzer verbindet danach sein eigenes Google-/Dropbox-Konto in der App.
|
||||||
|
# E-Mail/Passwörter der Nutzer werden dafür nicht benötigt und nicht gespeichert.
|
||||||
|
#
|
||||||
|
# GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET:
|
||||||
|
# OAuth-Client vom Typ "TVs and Limited Input devices" (Device Flow) in der
|
||||||
|
# Google Cloud Console. Scope: https://www.googleapis.com/auth/drive.file
|
||||||
|
# DROPBOX_APP_KEY:
|
||||||
|
# App Key einer Dropbox-App mit "App folder"-Zugriff (Scoped access).
|
||||||
|
# DROPBOX_APP_SECRET:
|
||||||
|
# Optional; der PKCE-Flow funktioniert auch ohne Secret.
|
||||||
|
GOOGLE_CLIENT_ID=
|
||||||
|
GOOGLE_CLIENT_SECRET=
|
||||||
|
DROPBOX_APP_KEY=
|
||||||
|
DROPBOX_APP_SECRET=
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,8 @@ Kür-Ordner kopiert und in der Kür-JSON als Dateiname vermerkt.
|
||||||
an diesem Zeitpunkt an; der Text wird im Dialog eingegeben.
|
an diesem Zeitpunkt an; der Text wird im Dialog eingegeben.
|
||||||
- **Bearbeiten:** Ein Klick auf ein goldenes eigenes Label öffnet den Dialog
|
- **Bearbeiten:** Ein Klick auf ein goldenes eigenes Label öffnet den Dialog
|
||||||
erneut. Dort lässt es sich umbenennen oder löschen.
|
erneut. Dort lässt es sich umbenennen oder löschen.
|
||||||
|
- **Zeit-Tooltip:** Beim Überfahren eines Element-Labels zeigt ein Tooltip
|
||||||
|
dessen Zeitpunkt im Track, z. B. `1A · 12,3 s`.
|
||||||
- Labels gehören zur Kür, werden mitgespeichert und über Undo/Redo sowie den
|
- Labels gehören zur Kür, werden mitgespeichert und über Undo/Redo sowie den
|
||||||
Sync mitgeführt.
|
Sync mitgeführt.
|
||||||
|
|
||||||
|
|
@ -102,6 +104,10 @@ Eine laufende Wiedergabe wird dabei angehalten; mit **Start** läuft sie ab
|
||||||
dieser Stelle weiter. Die Position berücksichtigt alle davor liegenden
|
dieser Stelle weiter. Die Position berücksichtigt alle davor liegenden
|
||||||
Abschnitte inklusive Element-Standzeiten.
|
Abschnitte inklusive Element-Standzeiten.
|
||||||
|
|
||||||
|
Während der Wiedergabe markiert ein **▶** den aktuellen Abschnitt in der
|
||||||
|
Liste rechts. Der Name des Abschnitts erscheint kurz oben auf der Eisfläche
|
||||||
|
und blendet sich innerhalb von zwei Sekunden weich aus.
|
||||||
|
|
||||||
## Export
|
## Export
|
||||||
|
|
||||||
**Datei → Exportieren…** schreibt nach `user://exports/`. Zur Wahl stehen:
|
**Datei → Exportieren…** schreibt nach `user://exports/`. Zur Wahl stehen:
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ Voraussetzung für Phase 1.
|
||||||
- [x] Playback-Dot mit Blickrichtung, Timeline, Play/Pause/Reset und
|
- [x] Playback-Dot mit Blickrichtung, Timeline, Play/Pause/Reset und
|
||||||
Geschwindigkeit 0,25×–2,0×
|
Geschwindigkeit 0,25×–2,0×
|
||||||
- [x] Musikstück (MP3/OGG/WAV) je Kür laden; Wiedergabe, Scrubbing und
|
- [x] Musikstück (MP3/OGG/WAV) je Kür laden; Wiedergabe, Scrubbing und
|
||||||
Geschwindigkeit laufen synchron zum Läufer; der FTP-Sync überträgt die
|
Geschwindigkeit laufen synchron zum Läufer; der Cloud-Sync überträgt die
|
||||||
Musikdatei mit der Kür
|
Musikdatei mit der Kür
|
||||||
- [x] Timeline-Labels: Kür-Labels schräg auf der Timeline, eigene Labels per
|
- [x] Timeline-Labels: Kür-Labels schräg auf der Timeline, eigene Labels per
|
||||||
Klick anlegen, bearbeiten und löschen
|
Klick anlegen, bearbeiten und löschen
|
||||||
|
|
@ -96,13 +96,14 @@ Voraussetzung für Phase 1.
|
||||||
|
|
||||||
### Erledigt: Kontosync (Desktop ↔ Tablet)
|
### Erledigt: Kontosync (Desktop ↔ Tablet)
|
||||||
|
|
||||||
- [x] Sync-Einstellungen in der App (FTP-Host, Port, Benutzer, Passwort,
|
- [x] Sync-Einstellungen in der App (Anbieter, Konto verbinden/trennen,
|
||||||
Verzeichnis, FTPS, Zertifikatsprüfung), Zugangsdaten unter `user://`
|
Cloud-Ordner), Refresh-Tokens unter `user://`
|
||||||
- [x] Manueller Sync: `.json` je Kür laden/hochladen (Legacy-`.tres` weiterhin),
|
- [x] Manueller Sync: `.json` je Kür laden/hochladen (Legacy-`.tres` weiterhin),
|
||||||
Sync-Stand lokal
|
Sync-Stand lokal
|
||||||
- [x] Konflikte als Kopien mit Server-Zeitstempel behalten
|
- [x] Konflikte als Kopien mit Server-Zeitstempel behalten
|
||||||
- [x] Fortschritt und Zusammenfassung in der Oberfläche
|
- [x] Fortschritt und Zusammenfassung in der Oberfläche
|
||||||
- [x] FTP/FTPS-Client ohne externe Bibliothek
|
- [x] Google-Drive- und Dropbox-Backend ohne externe Bibliothek
|
||||||
|
- [x] Pro-Nutzer-OAuth (Google Device Flow, Dropbox PKCE)
|
||||||
- [ ] Automatischer Sync im Hintergrund (später)
|
- [ ] Automatischer Sync im Hintergrund (später)
|
||||||
- [ ] Konflikt-Zusammenführung in der Oberfläche (später)
|
- [ ] Konflikt-Zusammenführung in der Oberfläche (später)
|
||||||
|
|
||||||
|
|
@ -164,15 +165,14 @@ Voraussetzung für Phase 1.
|
||||||
|
|
||||||
### Zurückgestellt bis nach dem Proof-of-Concept
|
### Zurückgestellt bis nach dem Proof-of-Concept
|
||||||
|
|
||||||
Wir sind bewusst noch im PoC. Der bestehende FTP-Sync und die aktuelle
|
Wir sind bewusst noch im PoC. Der bestehende Cloud-Sync und die aktuelle
|
||||||
Oberfläche reichen für Tests; Komfort und Optik werden erst nach der
|
Oberfläche reichen für Tests; Komfort und Optik werden erst nach der
|
||||||
fachlichen Validierung angefasst.
|
fachlichen Validierung angefasst.
|
||||||
|
|
||||||
- [ ] Automatischer Sync beim Start/Beenden
|
- [ ] Automatischer Sync beim Start/Beenden
|
||||||
- [ ] Konflikt-Zusammenführung in der Oberfläche
|
- [ ] Konflikt-Zusammenführung in der Oberfläche
|
||||||
- [ ] Löschweitergabe mit Bestätigung
|
- [ ] Löschweitergabe mit Bestätigung
|
||||||
- [ ] Sync über einen selbst gehosteten PHP-Webserver statt FTP
|
- [ ] Optional: Sync-Ordner pro Anbieter getrennt konfigurieren
|
||||||
(Ziel: maximaler Datenaustausch-Komfort, z. B. HTTP/JSON-API)
|
|
||||||
- [ ] Hochformat-, Multi-Window- und DeX-Layout (obere Leiste umbruchfähig)
|
- [ ] Hochformat-, Multi-Window- und DeX-Layout (obere Leiste umbruchfähig)
|
||||||
- [ ] Visuelles UI-Refactoring (z. B. Buttons statt Comboboxen) inklusive
|
- [ ] Visuelles UI-Refactoring (z. B. Buttons statt Comboboxen) inklusive
|
||||||
Übernahme des Feedbacks der Tester
|
Übernahme des Feedbacks der Tester
|
||||||
|
|
|
||||||
129
docs/sync.md
129
docs/sync.md
|
|
@ -1,35 +1,41 @@
|
||||||
# Kontosync über FTP
|
# Kür-Sync über Cloud-Speicher
|
||||||
|
|
||||||
Der Abgleich zwischen Desktop und Tablet läuft **manuell** über einen
|
Der Abgleich zwischen Desktop und Tablet läuft **manuell** über den eigenen
|
||||||
FTP-Zugang. Es gibt kein Konto im Sinne einer Anmeldung auf einem Server:
|
Cloud-Speicher des Nutzers: Google Drive oder Dropbox. Es gibt kein Konto auf
|
||||||
Die Zugangsdaten sind das „Konto“, jedes Gerät bekommt dieselben Daten.
|
einem Rinkplanner-Server. Jeder Nutzer verbindet sein eigenes Konto; die App
|
||||||
|
speichert nur den Refresh-Token lokal auf dem Gerät.
|
||||||
|
|
||||||
## Einrichten
|
## Einrichten
|
||||||
|
|
||||||
1. Auf beiden Geräten: **Datei → Sync-Einstellungen…**
|
1. Auf beiden Geräten: **Datei → Sync-Einstellungen…**
|
||||||
2. Eintragen:
|
2. **Anbieter** wählen: Dropbox oder Google Drive.
|
||||||
- **Server** – Hostname des FTP-Servers (ohne `ftp://`)
|
3. **Verbinden…** drücken und im Browser mit dem eigenen Konto anmelden:
|
||||||
- **Port** – normalerweise 21
|
- **Google Drive:** Die App zeigt einen Code und öffnet die
|
||||||
- **Benutzer / Passwort**
|
Google-Anmeldeseite. Nach der Bestätigung im Browser schließt sich der
|
||||||
- **Verzeichnis** – Zielordner relativ zum Login, z. B. `rinkplanner`
|
Dialog automatisch.
|
||||||
3. **FTPS** eingeschaltet lassen (empfohlen).
|
- **Dropbox:** Die App öffnet die Dropbox-Seite. Den dort angezeigten Code
|
||||||
4. **Server-Zertifikat prüfen** nur abschalten, wenn der Hoster ein
|
in das Feld einfügen und **Verbinden** drücken.
|
||||||
abweichendes Zertifikat nutzt (bei Shared Hosting häufig). Die Verbindung
|
4. **Cloud-Ordner** festlegen. Bei Dropbox ist das standardmäßig der
|
||||||
bleibt verschlüsselt, der Server wird dann aber nicht kryptografisch
|
App-Ordner selbst (`Apps/<App-Name>`); bei Google Drive legt die App
|
||||||
bestätigt.
|
standardmäßig den Ordner `Rinkplanner` an. Ein leerer Eintrag bedeutet
|
||||||
|
„Cloud-Hauptordner des Anbieters“.
|
||||||
5. **Speichern**.
|
5. **Speichern**.
|
||||||
|
|
||||||
Danach **Datei → Jetzt synchronisieren**.
|
Danach **Datei → Jetzt synchronisieren**.
|
||||||
|
|
||||||
|
Auf dem Tablet muss das Konto ebenfalls einmal verbunden werden. Beide Geräte
|
||||||
|
können dasselbe Google-/Dropbox-Konto verwenden; der Abgleich läuft über den
|
||||||
|
gemeinsamen Cloud-Ordner.
|
||||||
|
|
||||||
## Was passiert
|
## Was passiert
|
||||||
|
|
||||||
- Jede Kür liegt als `.json` unter `user://routines/` und wird 1:1 in das
|
- Jede Kür liegt als `.json` unter `user://routines/` und wird 1:1 in den
|
||||||
FTP-Verzeichnis gespiegelt (flach, keine Unterordner). Gehört eine
|
Cloud-Ordner gespiegelt (flach, keine Unterordner). Gehört eine Musikdatei
|
||||||
Musikdatei zur Kür (`.mp3`, `.ogg`, `.wav`), liegt sie im selben Ordner und
|
zur Kür (`.mp3`, `.ogg`, `.wav`), liegt sie im selben Ordner und wird mit
|
||||||
wird mit denselben Regeln hoch- und heruntergeladen. Legacy-`.tres`-
|
denselben Regeln hoch- und heruntergeladen. Legacy-`.tres`-Dateien werden
|
||||||
Dateien werden weiterhin mit synchronisiert, damit bestehende Installationen
|
weiterhin mit synchronisiert, damit bestehende Installationen ihre
|
||||||
ihre Serverkopien nicht verlieren; neue Speicherungen schreiben `.json`.
|
Cloud-Kopien nicht verlieren; neue Speicherungen schreiben `.json`. Beim
|
||||||
Beim Laden wird eine `.tres` vor dem `ResourceLoader` gegen eine Whitelist
|
Laden wird eine `.tres` vor dem `ResourceLoader` gegen eine Whitelist
|
||||||
geprüft (nur Modellskripte, kein eingebettetes GDScript).
|
geprüft (nur Modellskripte, kein eingebettetes GDScript).
|
||||||
- Der Sync vergleicht pro Datei den letzten gemeinsamen Stand
|
- Der Sync vergleicht pro Datei den letzten gemeinsamen Stand
|
||||||
(`user://sync_state.cfg`) mit den aktuellen Zeitstempeln:
|
(`user://sync_state.cfg`) mit den aktuellen Zeitstempeln:
|
||||||
|
|
@ -37,12 +43,12 @@ Danach **Datei → Jetzt synchronisieren**.
|
||||||
| Lage | Aktion |
|
| Lage | Aktion |
|
||||||
| :--- | :--- |
|
| :--- | :--- |
|
||||||
| nur lokal, noch nie synchronisiert | hochladen |
|
| nur lokal, noch nie synchronisiert | hochladen |
|
||||||
| nur auf dem Server | herunterladen |
|
| nur in der Cloud | herunterladen |
|
||||||
| seit dem letzten Sync nur lokal geändert | hochladen |
|
| seit dem letzten Sync nur lokal geändert | hochladen |
|
||||||
| seit dem letzten Sync nur auf dem Server geändert | herunterladen |
|
| seit dem letzten Sync nur in der Cloud geändert | herunterladen |
|
||||||
| beidseitig geändert (seit dem letzten Sync) | **Konflikt**: lokale Fassung bleibt Hauptdatei, Serverfassung kommt als `(Server …)`-Kopie dazu |
|
| beidseitig geändert (seit dem letzten Sync) | **Konflikt**: lokale Fassung bleibt Hauptdatei, Cloud-Fassung kommt als `(Server …)`-Kopie dazu |
|
||||||
| Datei auf einer Seite gelöscht | nichts tun (keine Löschweitergabe) |
|
| Datei auf einer Seite gelöscht | nichts tun (keine Löschweitergabe) |
|
||||||
| erster Sync, Datei auf beiden Seiten | **Server übernimmt**: Serverfassung wird Hauptdatei, lokale Fassung bleibt als `(Lokal …)`-Kopie |
|
| erster Sync, Datei auf beiden Seiten | **Cloud übernimmt**: Cloud-Fassung wird Hauptdatei, lokale Fassung bleibt als `(Lokal …)`-Kopie |
|
||||||
|
|
||||||
### Wie kommt eine Kür vom Desktop aufs Tablet?
|
### Wie kommt eine Kür vom Desktop aufs Tablet?
|
||||||
|
|
||||||
|
|
@ -55,11 +61,11 @@ Kür-Titel entsteht). Eine Kür mit demselben Namen auf beiden Geräten ist
|
||||||
kein „Update“, sondern eine Kollision:
|
kein „Update“, sondern eine Kollision:
|
||||||
|
|
||||||
- **Erster Sync einer Datei auf beiden Seiten** (kein gemeinsamer Stand):
|
- **Erster Sync einer Datei auf beiden Seiten** (kein gemeinsamer Stand):
|
||||||
Die **Serverfassung übernimmt den Namen**, die lokale Fassung bleibt als
|
Die **Cloud-Fassung übernimmt den Namen**, die lokale Fassung bleibt als
|
||||||
`name (Lokal JJJJ-MM-TT HHMM).json` daneben. So bekommt ein neues Gerät die
|
`name (Lokal JJJJ-MM-TT HHMM).json` daneben. So bekommt ein neues Gerät die
|
||||||
gemeinsame Version, ohne die lokale Arbeit zu verlieren.
|
gemeinsame Version, ohne die lokale Arbeit zu verlieren.
|
||||||
- **Beide Seiten seit dem letzten Sync geändert**: Die lokale Fassung bleibt
|
- **Beide Seiten seit dem letzten Sync geändert**: Die lokale Fassung bleibt
|
||||||
Hauptdatei, die Serverfassung kommt als
|
Hauptdatei, die Cloud-Fassung kommt als
|
||||||
`name (Server JJJJ-MM-TT HHMM).json` dazu. Beim nächsten Sync wird diese
|
`name (Server JJJJ-MM-TT HHMM).json` dazu. Beim nächsten Sync wird diese
|
||||||
Kopie als neue Kür hochgeladen. Zusammenführen musst du selbst.
|
Kopie als neue Kür hochgeladen. Zusammenführen musst du selbst.
|
||||||
Die Kopien behalten die Endung der Ausgangsdatei; bei Legacy-`.tres`
|
Die Kopien behalten die Endung der Ausgangsdatei; bei Legacy-`.tres`
|
||||||
|
|
@ -81,20 +87,27 @@ Kür öffnen und bearbeiten.
|
||||||
|
|
||||||
| Datei | Aufgabe |
|
| Datei | Aufgabe |
|
||||||
| :--- | :--- |
|
| :--- | :--- |
|
||||||
| `src/core/sync/ftp_client.gd` | FTP/FTPS-Client (USER/PASS, AUTH TLS + PROT P, EPSV/PASV, MLSD, SIZE, RETR, STOR, DELE, MKD, RNFR/RNTO) |
|
| `src/core/sync/remote_store.gd` | gemeinsame Schnittstelle der Cloud-Anbieter |
|
||||||
|
| `src/core/sync/dropbox_store.gd` | Dropbox-API (App-Ordner, `files/list_folder`, `files/upload`, `files/download`, `files/move_v2`) |
|
||||||
|
| `src/core/sync/google_drive_store.gd` | Google-Drive-API v3 (`drive.file`-Scope, Ordner `Rinkplanner`, Multipart-Upload, `alt=media`-Download) |
|
||||||
|
| `src/core/sync/cloud_http.gd` | blockierender HTTPS-Client für den Worker-Thread |
|
||||||
|
| `src/core/sync/cloud_auth.gd` | Refresh-Token, Access-Token-Erneuerung |
|
||||||
|
| `src/core/sync/cloud_oauth_job.gd` | Google-Device-Flow und Dropbox-PKCE-Flow |
|
||||||
|
| `src/core/sync/sync_app_config.gd` | App-Client-ID/App-Key laden |
|
||||||
| `src/core/sync/sync_plan.gd` | reine Vergleichslogik, Konfliktnamen, Zeitstempel |
|
| `src/core/sync/sync_plan.gd` | reine Vergleichslogik, Konfliktnamen, Zeitstempel |
|
||||||
| `src/core/sync/routine_sync.gd` | Ablauf, Datei-Ersetzung, Sync-Stand |
|
| `src/core/sync/routine_sync.gd` | Ablauf, Datei-Ersetzung, Sync-Stand |
|
||||||
|
|
||||||
- Der Sync läuft in einem `Thread`; die Oberfläche bleibt bedienbar und
|
- Der Sync läuft in einem `Thread`; die Oberfläche bleibt bedienbar und
|
||||||
pollt den Fortschritt in `_process`.
|
pollt den Fortschritt in `_process`.
|
||||||
- Uploads gehen zuerst nach `name.uploading` und werden dann umbenannt
|
- Cloud-Uploads sind einzelne, atomare HTTP-Anfragen (Dropbox
|
||||||
(falls der Server das verweigert: direkter Upload).
|
`files/upload` mit `mode: overwrite`, Google Drive Multipart-Upload). Ein
|
||||||
|
zusätzliches `.uploading`-Umbenennen wie beim alten FTP-Sync entfällt.
|
||||||
- Downloads landen in `name.part` und ersetzen die Zieldatei erst danach.
|
- Downloads landen in `name.part` und ersetzen die Zieldatei erst danach.
|
||||||
- Heruntergeladene `.json`-Dateien werden als JSON validiert; Legacy-`.tres`
|
- Heruntergeladene `.json`-Dateien werden als JSON validiert; Legacy-`.tres`
|
||||||
laufen vor dem Laden durch die Whitelist in `RoutineFile`. Ein präparierter
|
laufen vor dem Laden durch die Whitelist in `RoutineFile`. Ein manipuliertes
|
||||||
Server kann damit keine eingebetteten GDScripts ausführen.
|
Cloud-Konto kann damit keine eingebetteten GDScripts ausführen.
|
||||||
- Neue Speicherungen sind JSON; der Sync akzeptiert weiterhin `.tres`, damit
|
- Neue Speicherungen sind JSON; der Sync akzeptiert weiterhin `.tres`, damit
|
||||||
bestehende Dateien auf Server und Tablet nicht verschwinden.
|
bestehende Dateien in der Cloud und auf dem Tablet nicht verschwinden.
|
||||||
- Musikdateien werden als normale Anhänge der Kür behandelt: Die JSON nennt
|
- Musikdateien werden als normale Anhänge der Kür behandelt: Die JSON nennt
|
||||||
nur den Dateinamen (`music_file`), die Datei liegt daneben. Ändert sich die
|
nur den Dateinamen (`music_file`), die Datei liegt daneben. Ändert sich die
|
||||||
Musik auf einem Gerät, lädt der nächste Sync sie hoch; auf dem anderen Gerät
|
Musik auf einem Gerät, lädt der nächste Sync sie hoch; auf dem anderen Gerät
|
||||||
|
|
@ -102,22 +115,30 @@ Kür öffnen und bearbeiten.
|
||||||
behalten die Audio-Endung (z. B. `kuer (Server …).mp3`).
|
behalten die Audio-Endung (z. B. `kuer (Server …).mp3`).
|
||||||
- Eigene Timeline-Labels stehen in der Kür-JSON (`timeline_labels`) und
|
- Eigene Timeline-Labels stehen in der Kür-JSON (`timeline_labels`) und
|
||||||
werden ohne Zusatzdateien mit der Kür übertragen.
|
werden ohne Zusatzdateien mit der Kür übertragen.
|
||||||
- Zugangsdaten liegen in `user://sync.cfg` (Klartext, app-privat). Auf
|
- Refresh-Tokens liegen in `user://sync.cfg` (Klartext, app-privat). Auf
|
||||||
Android ist das der interne App-Speicher, auf dem Desktop
|
Android ist das der interne App-Speicher, auf dem Desktop
|
||||||
`~/.local/share/godot/app_userdata/Rinkplanner/`.
|
`~/.local/share/godot/app_userdata/Rinkplanner/`. Nutzerpasswörter werden
|
||||||
|
nicht gespeichert. Nach einem Kontowechsel oder Anbieterwechsel wird
|
||||||
|
`user://sync_state.cfg` zurückgesetzt, damit alte Zeitstempel keinen
|
||||||
|
falschen Konflikt auslösen.
|
||||||
- Android braucht die `INTERNET`-Berechtigung – ist im APK gesetzt.
|
- Android braucht die `INTERNET`-Berechtigung – ist im APK gesetzt.
|
||||||
|
|
||||||
## Erfahrungen mit dem Zielserver
|
## Datenschutz und Musiklizenzen
|
||||||
|
|
||||||
- Der Server spricht explizites FTPS (`AUTH TLS`), außerdem `MLST`, `MDTM`,
|
- Bei Google Drive nutzt die App den Scope `drive.file`: Sie sieht nur
|
||||||
`MFMT` und `EPSV` – genau das, was der Abgleich braucht.
|
Dateien, die Rinkplanner selbst angelegt hat, nicht das übrige Drive.
|
||||||
- Sein TLS-Zertifikat passt nicht zum Hostnamen (leeres CN/SAN). Deshalb muss
|
- Bei Dropbox ist die App auf einen **App-Ordner** beschränkt.
|
||||||
„Server-Zertifikat prüfen“ ausgeschaltet werden; die Übertragung bleibt
|
- Musikdateien werden im Konto des Nutzers gespeichert. Es gibt keinen
|
||||||
verschlüsselt.
|
zentralen Rinkplanner-Speicher und keine Weitergabe zwischen Konten. Die
|
||||||
- Der Zielordner existiert in Kleinschreibung. Die App wechselt direkt
|
Verantwortung für die Nutzungsrechte liegt beim Nutzer.
|
||||||
hinein und legt ihn bei Bedarf per `MKD` an.
|
- Die App zeigt diesen Hinweis in den Sync-Einstellungen und sollte ihn auch
|
||||||
- Ein vollständiger Testlauf (Upload, Überspringen, Download, Übernahme,
|
in der Datenschutzerklärung für Stores führen.
|
||||||
Konflikt, Aufräumen) lief gegen den echten Server erfolgreich.
|
|
||||||
|
## Einrichtung der OAuth-Apps
|
||||||
|
|
||||||
|
Die App-Registrierung bei Google und Dropbox, die nötigen Scopes und die
|
||||||
|
Werte in `docs/credentials.txt` stehen in
|
||||||
|
[`docs/cloud-setup.md`](cloud-setup.md).
|
||||||
|
|
||||||
## Grenzen
|
## Grenzen
|
||||||
|
|
||||||
|
|
@ -126,7 +147,23 @@ Kür öffnen und bearbeiten.
|
||||||
verhindert dann Datenverlust, nicht aber doppelte Dateien.
|
verhindert dann Datenverlust, nicht aber doppelte Dateien.
|
||||||
- Löschungen werden nicht übertragen (bewusst, um Versehen nicht zu
|
- Löschungen werden nicht übertragen (bewusst, um Versehen nicht zu
|
||||||
multiplizieren).
|
multiplizieren).
|
||||||
- Umbenennen einer Kür wirkt wie „neu lokal“ + „nur Server“: beide Fassungen
|
- Umbenennen einer Kür wirkt wie „neu lokal“ + „nur Cloud“: beide Fassungen
|
||||||
landen nebeneinander.
|
landen nebeneinander.
|
||||||
- Sehr große Kürsammlungen werden vollständig verglichen; für hunderte
|
- Sehr große Kürsammlungen werden vollständig verglichen; für hunderte
|
||||||
Dateien ist das noch unkritisch, für tausende wäre ein Manifest sinnvoll.
|
Dateien ist das noch unkritisch, für tausende wäre ein Manifest sinnvoll.
|
||||||
|
- Dropbox-Uploads sind auf 150 MB pro Datei begrenzt (App-Ordner-Apps). Für
|
||||||
|
Kür-JSONs und übliche Musikdateien reicht das; größere Dateien müssten
|
||||||
|
chunked hochgeladen werden.
|
||||||
|
- Google Drive erlaubt technisch mehrere Dateien mit demselben Namen. Der
|
||||||
|
Sync sucht die erste passende Datei und führt bestehende Duplikate aus
|
||||||
|
anderen Quellen nicht zusammen.
|
||||||
|
|
||||||
|
## Migration vom FTP-Sync
|
||||||
|
|
||||||
|
Der frühere FTP-/FTPS-Sync ist entfernt. Alte `user://sync.cfg`-Einträge
|
||||||
|
(`host`, `port`, `user`, `password`, `ftps`, `verify_certificate`) werden
|
||||||
|
ignoriert; beim ersten Öffnen der Sync-Einstellungen muss ein Cloud-Konto
|
||||||
|
verbunden werden. Die Dateien im alten FTP-Verzeichnis werden nicht
|
||||||
|
automatisch übernommen: Wer sie behalten will, kopiert sie einmalig manuell
|
||||||
|
in den Cloud-Ordner oder verbindet beide Geräte mit demselben Cloud-Konto und
|
||||||
|
lädt die lokalen Kürdateien hoch.
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ advanced_options=false
|
||||||
dedicated_server=false
|
dedicated_server=false
|
||||||
custom_features=""
|
custom_features=""
|
||||||
export_filter="all_resources"
|
export_filter="all_resources"
|
||||||
include_filter="*.json,assets/external/characters/*.glb"
|
include_filter="*.json,assets/external/characters/*.glb,sync_apps.cfg"
|
||||||
exclude_filter="tests/*,prototype/*,docs/*,addons/script-ide/*,addons/godot_ai_bridge/godot_ai_bridge.gd,addons/godot_ai_bridge/message_handler.gd,addons/godot_ai_bridge/ws_server.gd,assets/models/*,assets/external/characters/weights_rings*"
|
exclude_filter="tests/*,prototype/*,docs/*,addons/script-ide/*,addons/godot_ai_bridge/godot_ai_bridge.gd,addons/godot_ai_bridge/message_handler.gd,addons/godot_ai_bridge/ws_server.gd,assets/models/*,assets/external/characters/weights_rings*"
|
||||||
export_path="build/linux/rinkplanner.x86_64"
|
export_path="build/linux/rinkplanner.x86_64"
|
||||||
patches=PackedStringArray()
|
patches=PackedStringArray()
|
||||||
|
|
@ -39,7 +39,7 @@ advanced_options=false
|
||||||
dedicated_server=false
|
dedicated_server=false
|
||||||
custom_features=""
|
custom_features=""
|
||||||
export_filter="all_resources"
|
export_filter="all_resources"
|
||||||
include_filter="*.json,assets/external/characters/*.glb"
|
include_filter="*.json,assets/external/characters/*.glb,sync_apps.cfg"
|
||||||
exclude_filter="tests/*,prototype/*,docs/*,addons/script-ide/*,addons/godot_ai_bridge/godot_ai_bridge.gd,addons/godot_ai_bridge/message_handler.gd,addons/godot_ai_bridge/ws_server.gd,assets/models/*,assets/external/characters/weights_rings*"
|
exclude_filter="tests/*,prototype/*,docs/*,addons/script-ide/*,addons/godot_ai_bridge/godot_ai_bridge.gd,addons/godot_ai_bridge/message_handler.gd,addons/godot_ai_bridge/ws_server.gd,assets/models/*,assets/external/characters/weights_rings*"
|
||||||
export_path="build/windows/rinkplanner.exe"
|
export_path="build/windows/rinkplanner.exe"
|
||||||
patches=PackedStringArray()
|
patches=PackedStringArray()
|
||||||
|
|
@ -94,7 +94,7 @@ advanced_options=false
|
||||||
dedicated_server=false
|
dedicated_server=false
|
||||||
custom_features=""
|
custom_features=""
|
||||||
export_filter="all_resources"
|
export_filter="all_resources"
|
||||||
include_filter="*.json,assets/external/characters/*.glb"
|
include_filter="*.json,assets/external/characters/*.glb,sync_apps.cfg"
|
||||||
exclude_filter="tests/*,prototype/*,docs/*,addons/script-ide/*,addons/godot_ai_bridge/godot_ai_bridge.gd,addons/godot_ai_bridge/message_handler.gd,addons/godot_ai_bridge/ws_server.gd,assets/models/*,assets/external/characters/weights_rings*"
|
exclude_filter="tests/*,prototype/*,docs/*,addons/script-ide/*,addons/godot_ai_bridge/godot_ai_bridge.gd,addons/godot_ai_bridge/message_handler.gd,addons/godot_ai_bridge/ws_server.gd,assets/models/*,assets/external/characters/weights_rings*"
|
||||||
export_path="build/macos/rinkplanner.zip"
|
export_path="build/macos/rinkplanner.zip"
|
||||||
patches=PackedStringArray()
|
patches=PackedStringArray()
|
||||||
|
|
@ -214,7 +214,7 @@ advanced_options=false
|
||||||
dedicated_server=false
|
dedicated_server=false
|
||||||
custom_features=""
|
custom_features=""
|
||||||
export_filter="all_resources"
|
export_filter="all_resources"
|
||||||
include_filter="*.json,assets/external/characters/*.glb"
|
include_filter="*.json,assets/external/characters/*.glb,sync_apps.cfg"
|
||||||
exclude_filter="tests/*,prototype/*,docs/*,addons/script-ide/*,addons/godot_ai_bridge/godot_ai_bridge.gd,addons/godot_ai_bridge/message_handler.gd,addons/godot_ai_bridge/ws_server.gd,assets/models/*,assets/external/characters/weights_rings*"
|
exclude_filter="tests/*,prototype/*,docs/*,addons/script-ide/*,addons/godot_ai_bridge/godot_ai_bridge.gd,addons/godot_ai_bridge/message_handler.gd,addons/godot_ai_bridge/ws_server.gd,assets/models/*,assets/external/characters/weights_rings*"
|
||||||
export_path="build/android/rinkplanner.apk"
|
export_path="build/android/rinkplanner.apk"
|
||||||
patches=PackedStringArray()
|
patches=PackedStringArray()
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,7 @@ text = "+"
|
||||||
tooltip_text = "Abschnitt hinzufügen"
|
tooltip_text = "Abschnitt hinzufügen"
|
||||||
|
|
||||||
[node name="SectionScroll" type="ScrollContainer" parent="Layout/Content/SectionsPanel/SectionsVBox"]
|
[node name="SectionScroll" type="ScrollContainer" parent="Layout/Content/SectionsPanel/SectionsVBox"]
|
||||||
|
unique_name_in_owner = true
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
horizontal_scroll_mode = 0
|
horizontal_scroll_mode = 0
|
||||||
|
|
@ -819,8 +820,8 @@ cancel_button_text = "Abbrechen"
|
||||||
|
|
||||||
[node name="SyncSettingsDialog" type="ConfirmationDialog" parent="."]
|
[node name="SyncSettingsDialog" type="ConfirmationDialog" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
title = "Sync-Einstellungen (FTP)"
|
title = "Sync-Einstellungen"
|
||||||
size = Vector2i(620, 620)
|
size = Vector2i(620, 500)
|
||||||
ok_button_text = "Speichern"
|
ok_button_text = "Speichern"
|
||||||
cancel_button_text = "Abbrechen"
|
cancel_button_text = "Abbrechen"
|
||||||
|
|
||||||
|
|
@ -828,7 +829,7 @@ cancel_button_text = "Abbrechen"
|
||||||
offset_left = 12.0
|
offset_left = 12.0
|
||||||
offset_top = 12.0
|
offset_top = 12.0
|
||||||
offset_right = 608.0
|
offset_right = 608.0
|
||||||
offset_bottom = 540.0
|
offset_bottom = 430.0
|
||||||
theme_override_constants/separation = 10
|
theme_override_constants/separation = 10
|
||||||
|
|
||||||
[node name="SyncHint" type="Label" parent="SyncSettingsDialog/SyncBox"]
|
[node name="SyncHint" type="Label" parent="SyncSettingsDialog/SyncBox"]
|
||||||
|
|
@ -836,7 +837,7 @@ custom_minimum_size = Vector2(560, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||||
theme_override_font_sizes/font_size = 14
|
theme_override_font_sizes/font_size = 14
|
||||||
text = "Zugangsdaten werden nur lokal unter user://sync.cfg gespeichert. Der Abgleich läuft manuell über Datei → Jetzt synchronisieren."
|
text = "Jedes Gerät verbindet sein eigenes Google- oder Dropbox-Konto. Rinkplanner speichert die Kürdateien und Musik nur in diesem Konto; es gibt keinen gemeinsamen Server."
|
||||||
autowrap_mode = 2
|
autowrap_mode = 2
|
||||||
|
|
||||||
[node name="SyncGrid" type="GridContainer" parent="SyncSettingsDialog/SyncBox"]
|
[node name="SyncGrid" type="GridContainer" parent="SyncSettingsDialog/SyncBox"]
|
||||||
|
|
@ -845,82 +846,106 @@ theme_override_constants/h_separation = 10
|
||||||
theme_override_constants/v_separation = 8
|
theme_override_constants/v_separation = 8
|
||||||
columns = 2
|
columns = 2
|
||||||
|
|
||||||
[node name="SyncHostLabel" type="Label" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
[node name="SyncProviderLabel" type="Label" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Server"
|
text = "Anbieter"
|
||||||
|
|
||||||
[node name="SyncHostEdit" type="LineEdit" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
[node name="SyncProviderOption" type="OptionButton" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
custom_minimum_size = Vector2(330, 48)
|
custom_minimum_size = Vector2(330, 48)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
placeholder_text = "ftp.example.org"
|
|
||||||
|
|
||||||
[node name="SyncPortLabel" type="Label" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
|
||||||
layout_mode = 2
|
|
||||||
text = "Port"
|
|
||||||
|
|
||||||
[node name="SyncPortEdit" type="LineEdit" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
custom_minimum_size = Vector2(330, 48)
|
|
||||||
layout_mode = 2
|
|
||||||
size_flags_horizontal = 3
|
|
||||||
text = "21"
|
|
||||||
|
|
||||||
[node name="SyncUserLabel" type="Label" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
|
||||||
layout_mode = 2
|
|
||||||
text = "Benutzer"
|
|
||||||
|
|
||||||
[node name="SyncUserEdit" type="LineEdit" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
custom_minimum_size = Vector2(330, 48)
|
|
||||||
layout_mode = 2
|
|
||||||
size_flags_horizontal = 3
|
|
||||||
|
|
||||||
[node name="SyncPasswordLabel" type="Label" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
|
||||||
layout_mode = 2
|
|
||||||
text = "Passwort"
|
|
||||||
|
|
||||||
[node name="SyncPasswordEdit" type="LineEdit" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
|
||||||
unique_name_in_owner = true
|
|
||||||
custom_minimum_size = Vector2(330, 48)
|
|
||||||
layout_mode = 2
|
|
||||||
size_flags_horizontal = 3
|
|
||||||
secret = true
|
|
||||||
|
|
||||||
[node name="SyncDirectoryLabel" type="Label" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
[node name="SyncDirectoryLabel" type="Label" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Verzeichnis"
|
text = "Cloud-Ordner"
|
||||||
|
|
||||||
[node name="SyncDirectoryEdit" type="LineEdit" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
[node name="SyncDirectoryEdit" type="LineEdit" parent="SyncSettingsDialog/SyncBox/SyncGrid"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
custom_minimum_size = Vector2(330, 48)
|
custom_minimum_size = Vector2(330, 48)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
placeholder_text = "rinkplanner"
|
placeholder_text = "leer = Cloud-Hauptordner"
|
||||||
|
|
||||||
[node name="SyncFtpsCheck" type="CheckBox" parent="SyncSettingsDialog/SyncBox"]
|
[node name="SyncAccountRow" type="HBoxContainer" parent="SyncSettingsDialog/SyncBox"]
|
||||||
unique_name_in_owner = true
|
|
||||||
custom_minimum_size = Vector2(0, 48)
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
button_pressed = true
|
theme_override_constants/separation = 10
|
||||||
text = "FTPS (verschlüsselte Verbindung)"
|
|
||||||
|
|
||||||
[node name="SyncVerifyCheck" type="CheckBox" parent="SyncSettingsDialog/SyncBox"]
|
[node name="SyncAccountLabel" type="Label" parent="SyncSettingsDialog/SyncBox/SyncAccountRow"]
|
||||||
unique_name_in_owner = true
|
|
||||||
custom_minimum_size = Vector2(0, 48)
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
button_pressed = true
|
text = "Konto"
|
||||||
text = "Server-Zertifikat prüfen"
|
|
||||||
|
|
||||||
[node name="SyncVerifyHint" type="Label" parent="SyncSettingsDialog/SyncBox"]
|
[node name="SyncAccountValue" type="Label" parent="SyncSettingsDialog/SyncBox/SyncAccountRow"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
text = "Nicht verbunden"
|
||||||
|
autowrap_mode = 2
|
||||||
|
|
||||||
|
[node name="SyncConnectButton" type="Button" parent="SyncSettingsDialog/SyncBox/SyncAccountRow"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(150, 44)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Verbinden…"
|
||||||
|
|
||||||
|
[node name="SyncHint2" type="Label" parent="SyncSettingsDialog/SyncBox"]
|
||||||
custom_minimum_size = Vector2(560, 0)
|
custom_minimum_size = Vector2(560, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||||
theme_override_font_sizes/font_size = 13
|
theme_override_font_sizes/font_size = 13
|
||||||
text = "Nur abschalten, wenn der Server ein abweichendes Zertifikat nutzt (z. B. Shared Hosting)."
|
text = "Musikdateien liegen im eigenen Cloud-Konto. Für die Nutzungsrechte an der Musik ist der Nutzer verantwortlich. Zugangsdaten bleiben lokal unter user://sync.cfg; der Abgleich läuft manuell über Datei → Jetzt synchronisieren."
|
||||||
autowrap_mode = 2
|
autowrap_mode = 2
|
||||||
|
|
||||||
|
[node name="CloudAuthDialog" type="ConfirmationDialog" parent="."]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
title = "Cloud-Konto verbinden"
|
||||||
|
size = Vector2i(620, 430)
|
||||||
|
ok_button_text = "Weiter"
|
||||||
|
cancel_button_text = "Abbrechen"
|
||||||
|
|
||||||
|
[node name="CloudAuthBox" type="VBoxContainer" parent="CloudAuthDialog"]
|
||||||
|
offset_left = 12.0
|
||||||
|
offset_top = 12.0
|
||||||
|
offset_right = 608.0
|
||||||
|
offset_bottom = 360.0
|
||||||
|
theme_override_constants/separation = 10
|
||||||
|
|
||||||
|
[node name="CloudAuthStatus" type="Label" parent="CloudAuthDialog/CloudAuthBox"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(560, 0)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Anmeldung wird vorbereitet …"
|
||||||
|
autowrap_mode = 2
|
||||||
|
|
||||||
|
[node name="CloudAuthUrlEdit" type="LineEdit" parent="CloudAuthDialog/CloudAuthBox"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(560, 48)
|
||||||
|
layout_mode = 2
|
||||||
|
editable = false
|
||||||
|
select_all_on_focus = true
|
||||||
|
|
||||||
|
[node name="CloudAuthUserCode" type="Label" parent="CloudAuthDialog/CloudAuthBox"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(560, 0)
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_font_sizes/font_size = 30
|
||||||
|
horizontal_alignment = 1
|
||||||
|
|
||||||
|
[node name="CloudAuthCodeHint" type="Label" parent="CloudAuthDialog/CloudAuthBox"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(560, 0)
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||||
|
theme_override_font_sizes/font_size = 14
|
||||||
|
text = "Code aus der Dropbox-Seite hier einfügen."
|
||||||
|
autowrap_mode = 2
|
||||||
|
|
||||||
|
[node name="CloudAuthCodeEdit" type="LineEdit" parent="CloudAuthDialog/CloudAuthBox"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(560, 52)
|
||||||
|
layout_mode = 2
|
||||||
|
placeholder_text = "Autorisierungscode"
|
||||||
|
|
||||||
[node name="AutosaveTimer" type="Timer" parent="."]
|
[node name="AutosaveTimer" type="Timer" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
wait_time = 1.5
|
wait_time = 1.5
|
||||||
|
|
|
||||||
152
rinkplanner/src/core/sync/cloud_auth.gd
Normal file
152
rinkplanner/src/core/sync/cloud_auth.gd
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
class_name CloudAuth
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
## Holds the OAuth tokens of one provider for one user and refreshes the
|
||||||
|
## short-lived access token when needed. Tokens are stored by the controller in
|
||||||
|
## `user://sync.cfg`; this class never writes to disk.
|
||||||
|
|
||||||
|
const GOOGLE_TOKEN_URL := "https://oauth2.googleapis.com/token"
|
||||||
|
const DROPBOX_TOKEN_URL := "https://api.dropboxapi.com/oauth2/token"
|
||||||
|
const EXPIRY_MARGIN_SECONDS := 60
|
||||||
|
|
||||||
|
var provider: String = ""
|
||||||
|
var client_id: String = ""
|
||||||
|
var client_secret: String = ""
|
||||||
|
var refresh_token: String = ""
|
||||||
|
var access_token: String = ""
|
||||||
|
var expires_at: int = 0
|
||||||
|
var account: String = ""
|
||||||
|
var last_error: String = ""
|
||||||
|
|
||||||
|
|
||||||
|
func configure(
|
||||||
|
p_provider: String,
|
||||||
|
p_client_id: String,
|
||||||
|
p_client_secret: String,
|
||||||
|
tokens: Dictionary
|
||||||
|
) -> void:
|
||||||
|
provider = p_provider
|
||||||
|
client_id = p_client_id
|
||||||
|
client_secret = p_client_secret
|
||||||
|
refresh_token = str(tokens.get("refresh_token", ""))
|
||||||
|
access_token = str(tokens.get("access_token", ""))
|
||||||
|
expires_at = int(tokens.get("expires_at", 0))
|
||||||
|
account = str(tokens.get("account", ""))
|
||||||
|
|
||||||
|
|
||||||
|
func ensure_access_token() -> String:
|
||||||
|
last_error = ""
|
||||||
|
if not access_token.is_empty() and Time.get_unix_time_from_system() < expires_at - EXPIRY_MARGIN_SECONDS:
|
||||||
|
return ""
|
||||||
|
if refresh_token.is_empty():
|
||||||
|
last_error = "Nicht mit dem Cloud-Konto verbunden."
|
||||||
|
return last_error
|
||||||
|
|
||||||
|
var http := CloudHttp.new()
|
||||||
|
var params := {
|
||||||
|
"grant_type": "refresh_token",
|
||||||
|
"refresh_token": refresh_token,
|
||||||
|
}
|
||||||
|
if provider == "google_drive":
|
||||||
|
params["client_id"] = client_id
|
||||||
|
params["client_secret"] = client_secret
|
||||||
|
else:
|
||||||
|
params["client_id"] = client_id
|
||||||
|
if not client_secret.is_empty():
|
||||||
|
params["client_secret"] = client_secret
|
||||||
|
|
||||||
|
var response := http.request(
|
||||||
|
HTTPClient.METHOD_POST,
|
||||||
|
_token_url(),
|
||||||
|
PackedStringArray(["Content-Type: application/x-www-form-urlencoded"]),
|
||||||
|
CloudHttp.form_encode(params).to_utf8_buffer()
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
last_error = http.last_error
|
||||||
|
return last_error
|
||||||
|
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
if int(response["status"]) != 200:
|
||||||
|
last_error = _friendly_error(data, response)
|
||||||
|
return last_error
|
||||||
|
if not data is Dictionary:
|
||||||
|
last_error = "Ungültige Token-Antwort des Anbieters."
|
||||||
|
return last_error
|
||||||
|
|
||||||
|
_apply_token_response(data)
|
||||||
|
if access_token.is_empty():
|
||||||
|
last_error = "Der Anbieter hat keinen Access-Token geliefert."
|
||||||
|
return last_error
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func to_tokens() -> Dictionary:
|
||||||
|
return {
|
||||||
|
"refresh_token": refresh_token,
|
||||||
|
"access_token": access_token,
|
||||||
|
"expires_at": expires_at,
|
||||||
|
"account": account,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func _apply_token_response(data: Dictionary) -> void:
|
||||||
|
access_token = str(data.get("access_token", ""))
|
||||||
|
var new_refresh := str(data.get("refresh_token", ""))
|
||||||
|
if not new_refresh.is_empty():
|
||||||
|
refresh_token = new_refresh
|
||||||
|
expires_at = (
|
||||||
|
int(Time.get_unix_time_from_system())
|
||||||
|
+ maxi(60, int(data.get("expires_in", 3600)))
|
||||||
|
)
|
||||||
|
var id_token := str(data.get("id_token", ""))
|
||||||
|
if account.is_empty() and not id_token.is_empty():
|
||||||
|
account = CloudAuth.email_from_id_token(id_token)
|
||||||
|
|
||||||
|
|
||||||
|
func _token_url() -> String:
|
||||||
|
return GOOGLE_TOKEN_URL if provider == "google_drive" else DROPBOX_TOKEN_URL
|
||||||
|
|
||||||
|
|
||||||
|
func _friendly_error(data: Variant, response: Dictionary) -> String:
|
||||||
|
var detail := CloudHttp.error_text(data, response)
|
||||||
|
if provider == "google_drive" and detail.contains("invalid_grant"):
|
||||||
|
return (
|
||||||
|
"Die Google-Anmeldung ist abgelaufen oder wurde widerrufen. "
|
||||||
|
+ "Bitte das Konto erneut verbinden."
|
||||||
|
)
|
||||||
|
if provider == "dropbox" and detail.contains("invalid_grant"):
|
||||||
|
return (
|
||||||
|
"Die Dropbox-Anmeldung ist abgelaufen oder wurde widerrufen. "
|
||||||
|
+ "Bitte das Konto erneut verbinden."
|
||||||
|
)
|
||||||
|
return "Token-Erneuerung fehlgeschlagen: %s" % detail
|
||||||
|
|
||||||
|
|
||||||
|
static func tokens_from_response(data: Dictionary) -> Dictionary:
|
||||||
|
var tokens := {
|
||||||
|
"access_token": str(data.get("access_token", "")),
|
||||||
|
"refresh_token": str(data.get("refresh_token", "")),
|
||||||
|
"expires_at": (
|
||||||
|
int(Time.get_unix_time_from_system())
|
||||||
|
+ maxi(60, int(data.get("expires_in", 3600)))
|
||||||
|
),
|
||||||
|
"account": "",
|
||||||
|
}
|
||||||
|
var id_token := str(data.get("id_token", ""))
|
||||||
|
if not id_token.is_empty():
|
||||||
|
tokens["account"] = email_from_id_token(id_token)
|
||||||
|
return tokens
|
||||||
|
|
||||||
|
|
||||||
|
static func email_from_id_token(id_token: String) -> String:
|
||||||
|
var parts := id_token.split(".")
|
||||||
|
if parts.size() < 2:
|
||||||
|
return ""
|
||||||
|
var payload := parts[1].replace("-", "+").replace("_", "/")
|
||||||
|
while payload.length() % 4 != 0:
|
||||||
|
payload += "="
|
||||||
|
var raw := Marshalls.base64_to_raw(payload)
|
||||||
|
var data: Variant = JSON.parse_string(raw.get_string_from_utf8())
|
||||||
|
if data is Dictionary:
|
||||||
|
return str((data as Dictionary).get("email", ""))
|
||||||
|
return ""
|
||||||
1
rinkplanner/src/core/sync/cloud_auth.gd.uid
Normal file
1
rinkplanner/src/core/sync/cloud_auth.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bh2kwi34xujd1
|
||||||
305
rinkplanner/src/core/sync/cloud_http.gd
Normal file
305
rinkplanner/src/core/sync/cloud_http.gd
Normal file
|
|
@ -0,0 +1,305 @@
|
||||||
|
class_name CloudHttp
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
## Small blocking HTTP client for the cloud sync. Runs on a worker thread, so
|
||||||
|
## it uses [HTTPClient] directly instead of the scene-tree [HTTPRequest] node.
|
||||||
|
##
|
||||||
|
## All helpers return plain data; network failures are reported through
|
||||||
|
## [member last_error] and an empty dictionary.
|
||||||
|
|
||||||
|
const DEFAULT_TIMEOUT_MSEC := 30000
|
||||||
|
const TRANSFER_TIMEOUT_MSEC := 300000
|
||||||
|
const POLL_DELAY_MSEC := 5
|
||||||
|
const USER_AGENT := "Rinkplanner/0.1 (Godot)"
|
||||||
|
|
||||||
|
var last_error: String = ""
|
||||||
|
|
||||||
|
|
||||||
|
func request(
|
||||||
|
method: int,
|
||||||
|
url: String,
|
||||||
|
headers: PackedStringArray = PackedStringArray(),
|
||||||
|
body: PackedByteArray = PackedByteArray(),
|
||||||
|
timeout_msec: int = DEFAULT_TIMEOUT_MSEC,
|
||||||
|
redirects_left: int = 5
|
||||||
|
) -> Dictionary:
|
||||||
|
last_error = ""
|
||||||
|
var parsed := parse_url(url)
|
||||||
|
if parsed.is_empty():
|
||||||
|
last_error = "Ungültige URL: %s" % url
|
||||||
|
return {}
|
||||||
|
|
||||||
|
var client := HTTPClient.new()
|
||||||
|
var tls: TLSOptions = null
|
||||||
|
if str(parsed["scheme"]) == "https":
|
||||||
|
tls = TLSOptions.client()
|
||||||
|
var err := client.connect_to_host(
|
||||||
|
str(parsed["host"]),
|
||||||
|
int(parsed["port"]),
|
||||||
|
tls
|
||||||
|
)
|
||||||
|
if err != OK:
|
||||||
|
last_error = "Verbindung zu %s fehlgeschlagen (Fehler %d)" % [parsed["host"], err]
|
||||||
|
return {}
|
||||||
|
|
||||||
|
var deadline := Time.get_ticks_msec() + timeout_msec
|
||||||
|
if not _wait_connected(client, deadline):
|
||||||
|
client.close()
|
||||||
|
if last_error.is_empty():
|
||||||
|
last_error = "Zeitüberschreitung beim Verbindungsaufbau zu %s" % parsed["host"]
|
||||||
|
return {}
|
||||||
|
|
||||||
|
var request_headers := PackedStringArray(headers)
|
||||||
|
request_headers.append("User-Agent: " + USER_AGENT)
|
||||||
|
request_headers.append("Accept-Encoding: identity")
|
||||||
|
err = client.request_raw(method, str(parsed["path"]), request_headers, body)
|
||||||
|
if err != OK:
|
||||||
|
client.close()
|
||||||
|
last_error = "Anfrage konnte nicht gesendet werden (Fehler %d)" % err
|
||||||
|
return {}
|
||||||
|
|
||||||
|
while client.get_status() == HTTPClient.STATUS_REQUESTING:
|
||||||
|
if Time.get_ticks_msec() > deadline:
|
||||||
|
client.close()
|
||||||
|
last_error = "Zeitüberschreitung beim Warten auf die Antwort"
|
||||||
|
return {}
|
||||||
|
client.poll()
|
||||||
|
OS.delay_msec(POLL_DELAY_MSEC)
|
||||||
|
|
||||||
|
if not client.has_response():
|
||||||
|
var status := client.get_status()
|
||||||
|
client.close()
|
||||||
|
last_error = _status_error(status)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
var response_status := client.get_response_code()
|
||||||
|
var response_headers := client.get_response_headers_as_dictionary()
|
||||||
|
var payload := PackedByteArray()
|
||||||
|
while client.get_status() == HTTPClient.STATUS_BODY:
|
||||||
|
if Time.get_ticks_msec() > deadline:
|
||||||
|
client.close()
|
||||||
|
last_error = "Zeitüberschreitung beim Lesen der Antwort"
|
||||||
|
return {}
|
||||||
|
client.poll()
|
||||||
|
var chunk := client.read_response_body_chunk()
|
||||||
|
if chunk.size() > 0:
|
||||||
|
payload.append_array(chunk)
|
||||||
|
else:
|
||||||
|
OS.delay_msec(POLL_DELAY_MSEC)
|
||||||
|
client.close()
|
||||||
|
|
||||||
|
var location := header(response_headers, "location")
|
||||||
|
if (
|
||||||
|
response_status in [301, 302, 303, 307, 308]
|
||||||
|
and not location.is_empty()
|
||||||
|
and redirects_left > 0
|
||||||
|
):
|
||||||
|
var target := resolve_url(url, location)
|
||||||
|
if not target.is_empty():
|
||||||
|
var next_headers := headers
|
||||||
|
var target_parsed := parse_url(target)
|
||||||
|
if str(target_parsed.get("host", "")) != str(parsed["host"]):
|
||||||
|
next_headers = _without_sensitive_headers(headers)
|
||||||
|
var next_method := method
|
||||||
|
var next_body := body
|
||||||
|
if response_status == 303:
|
||||||
|
next_method = HTTPClient.METHOD_GET
|
||||||
|
next_body = PackedByteArray()
|
||||||
|
return request(
|
||||||
|
next_method,
|
||||||
|
target,
|
||||||
|
next_headers,
|
||||||
|
next_body,
|
||||||
|
timeout_msec,
|
||||||
|
redirects_left - 1
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": response_status,
|
||||||
|
"headers": response_headers,
|
||||||
|
"body": payload,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func _wait_connected(client: HTTPClient, deadline: int) -> bool:
|
||||||
|
while true:
|
||||||
|
match client.get_status():
|
||||||
|
HTTPClient.STATUS_RESOLVING, HTTPClient.STATUS_CONNECTING:
|
||||||
|
if Time.get_ticks_msec() > deadline:
|
||||||
|
last_error = "Zeitüberschreitung beim Verbindungsaufbau"
|
||||||
|
return false
|
||||||
|
client.poll()
|
||||||
|
OS.delay_msec(POLL_DELAY_MSEC)
|
||||||
|
HTTPClient.STATUS_CONNECTED:
|
||||||
|
return true
|
||||||
|
HTTPClient.STATUS_CANT_RESOLVE:
|
||||||
|
last_error = "Hostname konnte nicht aufgelöst werden"
|
||||||
|
return false
|
||||||
|
HTTPClient.STATUS_CONNECTION_ERROR:
|
||||||
|
last_error = "Netzwerkfehler beim Verbindungsaufbau"
|
||||||
|
return false
|
||||||
|
HTTPClient.STATUS_TLS_HANDSHAKE_ERROR:
|
||||||
|
last_error = "TLS-Handshake fehlgeschlagen"
|
||||||
|
return false
|
||||||
|
_:
|
||||||
|
last_error = _status_error(client.get_status())
|
||||||
|
return false
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
|
static func _status_error(status: int) -> String:
|
||||||
|
match status:
|
||||||
|
HTTPClient.STATUS_CANT_RESOLVE:
|
||||||
|
return "Hostname konnte nicht aufgelöst werden"
|
||||||
|
HTTPClient.STATUS_CONNECTION_ERROR:
|
||||||
|
return "Netzwerkverbindung fehlgeschlagen"
|
||||||
|
HTTPClient.STATUS_TLS_HANDSHAKE_ERROR:
|
||||||
|
return "TLS-Verbindung fehlgeschlagen"
|
||||||
|
HTTPClient.STATUS_DISCONNECTED:
|
||||||
|
return "Server hat die Verbindung getrennt"
|
||||||
|
_:
|
||||||
|
return "Unerwarteter Netzwerkstatus (%d)" % status
|
||||||
|
|
||||||
|
|
||||||
|
static func parse_url(url: String) -> Dictionary:
|
||||||
|
var scheme := "https"
|
||||||
|
var rest := url.strip_edges()
|
||||||
|
var scheme_end := rest.find("://")
|
||||||
|
if scheme_end >= 0:
|
||||||
|
scheme = rest.substr(0, scheme_end).to_lower()
|
||||||
|
rest = rest.substr(scheme_end + 3)
|
||||||
|
|
||||||
|
var path_start := rest.find("/")
|
||||||
|
var host_port := rest
|
||||||
|
var path := "/"
|
||||||
|
if path_start >= 0:
|
||||||
|
host_port = rest.substr(0, path_start)
|
||||||
|
path = rest.substr(path_start)
|
||||||
|
if host_port.is_empty():
|
||||||
|
return {}
|
||||||
|
|
||||||
|
var host := host_port
|
||||||
|
var port := 443 if scheme == "https" else 80
|
||||||
|
var colon := host_port.rfind(":")
|
||||||
|
if colon >= 0 and not host_port.substr(colon + 1).is_empty():
|
||||||
|
var port_text := host_port.substr(colon + 1)
|
||||||
|
if port_text.is_valid_int():
|
||||||
|
port = int(port_text)
|
||||||
|
host = host_port.substr(0, colon)
|
||||||
|
if host.is_empty():
|
||||||
|
return {}
|
||||||
|
if scheme != "http" and scheme != "https":
|
||||||
|
return {}
|
||||||
|
return {"scheme": scheme, "host": host, "port": port, "path": path}
|
||||||
|
|
||||||
|
|
||||||
|
static func form_encode(values: Dictionary) -> String:
|
||||||
|
var parts := PackedStringArray()
|
||||||
|
for key: String in values.keys():
|
||||||
|
parts.append(
|
||||||
|
str(key).uri_encode() + "=" + str(values[key]).uri_encode()
|
||||||
|
)
|
||||||
|
return "&".join(parts)
|
||||||
|
|
||||||
|
|
||||||
|
static func json_parse(body: PackedByteArray) -> Variant:
|
||||||
|
if body.is_empty():
|
||||||
|
return {}
|
||||||
|
var parser := JSON.new()
|
||||||
|
if parser.parse(body.get_string_from_utf8()) != OK:
|
||||||
|
return null
|
||||||
|
return parser.data
|
||||||
|
|
||||||
|
|
||||||
|
static func json_stringify(value: Variant) -> String:
|
||||||
|
return JSON.stringify(value, "", false)
|
||||||
|
|
||||||
|
|
||||||
|
## JSON with all non-ASCII characters escaped. Used for the Dropbox
|
||||||
|
## `Dropbox-API-Arg` header, which must stay ASCII even for umlauts.
|
||||||
|
static func json_stringify_ascii(value: Variant) -> String:
|
||||||
|
var text := json_stringify(value)
|
||||||
|
var out := ""
|
||||||
|
for index: int in range(text.length()):
|
||||||
|
var code := text.unicode_at(index)
|
||||||
|
if code < 128:
|
||||||
|
out += text.substr(index, 1)
|
||||||
|
elif code <= 0xFFFF:
|
||||||
|
out += "\\u%04x" % code
|
||||||
|
else:
|
||||||
|
var offset := code - 0x10000
|
||||||
|
out += "\\u%04x\\u%04x" % [
|
||||||
|
0xD800 + (offset >> 10),
|
||||||
|
0xDC00 + (offset & 0x3FF),
|
||||||
|
]
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
static func resolve_url(base_url: String, location: String) -> String:
|
||||||
|
var target := location.strip_edges()
|
||||||
|
if target.is_empty():
|
||||||
|
return ""
|
||||||
|
if target.begins_with("http://") or target.begins_with("https://"):
|
||||||
|
return target
|
||||||
|
var base := parse_url(base_url)
|
||||||
|
if base.is_empty():
|
||||||
|
return ""
|
||||||
|
var scheme := str(base["scheme"])
|
||||||
|
var host := str(base["host"])
|
||||||
|
var port := int(base["port"])
|
||||||
|
var authority := "%s://%s:%d" % [scheme, host, port]
|
||||||
|
if target.begins_with("//"):
|
||||||
|
return scheme + ":" + target
|
||||||
|
if target.begins_with("/"):
|
||||||
|
return authority + target
|
||||||
|
var path := str(base["path"])
|
||||||
|
var slash := path.rfind("/")
|
||||||
|
var directory := path.substr(0, slash + 1) if slash >= 0 else "/"
|
||||||
|
return authority + directory + target
|
||||||
|
|
||||||
|
|
||||||
|
static func _without_sensitive_headers(headers: PackedStringArray) -> PackedStringArray:
|
||||||
|
var result := PackedStringArray()
|
||||||
|
for value: String in headers:
|
||||||
|
var lower := value.to_lower()
|
||||||
|
if lower.begins_with("authorization:") or lower.begins_with("cookie:"):
|
||||||
|
continue
|
||||||
|
result.append(value)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
static func header(headers: Dictionary, name: String) -> String:
|
||||||
|
for key: String in headers.keys():
|
||||||
|
if key.to_lower() == name.to_lower():
|
||||||
|
return str(headers[key])
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
static func error_text(data: Variant, response: Dictionary = {}) -> String:
|
||||||
|
if data is Dictionary:
|
||||||
|
var dict: Dictionary = data
|
||||||
|
if dict.has("error_description"):
|
||||||
|
return str(dict["error_description"])
|
||||||
|
if dict.has("error_summary"):
|
||||||
|
return str(dict["error_summary"])
|
||||||
|
var error: Variant = dict.get("error", null)
|
||||||
|
if error is Dictionary:
|
||||||
|
if error.has("message"):
|
||||||
|
return str(error["message"])
|
||||||
|
if error.has("summary"):
|
||||||
|
return str(error["summary"])
|
||||||
|
if error.has(".tag"):
|
||||||
|
return str(error[".tag"])
|
||||||
|
for key: String in error.keys():
|
||||||
|
if key != ".tag" and error[key] is Dictionary:
|
||||||
|
var nested: Dictionary = error[key]
|
||||||
|
if nested.has(".tag"):
|
||||||
|
return "%s: %s" % [key, nested[".tag"]]
|
||||||
|
return str(error)
|
||||||
|
if error is String and not error.is_empty():
|
||||||
|
return error
|
||||||
|
if response.has("body"):
|
||||||
|
var text := (response["body"] as PackedByteArray).get_string_from_utf8()
|
||||||
|
if not text.strip_edges().is_empty():
|
||||||
|
return text.strip_edges().substr(0, 300)
|
||||||
|
return "HTTP-Fehler"
|
||||||
1
rinkplanner/src/core/sync/cloud_http.gd.uid
Normal file
1
rinkplanner/src/core/sync/cloud_http.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://buoubgak6d4pf
|
||||||
218
rinkplanner/src/core/sync/cloud_oauth_job.gd
Normal file
218
rinkplanner/src/core/sync/cloud_oauth_job.gd
Normal file
|
|
@ -0,0 +1,218 @@
|
||||||
|
class_name CloudOAuthJob
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
## Runs one OAuth authorisation on a worker thread. The controller polls the
|
||||||
|
## public fields from `_process` and keeps the UI responsive. No scene-tree
|
||||||
|
## access happens here.
|
||||||
|
|
||||||
|
const GOOGLE_DEVICE_URL := "https://oauth2.googleapis.com/device/code"
|
||||||
|
const GOOGLE_SCOPES := "openid email https://www.googleapis.com/auth/drive.file"
|
||||||
|
const DROPBOX_AUTHORIZE_URL := "https://www.dropbox.com/oauth2/authorize"
|
||||||
|
const DROPBOX_ACCOUNT_URL := "https://api.dropboxapi.com/2/users/get_current_account"
|
||||||
|
|
||||||
|
var provider: String = ""
|
||||||
|
var status: String = ""
|
||||||
|
var user_code: String = ""
|
||||||
|
var verification_url: String = ""
|
||||||
|
var error: String = ""
|
||||||
|
var done: bool = false
|
||||||
|
var cancelled: bool = false
|
||||||
|
var result: Dictionary = {}
|
||||||
|
|
||||||
|
|
||||||
|
func run_google_device(client_id: String, client_secret: String) -> void:
|
||||||
|
provider = "google_drive"
|
||||||
|
status = "Fordere Anmeldecode an …"
|
||||||
|
var http := CloudHttp.new()
|
||||||
|
var response := http.request(
|
||||||
|
HTTPClient.METHOD_POST,
|
||||||
|
GOOGLE_DEVICE_URL,
|
||||||
|
PackedStringArray(["Content-Type: application/x-www-form-urlencoded"]),
|
||||||
|
CloudHttp.form_encode({
|
||||||
|
"client_id": client_id,
|
||||||
|
"scope": GOOGLE_SCOPES,
|
||||||
|
}).to_utf8_buffer()
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
_fail(http.last_error)
|
||||||
|
return
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
if int(response["status"]) != 200 or not data is Dictionary:
|
||||||
|
_fail("Anmeldecode konnte nicht angefordert werden: " + CloudHttp.error_text(data, response))
|
||||||
|
return
|
||||||
|
|
||||||
|
var payload: Dictionary = data
|
||||||
|
var device_code := str(payload.get("device_code", ""))
|
||||||
|
user_code = str(payload.get("user_code", ""))
|
||||||
|
verification_url = str(payload.get("verification_url", payload.get("verification_uri", "")))
|
||||||
|
if device_code.is_empty() or user_code.is_empty() or verification_url.is_empty():
|
||||||
|
_fail("Der Anbieter hat keinen gültigen Anmeldecode geliefert.")
|
||||||
|
return
|
||||||
|
|
||||||
|
status = "Warte auf Bestätigung im Browser …"
|
||||||
|
var interval := maxi(5, int(payload.get("interval", 5)))
|
||||||
|
var deadline := Time.get_ticks_msec() + maxi(60, int(payload.get("expires_in", 600))) * 1000
|
||||||
|
var token_url := CloudAuth.GOOGLE_TOKEN_URL
|
||||||
|
|
||||||
|
while Time.get_ticks_msec() < deadline:
|
||||||
|
if cancelled:
|
||||||
|
_fail("Anmeldung abgebrochen.")
|
||||||
|
return
|
||||||
|
OS.delay_msec(interval * 1000)
|
||||||
|
if cancelled:
|
||||||
|
_fail("Anmeldung abgebrochen.")
|
||||||
|
return
|
||||||
|
var token_response := http.request(
|
||||||
|
HTTPClient.METHOD_POST,
|
||||||
|
token_url,
|
||||||
|
PackedStringArray(["Content-Type: application/x-www-form-urlencoded"]),
|
||||||
|
CloudHttp.form_encode({
|
||||||
|
"client_id": client_id,
|
||||||
|
"client_secret": client_secret,
|
||||||
|
"device_code": device_code,
|
||||||
|
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
|
||||||
|
}).to_utf8_buffer()
|
||||||
|
)
|
||||||
|
if token_response.is_empty():
|
||||||
|
_fail(http.last_error)
|
||||||
|
return
|
||||||
|
var token_data: Variant = CloudHttp.json_parse(token_response["body"])
|
||||||
|
if int(token_response["status"]) == 200 and token_data is Dictionary:
|
||||||
|
var tokens := CloudAuth.tokens_from_response(token_data)
|
||||||
|
if str(tokens.get("refresh_token", "")).is_empty():
|
||||||
|
_fail(
|
||||||
|
"Google hat keinen Refresh-Token geliefert. Bitte den "
|
||||||
|
+ "App-Zugriff in den Google-Kontoeinstellungen entfernen "
|
||||||
|
+ "und erneut verbinden."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
result = tokens
|
||||||
|
status = "Verbunden."
|
||||||
|
done = true
|
||||||
|
return
|
||||||
|
var token_error := _oauth_error(token_data)
|
||||||
|
if token_error == "authorization_pending":
|
||||||
|
continue
|
||||||
|
if token_error == "slow_down":
|
||||||
|
interval += 5
|
||||||
|
continue
|
||||||
|
if token_error == "access_denied":
|
||||||
|
_fail("Die Anmeldung wurde im Browser abgelehnt.")
|
||||||
|
return
|
||||||
|
if token_error == "expired_token":
|
||||||
|
_fail("Der Anmeldecode ist abgelaufen. Bitte erneut verbinden.")
|
||||||
|
return
|
||||||
|
_fail("Google-Anmeldung fehlgeschlagen: " + CloudHttp.error_text(token_data, token_response))
|
||||||
|
return
|
||||||
|
|
||||||
|
_fail("Zeitüberschreitung bei der Google-Anmeldung. Bitte erneut verbinden.")
|
||||||
|
|
||||||
|
|
||||||
|
func run_dropbox_exchange(
|
||||||
|
app_key: String,
|
||||||
|
app_secret: String,
|
||||||
|
code_verifier: String,
|
||||||
|
code: String
|
||||||
|
) -> void:
|
||||||
|
provider = "dropbox"
|
||||||
|
status = "Tausche Anmeldecode …"
|
||||||
|
var http := CloudHttp.new()
|
||||||
|
var params := {
|
||||||
|
"code": code.strip_edges(),
|
||||||
|
"grant_type": "authorization_code",
|
||||||
|
"client_id": app_key,
|
||||||
|
"code_verifier": code_verifier,
|
||||||
|
}
|
||||||
|
if not app_secret.is_empty():
|
||||||
|
params["client_secret"] = app_secret
|
||||||
|
var response := http.request(
|
||||||
|
HTTPClient.METHOD_POST,
|
||||||
|
CloudAuth.DROPBOX_TOKEN_URL,
|
||||||
|
PackedStringArray(["Content-Type: application/x-www-form-urlencoded"]),
|
||||||
|
CloudHttp.form_encode(params).to_utf8_buffer()
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
_fail(http.last_error)
|
||||||
|
return
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
if int(response["status"]) != 200 or not data is Dictionary:
|
||||||
|
_fail("Dropbox-Anmeldung fehlgeschlagen: " + CloudHttp.error_text(data, response))
|
||||||
|
return
|
||||||
|
var tokens := CloudAuth.tokens_from_response(data)
|
||||||
|
if str(tokens.get("refresh_token", "")).is_empty():
|
||||||
|
_fail(
|
||||||
|
"Dropbox hat keinen Refresh-Token geliefert. Bitte den App-Zugriff "
|
||||||
|
+ "in den Dropbox-Einstellungen entfernen und erneut verbinden."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
tokens["account"] = _dropbox_account(http, str(tokens.get("access_token", "")))
|
||||||
|
result = tokens
|
||||||
|
status = "Verbunden."
|
||||||
|
done = true
|
||||||
|
|
||||||
|
|
||||||
|
func _dropbox_account(http: CloudHttp, access_token: String) -> String:
|
||||||
|
if access_token.is_empty():
|
||||||
|
return ""
|
||||||
|
var response := http.request(
|
||||||
|
HTTPClient.METHOD_POST,
|
||||||
|
DROPBOX_ACCOUNT_URL,
|
||||||
|
PackedStringArray([
|
||||||
|
"Authorization: Bearer " + access_token,
|
||||||
|
"Content-Type: application/json",
|
||||||
|
]),
|
||||||
|
PackedByteArray()
|
||||||
|
)
|
||||||
|
if response.is_empty() or int(response["status"]) != 200:
|
||||||
|
return ""
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
if not data is Dictionary:
|
||||||
|
return ""
|
||||||
|
var account: Dictionary = data
|
||||||
|
var email := str(account.get("email", ""))
|
||||||
|
if not email.is_empty():
|
||||||
|
return email
|
||||||
|
var name: Variant = account.get("name", {})
|
||||||
|
if name is Dictionary:
|
||||||
|
return str((name as Dictionary).get("display_name", ""))
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func _oauth_error(data: Variant) -> String:
|
||||||
|
if data is Dictionary:
|
||||||
|
return str((data as Dictionary).get("error", ""))
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func _fail(message: String) -> void:
|
||||||
|
error = message
|
||||||
|
status = message
|
||||||
|
done = true
|
||||||
|
|
||||||
|
|
||||||
|
static func new_verifier() -> String:
|
||||||
|
var bytes := Crypto.new().generate_random_bytes(32)
|
||||||
|
return base64url(bytes)
|
||||||
|
|
||||||
|
|
||||||
|
static func pkce_challenge(verifier: String) -> String:
|
||||||
|
var context := HashingContext.new()
|
||||||
|
context.start(HashingContext.HASH_SHA256)
|
||||||
|
context.update(verifier.to_utf8_buffer())
|
||||||
|
return base64url(context.finish())
|
||||||
|
|
||||||
|
|
||||||
|
static func base64url(bytes: PackedByteArray) -> String:
|
||||||
|
var encoded := Marshalls.raw_to_base64(bytes)
|
||||||
|
encoded = encoded.replace("+", "-").replace("/", "_")
|
||||||
|
return encoded.rstrip("=")
|
||||||
|
|
||||||
|
|
||||||
|
static func dropbox_authorize_url(app_key: String, verifier: String) -> String:
|
||||||
|
return DROPBOX_AUTHORIZE_URL + "?" + CloudHttp.form_encode({
|
||||||
|
"client_id": app_key,
|
||||||
|
"response_type": "code",
|
||||||
|
"token_access_type": "offline",
|
||||||
|
"code_challenge": pkce_challenge(verifier),
|
||||||
|
"code_challenge_method": "S256",
|
||||||
|
})
|
||||||
1
rinkplanner/src/core/sync/cloud_oauth_job.gd.uid
Normal file
1
rinkplanner/src/core/sync/cloud_oauth_job.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://b33i7cyu0wjtf
|
||||||
279
rinkplanner/src/core/sync/dropbox_store.gd
Normal file
279
rinkplanner/src/core/sync/dropbox_store.gd
Normal file
|
|
@ -0,0 +1,279 @@
|
||||||
|
class_name DropboxStore
|
||||||
|
extends RemoteStore
|
||||||
|
|
||||||
|
## Dropbox backend for the routine sync.
|
||||||
|
##
|
||||||
|
## Uses a scoped "App folder" app with offline access (refresh token). All
|
||||||
|
## paths are relative to the app folder; Rinkplanner never sees the rest of the
|
||||||
|
## user's Dropbox. Files are uploaded with `files/upload` (mode overwrite) and
|
||||||
|
## downloaded from `content.dropboxapi.com` – both are single atomic requests.
|
||||||
|
|
||||||
|
const API_URL := "https://api.dropboxapi.com/2"
|
||||||
|
const CONTENT_URL := "https://content.dropboxapi.com/2"
|
||||||
|
const LIST_PAGE_LIMIT := 2000
|
||||||
|
|
||||||
|
var _settings: Dictionary
|
||||||
|
var _app: Dictionary
|
||||||
|
var _auth: CloudAuth
|
||||||
|
var _http := CloudHttp.new()
|
||||||
|
var _directory := ""
|
||||||
|
var _folder := ""
|
||||||
|
var _last_status := 0
|
||||||
|
|
||||||
|
|
||||||
|
func _init(settings: Dictionary, app: Dictionary) -> void:
|
||||||
|
_settings = settings.duplicate(true)
|
||||||
|
_app = app.duplicate(true)
|
||||||
|
_directory = str(_settings.get("directory", "")).strip_edges().trim_prefix("/").trim_suffix("/")
|
||||||
|
_folder = "" if _directory.is_empty() else "/" + _directory
|
||||||
|
var tokens := _provider_tokens()
|
||||||
|
_auth = CloudAuth.new()
|
||||||
|
_auth.configure(
|
||||||
|
"dropbox",
|
||||||
|
str(_app.get("dropbox_app_key", "")),
|
||||||
|
str(_app.get("dropbox_app_secret", "")),
|
||||||
|
tokens
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func open() -> String:
|
||||||
|
last_error = ""
|
||||||
|
if str(_app.get("dropbox_app_key", "")).is_empty():
|
||||||
|
return SyncAppConfig.missing_hint("dropbox")
|
||||||
|
if not _directory.is_empty() and _directory.contains("/"):
|
||||||
|
return "Der Cloud-Ordner darf keine Unterordner enthalten."
|
||||||
|
last_error = _auth.ensure_access_token()
|
||||||
|
if not last_error.is_empty():
|
||||||
|
return last_error
|
||||||
|
return _ensure_folder()
|
||||||
|
|
||||||
|
|
||||||
|
func list_files() -> Array[Dictionary]:
|
||||||
|
var files: Array[Dictionary] = []
|
||||||
|
var data := _post_json("files/list_folder", {
|
||||||
|
"path": _folder,
|
||||||
|
"recursive": false,
|
||||||
|
"include_deleted": false,
|
||||||
|
"include_non_downloadable_files": false,
|
||||||
|
"limit": LIST_PAGE_LIMIT,
|
||||||
|
})
|
||||||
|
if _last_status != 200:
|
||||||
|
return files
|
||||||
|
|
||||||
|
while true:
|
||||||
|
var entries: Variant = data.get("entries", [])
|
||||||
|
if entries is Array:
|
||||||
|
for raw_entry: Variant in entries:
|
||||||
|
if not raw_entry is Dictionary:
|
||||||
|
continue
|
||||||
|
var entry: Dictionary = raw_entry
|
||||||
|
if str(entry.get(".tag", "")) != "file":
|
||||||
|
continue
|
||||||
|
var name := str(entry.get("name", ""))
|
||||||
|
if name.is_empty():
|
||||||
|
continue
|
||||||
|
files.append({
|
||||||
|
"name": name,
|
||||||
|
"size": int(entry.get("size", -1)),
|
||||||
|
"modify": parse_timestamp(str(entry.get("server_modified", ""))),
|
||||||
|
})
|
||||||
|
if not bool(data.get("has_more", false)):
|
||||||
|
break
|
||||||
|
data = _post_json("files/list_folder/continue", {
|
||||||
|
"cursor": str(data.get("cursor", "")),
|
||||||
|
})
|
||||||
|
if _last_status != 200:
|
||||||
|
break
|
||||||
|
return files
|
||||||
|
|
||||||
|
|
||||||
|
func download(remote_name: String, local_path: String) -> String:
|
||||||
|
var response := _content("files/download", {"path": _path(remote_name)})
|
||||||
|
if _last_status != 200:
|
||||||
|
return last_error
|
||||||
|
var payload: PackedByteArray = response.get("body", PackedByteArray())
|
||||||
|
var metadata_text := CloudHttp.header(response.get("headers", {}), "dropbox-api-result")
|
||||||
|
if not metadata_text.is_empty():
|
||||||
|
var metadata: Variant = JSON.parse_string(metadata_text)
|
||||||
|
if metadata is Dictionary and metadata.has("size"):
|
||||||
|
var expected := int(metadata["size"])
|
||||||
|
if expected >= 0 and payload.size() != expected:
|
||||||
|
return (
|
||||||
|
"Download unvollständig: %d von %d Bytes"
|
||||||
|
% [payload.size(), expected]
|
||||||
|
)
|
||||||
|
var file := FileAccess.open(local_path, FileAccess.WRITE)
|
||||||
|
if file == null:
|
||||||
|
return "Lokale Datei nicht schreibbar: %s" % local_path
|
||||||
|
file.store_buffer(payload)
|
||||||
|
file.close()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func upload(local_path: String, remote_name: String) -> String:
|
||||||
|
var file := FileAccess.open(local_path, FileAccess.READ)
|
||||||
|
if file == null:
|
||||||
|
return "Lokale Datei nicht lesbar: %s" % local_path
|
||||||
|
var payload := file.get_buffer(file.get_length())
|
||||||
|
file.close()
|
||||||
|
_content("files/upload", {
|
||||||
|
"path": _path(remote_name),
|
||||||
|
"mode": "overwrite",
|
||||||
|
"autorename": false,
|
||||||
|
"mute": true,
|
||||||
|
}, payload)
|
||||||
|
if _last_status != 200:
|
||||||
|
return last_error
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func delete_file(remote_name: String) -> String:
|
||||||
|
_post_json("files/delete_v2", {"path": _path(remote_name)})
|
||||||
|
if _last_status == 200:
|
||||||
|
return ""
|
||||||
|
if _last_status == 409 and last_error.contains("not_found"):
|
||||||
|
return ""
|
||||||
|
return last_error if not last_error.is_empty() else "Löschen fehlgeschlagen."
|
||||||
|
|
||||||
|
|
||||||
|
func rename(from_name: String, to_name: String) -> String:
|
||||||
|
_post_json("files/move_v2", {
|
||||||
|
"from_path": _path(from_name),
|
||||||
|
"to_path": _path(to_name),
|
||||||
|
"autorename": false,
|
||||||
|
})
|
||||||
|
if _last_status == 200:
|
||||||
|
return ""
|
||||||
|
return last_error if not last_error.is_empty() else "Umbenennen fehlgeschlagen."
|
||||||
|
|
||||||
|
|
||||||
|
func close() -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func _ensure_folder() -> String:
|
||||||
|
if _folder.is_empty():
|
||||||
|
return ""
|
||||||
|
_post_json("files/get_metadata", {"path": _folder})
|
||||||
|
if _last_status == 200:
|
||||||
|
return ""
|
||||||
|
if _last_status != 409:
|
||||||
|
return last_error if not last_error.is_empty() else "Cloud-Ordner nicht erreichbar."
|
||||||
|
_post_json("files/create_folder_v2", {"path": _folder, "autorename": false})
|
||||||
|
if _last_status == 200 or _last_status == 409:
|
||||||
|
return ""
|
||||||
|
return last_error if not last_error.is_empty() else "Cloud-Ordner konnte nicht angelegt werden."
|
||||||
|
|
||||||
|
|
||||||
|
func _path(name: String) -> String:
|
||||||
|
return remote_path(_folder, name)
|
||||||
|
|
||||||
|
|
||||||
|
func _provider_tokens() -> Dictionary:
|
||||||
|
var all_tokens: Variant = _settings.get("tokens", {})
|
||||||
|
if all_tokens is Dictionary:
|
||||||
|
var entry: Variant = (all_tokens as Dictionary).get("dropbox", {})
|
||||||
|
if entry is Dictionary:
|
||||||
|
return (entry as Dictionary).duplicate(true)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
func _headers() -> PackedStringArray:
|
||||||
|
return PackedStringArray([
|
||||||
|
"Authorization: Bearer " + _auth.access_token,
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
func _post_json(endpoint: String, payload: Dictionary) -> Dictionary:
|
||||||
|
var body := CloudHttp.json_stringify(payload).to_utf8_buffer()
|
||||||
|
var headers := _headers()
|
||||||
|
headers.append("Content-Type: application/json")
|
||||||
|
for attempt: int in range(2):
|
||||||
|
var response := _http.request(
|
||||||
|
HTTPClient.METHOD_POST,
|
||||||
|
API_URL + "/" + endpoint,
|
||||||
|
headers,
|
||||||
|
body
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
_last_status = 0
|
||||||
|
last_error = _http.last_error
|
||||||
|
return {}
|
||||||
|
_last_status = int(response["status"])
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
if _last_status == 401 and attempt == 0:
|
||||||
|
var refresh_error := _refresh_token()
|
||||||
|
if not refresh_error.is_empty():
|
||||||
|
last_error = refresh_error
|
||||||
|
return {}
|
||||||
|
continue
|
||||||
|
if _last_status >= 200 and _last_status < 300:
|
||||||
|
last_error = ""
|
||||||
|
return data if data is Dictionary else {}
|
||||||
|
last_error = CloudHttp.error_text(data, response)
|
||||||
|
return {}
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
func _content(endpoint: String, arg: Dictionary, body: PackedByteArray = PackedByteArray()) -> Dictionary:
|
||||||
|
for attempt: int in range(2):
|
||||||
|
var headers := content_headers(_auth.access_token, arg)
|
||||||
|
var response := _http.request(
|
||||||
|
HTTPClient.METHOD_POST,
|
||||||
|
CONTENT_URL + "/" + endpoint,
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
CloudHttp.TRANSFER_TIMEOUT_MSEC
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
_last_status = 0
|
||||||
|
last_error = _http.last_error
|
||||||
|
return {}
|
||||||
|
_last_status = int(response["status"])
|
||||||
|
if _last_status == 401 and attempt == 0:
|
||||||
|
var refresh_error := _refresh_token()
|
||||||
|
if not refresh_error.is_empty():
|
||||||
|
last_error = refresh_error
|
||||||
|
return {}
|
||||||
|
continue
|
||||||
|
if _last_status >= 200 and _last_status < 300:
|
||||||
|
last_error = ""
|
||||||
|
return response
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
last_error = CloudHttp.error_text(data, response)
|
||||||
|
return {}
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
func _refresh_token() -> String:
|
||||||
|
_auth.access_token = ""
|
||||||
|
return _auth.ensure_access_token()
|
||||||
|
|
||||||
|
|
||||||
|
## Content-API headers exactly once. Dropbox rejects duplicate Content-Type
|
||||||
|
## headers, so the auth helper must not add one.
|
||||||
|
static func content_headers(access_token: String, arg: Dictionary) -> PackedStringArray:
|
||||||
|
return PackedStringArray([
|
||||||
|
"Authorization: Bearer " + access_token,
|
||||||
|
"Dropbox-API-Arg: " + CloudHttp.json_stringify_ascii(arg),
|
||||||
|
"Content-Type: application/octet-stream",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
static func remote_path(folder: String, name: String) -> String:
|
||||||
|
var base := folder.strip_edges()
|
||||||
|
if base.is_empty() or base == "/":
|
||||||
|
return "/" + name
|
||||||
|
if not base.begins_with("/"):
|
||||||
|
base = "/" + base
|
||||||
|
return base.trim_suffix("/") + "/" + name
|
||||||
|
|
||||||
|
|
||||||
|
static func parse_timestamp(value: String) -> int:
|
||||||
|
# "2026-11-09T12:34:56Z" or with fractional seconds.
|
||||||
|
var text := value.strip_edges().trim_suffix("Z")
|
||||||
|
if text.contains("."):
|
||||||
|
text = text.split(".", true, 1)[0]
|
||||||
|
if text.length() < 19:
|
||||||
|
return -1
|
||||||
|
return int(Time.get_unix_time_from_datetime_string(text))
|
||||||
1
rinkplanner/src/core/sync/dropbox_store.gd.uid
Normal file
1
rinkplanner/src/core/sync/dropbox_store.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://kjceh3wa2e22
|
||||||
|
|
@ -1,514 +0,0 @@
|
||||||
class_name FtpClient
|
|
||||||
extends RefCounted
|
|
||||||
|
|
||||||
## Minimal blocking FTP/FTPS client for the manual routine sync.
|
|
||||||
##
|
|
||||||
## Runs on a worker thread, so it never touches the scene tree. All methods
|
|
||||||
## return an error string ("" means success); [member last_error] carries the
|
|
||||||
## reason for value-returning helpers.
|
|
||||||
##
|
|
||||||
## Supported: USER/PASS, AUTH TLS + PROT P (explicit FTPS), EPSV/PASV,
|
|
||||||
## MLSD, SIZE, MDTM, RETR, STOR, DELE, MKD, CWD, PWD, RNFR/RNTO.
|
|
||||||
|
|
||||||
enum Encryption {
|
|
||||||
NONE,
|
|
||||||
EXPLICIT_TLS,
|
|
||||||
}
|
|
||||||
|
|
||||||
const DEFAULT_TIMEOUT_MSEC := 15000
|
|
||||||
const TRANSFER_TIMEOUT_MSEC := 120000
|
|
||||||
const POLL_DELAY_MSEC := 5
|
|
||||||
|
|
||||||
var last_error: String = ""
|
|
||||||
|
|
||||||
var _tcp: StreamPeerTCP
|
|
||||||
var _peer: StreamPeer
|
|
||||||
var _host: String = ""
|
|
||||||
var _port: int = 21
|
|
||||||
var _timeout_msec: int = DEFAULT_TIMEOUT_MSEC
|
|
||||||
var _encryption: Encryption = Encryption.NONE
|
|
||||||
var _tls_options: TLSOptions
|
|
||||||
var _buffer: String = ""
|
|
||||||
var _expected_size: int = -1
|
|
||||||
|
|
||||||
|
|
||||||
func connect_to(
|
|
||||||
host: String,
|
|
||||||
port: int = 21,
|
|
||||||
encryption: Encryption = Encryption.NONE,
|
|
||||||
verify_certificate: bool = true
|
|
||||||
) -> String:
|
|
||||||
last_error = ""
|
|
||||||
_host = host
|
|
||||||
_port = port
|
|
||||||
_encryption = encryption
|
|
||||||
_tls_options = (
|
|
||||||
TLSOptions.client()
|
|
||||||
if verify_certificate
|
|
||||||
else TLSOptions.client_unsafe()
|
|
||||||
)
|
|
||||||
|
|
||||||
_tcp = StreamPeerTCP.new()
|
|
||||||
var err := _tcp.connect_to_host(host, port)
|
|
||||||
if err != OK:
|
|
||||||
return "Verbindung zu %s:%d fehlgeschlagen (Fehler %d)" % [host, port, err]
|
|
||||||
|
|
||||||
if not _wait_for_tcp(_tcp, _timeout_msec):
|
|
||||||
close()
|
|
||||||
return "Zeitüberschreitung beim Verbindungsaufbau zu %s:%d" % [host, port]
|
|
||||||
|
|
||||||
_peer = _tcp
|
|
||||||
var reply := _read_reply()
|
|
||||||
if reply.is_empty() or int(reply["code"]) / 100 != 2:
|
|
||||||
close()
|
|
||||||
return "Server hat die Verbindung nicht bestätigt: %s" % _reply_text(reply)
|
|
||||||
|
|
||||||
if encryption == Encryption.EXPLICIT_TLS:
|
|
||||||
reply = _command("AUTH TLS")
|
|
||||||
if reply.get("code", 0) != 234:
|
|
||||||
close()
|
|
||||||
return "Server lehnt FTPS ab: %s" % _reply_text(reply)
|
|
||||||
var tls := StreamPeerTLS.new()
|
|
||||||
var tls_err := tls.connect_to_stream(_tcp, host, _tls_options)
|
|
||||||
if tls_err != OK:
|
|
||||||
close()
|
|
||||||
return "TLS-Handshake konnte nicht gestartet werden (Fehler %d)" % tls_err
|
|
||||||
var deadline := Time.get_ticks_msec() + _timeout_msec
|
|
||||||
while tls.get_status() == StreamPeerTLS.STATUS_HANDSHAKING:
|
|
||||||
if Time.get_ticks_msec() > deadline:
|
|
||||||
close()
|
|
||||||
return "TLS-Handshake: Zeitüberschreitung"
|
|
||||||
tls.poll()
|
|
||||||
OS.delay_msec(POLL_DELAY_MSEC)
|
|
||||||
if tls.get_status() != StreamPeerTLS.STATUS_CONNECTED:
|
|
||||||
var status := tls.get_status()
|
|
||||||
close()
|
|
||||||
return (
|
|
||||||
"TLS-Handshake fehlgeschlagen (Status %d). "
|
|
||||||
+ "Wenn der Server ein ungültiges Zertifikat nutzt, "
|
|
||||||
+ "die Zertifikatsprüfung in den Sync-Einstellungen abschalten."
|
|
||||||
) % status
|
|
||||||
_peer = tls
|
|
||||||
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
func login(user: String, password: String) -> String:
|
|
||||||
var reply := _command("USER " + user)
|
|
||||||
if reply.get("code", 0) == 331:
|
|
||||||
reply = _command("PASS " + password)
|
|
||||||
if reply.get("code", 0) != 230:
|
|
||||||
return "Login fehlgeschlagen: %s" % _reply_text(reply)
|
|
||||||
|
|
||||||
if _encryption == Encryption.EXPLICIT_TLS:
|
|
||||||
reply = _command("PBSZ 0")
|
|
||||||
if reply.get("code", 0) != 200:
|
|
||||||
return "PBSZ fehlgeschlagen: %s" % _reply_text(reply)
|
|
||||||
reply = _command("PROT P")
|
|
||||||
if reply.get("code", 0) != 200:
|
|
||||||
return "PROT P fehlgeschlagen: %s" % _reply_text(reply)
|
|
||||||
|
|
||||||
reply = _command("TYPE I")
|
|
||||||
if reply.get("code", 0) != 200:
|
|
||||||
return "Binärmodus nicht möglich: %s" % _reply_text(reply)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
func pwd() -> String:
|
|
||||||
var reply := _command("PWD")
|
|
||||||
if reply.get("code", 0) != 257:
|
|
||||||
last_error = _reply_text(reply)
|
|
||||||
return ""
|
|
||||||
var text: String = reply.get("text", "")
|
|
||||||
var start := text.find('"')
|
|
||||||
var end := text.find('"', start + 1)
|
|
||||||
if start < 0 or end < 0:
|
|
||||||
return ""
|
|
||||||
return text.substr(start + 1, end - start - 1)
|
|
||||||
|
|
||||||
|
|
||||||
func change_dir(path: String) -> String:
|
|
||||||
var reply := _command("CWD " + path)
|
|
||||||
if reply.get("code", 0) != 250:
|
|
||||||
return "Verzeichniswechsel fehlgeschlagen: %s" % _reply_text(reply)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
func make_dir(path: String) -> String:
|
|
||||||
var reply := _command("MKD " + path)
|
|
||||||
if reply.get("code", 0) in [250, 257]:
|
|
||||||
return ""
|
|
||||||
return "Ordner konnte nicht angelegt werden: %s" % _reply_text(reply)
|
|
||||||
|
|
||||||
|
|
||||||
## Returns [name, size, modify] entries with type "file" only.
|
|
||||||
func list_files() -> Array[Dictionary]:
|
|
||||||
var entries: Array[Dictionary] = []
|
|
||||||
var socket := _open_data_socket()
|
|
||||||
if socket == null:
|
|
||||||
return entries
|
|
||||||
|
|
||||||
var reply := _command("MLSD")
|
|
||||||
if reply.get("code", 0) not in [125, 150]:
|
|
||||||
close_data_connection(socket)
|
|
||||||
last_error = "Verzeichnisliste nicht möglich: %s" % _reply_text(reply)
|
|
||||||
return entries
|
|
||||||
|
|
||||||
var data_peer := _secure_data_peer(socket)
|
|
||||||
if data_peer == null:
|
|
||||||
_read_reply()
|
|
||||||
return entries
|
|
||||||
var payload := _read_all(data_peer, Time.get_ticks_msec() + TRANSFER_TIMEOUT_MSEC)
|
|
||||||
close_data_connection(data_peer)
|
|
||||||
reply = _read_reply()
|
|
||||||
if reply.get("code", 0) != 226:
|
|
||||||
last_error = "Übertragung der Liste unvollständig: %s" % _reply_text(reply)
|
|
||||||
return entries
|
|
||||||
|
|
||||||
for raw_line: String in payload.get_string_from_utf8().split("\n"):
|
|
||||||
var line := raw_line.strip_edges()
|
|
||||||
if line.is_empty() or not line.contains(";"):
|
|
||||||
continue
|
|
||||||
var parts := line.split(" ", false, 1)
|
|
||||||
if parts.size() < 2:
|
|
||||||
continue
|
|
||||||
var facts := parts[0].split(";", false)
|
|
||||||
var name := parts[1]
|
|
||||||
var info: Dictionary = {"name": name, "size": -1, "modify": -1}
|
|
||||||
for fact: String in facts:
|
|
||||||
var pair := fact.split("=", true, 1)
|
|
||||||
if pair.size() != 2:
|
|
||||||
continue
|
|
||||||
match pair[0].to_lower():
|
|
||||||
"type":
|
|
||||||
info["type"] = pair[1].to_lower()
|
|
||||||
"size":
|
|
||||||
info["size"] = int(pair[1])
|
|
||||||
"modify":
|
|
||||||
info["modify"] = parse_mdtm(pair[1])
|
|
||||||
if info.get("type", "") != "file":
|
|
||||||
continue
|
|
||||||
if name in [".", ".."]:
|
|
||||||
continue
|
|
||||||
entries.append(info)
|
|
||||||
return entries
|
|
||||||
|
|
||||||
|
|
||||||
func file_size(name: String) -> int:
|
|
||||||
var reply := _command("SIZE " + name)
|
|
||||||
if reply.get("code", 0) != 213:
|
|
||||||
last_error = _reply_text(reply)
|
|
||||||
return -1
|
|
||||||
var value := str(reply.get("text", "")).strip_edges().split(" ", false, 1)
|
|
||||||
return int(value[-1]) if value.size() > 0 else -1
|
|
||||||
|
|
||||||
|
|
||||||
func download(remote_name: String, local_path: String) -> String:
|
|
||||||
_expected_size = file_size(remote_name)
|
|
||||||
var socket := _open_data_socket()
|
|
||||||
if socket == null:
|
|
||||||
return "Datenverbindung fehlgeschlagen: " + last_error
|
|
||||||
|
|
||||||
var reply := _command("RETR " + remote_name)
|
|
||||||
if reply.get("code", 0) not in [125, 150]:
|
|
||||||
close_data_connection(socket)
|
|
||||||
return "Download abgelehnt: %s" % _reply_text(reply)
|
|
||||||
|
|
||||||
var data_peer := _secure_data_peer(socket)
|
|
||||||
if data_peer == null:
|
|
||||||
_read_reply()
|
|
||||||
return last_error
|
|
||||||
var payload := _read_all(
|
|
||||||
data_peer,
|
|
||||||
Time.get_ticks_msec() + TRANSFER_TIMEOUT_MSEC,
|
|
||||||
_expected_size
|
|
||||||
)
|
|
||||||
close_data_connection(data_peer)
|
|
||||||
reply = _read_reply()
|
|
||||||
if reply.get("code", 0) != 226:
|
|
||||||
return "Download unvollständig: %s" % _reply_text(reply)
|
|
||||||
if _expected_size >= 0 and payload.size() != _expected_size:
|
|
||||||
return (
|
|
||||||
"Download unvollständig: %d von %d Bytes"
|
|
||||||
% [payload.size(), _expected_size]
|
|
||||||
)
|
|
||||||
|
|
||||||
var file := FileAccess.open(local_path, FileAccess.WRITE)
|
|
||||||
if file == null:
|
|
||||||
return "Lokale Datei nicht schreibbar: %s" % local_path
|
|
||||||
file.store_buffer(payload)
|
|
||||||
file.close()
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
func upload(local_path: String, remote_name: String) -> String:
|
|
||||||
var file := FileAccess.open(local_path, FileAccess.READ)
|
|
||||||
if file == null:
|
|
||||||
return "Lokale Datei nicht lesbar: %s" % local_path
|
|
||||||
var payload := file.get_buffer(file.get_length())
|
|
||||||
file.close()
|
|
||||||
|
|
||||||
var socket := _open_data_socket()
|
|
||||||
if socket == null:
|
|
||||||
return "Datenverbindung fehlgeschlagen: " + last_error
|
|
||||||
|
|
||||||
var reply := _command("STOR " + remote_name)
|
|
||||||
if reply.get("code", 0) not in [125, 150]:
|
|
||||||
close_data_connection(socket)
|
|
||||||
return "Upload abgelehnt: %s" % _reply_text(reply)
|
|
||||||
|
|
||||||
var data_peer := _secure_data_peer(socket)
|
|
||||||
if data_peer == null:
|
|
||||||
_read_reply()
|
|
||||||
return last_error
|
|
||||||
var err := data_peer.put_data(payload)
|
|
||||||
close_data_connection(data_peer)
|
|
||||||
if err != OK:
|
|
||||||
return "Upload abgebrochen (Fehler %d)" % err
|
|
||||||
|
|
||||||
reply = _read_reply()
|
|
||||||
if reply.get("code", 0) != 226:
|
|
||||||
return "Upload unvollständig: %s" % _reply_text(reply)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
func delete_file(remote_name: String) -> String:
|
|
||||||
var reply := _command("DELE " + remote_name)
|
|
||||||
if reply.get("code", 0) != 250:
|
|
||||||
return "Löschen abgelehnt: %s" % _reply_text(reply)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
func rename(from_name: String, to_name: String) -> String:
|
|
||||||
var reply := _command("RNFR " + from_name)
|
|
||||||
if reply.get("code", 0) != 350:
|
|
||||||
return "Umbenennen abgelehnt: %s" % _reply_text(reply)
|
|
||||||
reply = _command("RNTO " + to_name)
|
|
||||||
if reply.get("code", 0) != 250:
|
|
||||||
return "Umbenennen fehlgeschlagen: %s" % _reply_text(reply)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
func close() -> void:
|
|
||||||
if _peer is StreamPeerTLS:
|
|
||||||
(_peer as StreamPeerTLS).disconnect_from_stream()
|
|
||||||
_peer = null
|
|
||||||
if _tcp != null:
|
|
||||||
_tcp.disconnect_from_host()
|
|
||||||
_tcp = null
|
|
||||||
_buffer = ""
|
|
||||||
|
|
||||||
|
|
||||||
# --- protocol helpers --------------------------------------------------------
|
|
||||||
|
|
||||||
static func parse_mdtm(value: String) -> int:
|
|
||||||
# YYYYMMDDHHMMSS[.sss], UTC.
|
|
||||||
var digits := value.strip_edges()
|
|
||||||
if digits.contains("."):
|
|
||||||
digits = digits.split(".", true, 1)[0]
|
|
||||||
if digits.length() < 14 or not digits.is_valid_int():
|
|
||||||
return -1
|
|
||||||
var iso := "%s-%s-%sT%s:%s:%s" % [
|
|
||||||
digits.substr(0, 4),
|
|
||||||
digits.substr(4, 2),
|
|
||||||
digits.substr(6, 2),
|
|
||||||
digits.substr(8, 2),
|
|
||||||
digits.substr(10, 2),
|
|
||||||
digits.substr(12, 2),
|
|
||||||
]
|
|
||||||
return int(Time.get_unix_time_from_datetime_string(iso))
|
|
||||||
|
|
||||||
|
|
||||||
static func parse_pasv(reply: String) -> Dictionary:
|
|
||||||
# 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)
|
|
||||||
var start := reply.find("(")
|
|
||||||
var end := reply.find(")")
|
|
||||||
if start < 0 or end <= start:
|
|
||||||
return {}
|
|
||||||
var numbers := reply.substr(start + 1, end - start - 1).split(",", false)
|
|
||||||
if numbers.size() != 6:
|
|
||||||
return {}
|
|
||||||
var host := "%s.%s.%s.%s" % [numbers[0], numbers[1], numbers[2], numbers[3]]
|
|
||||||
var port := int(numbers[4]) * 256 + int(numbers[5])
|
|
||||||
return {"host": host, "port": port}
|
|
||||||
|
|
||||||
|
|
||||||
static func parse_epsv(reply: String) -> int:
|
|
||||||
# 229 Entering Extended Passive Mode (|||port|)
|
|
||||||
var start := reply.find("(")
|
|
||||||
var end := reply.find(")", start + 1)
|
|
||||||
if start < 0 or end <= start:
|
|
||||||
return -1
|
|
||||||
var body := reply.substr(start + 1, end - start - 1)
|
|
||||||
var parts := body.split("|", true)
|
|
||||||
for part: String in parts:
|
|
||||||
if part.is_valid_int():
|
|
||||||
return int(part)
|
|
||||||
return -1
|
|
||||||
|
|
||||||
|
|
||||||
# --- transport ---------------------------------------------------------------
|
|
||||||
|
|
||||||
func _command(command: String) -> Dictionary:
|
|
||||||
if _peer == null:
|
|
||||||
last_error = "Nicht verbunden"
|
|
||||||
return {}
|
|
||||||
var payload := (command + "\r\n").to_utf8_buffer()
|
|
||||||
var err := _peer.put_data(payload)
|
|
||||||
if err != OK:
|
|
||||||
last_error = "Senden fehlgeschlagen (Fehler %d)" % err
|
|
||||||
return {}
|
|
||||||
return _read_reply()
|
|
||||||
|
|
||||||
|
|
||||||
func _read_reply() -> Dictionary:
|
|
||||||
var deadline := Time.get_ticks_msec() + _timeout_msec
|
|
||||||
var lines := PackedStringArray()
|
|
||||||
var code := -1
|
|
||||||
while true:
|
|
||||||
var line := _read_line(deadline)
|
|
||||||
if line.is_empty():
|
|
||||||
last_error = "Zeitüberschreitung beim Warten auf den Server"
|
|
||||||
return {}
|
|
||||||
lines.append(line)
|
|
||||||
if line.length() >= 4 and line[3] == " ":
|
|
||||||
code = int(line.substr(0, 3))
|
|
||||||
break
|
|
||||||
if line.length() == 3:
|
|
||||||
code = int(line)
|
|
||||||
break
|
|
||||||
return {"code": code, "text": "\n".join(lines)}
|
|
||||||
|
|
||||||
|
|
||||||
func _read_line(deadline: int) -> String:
|
|
||||||
while true:
|
|
||||||
var index := _buffer.find("\n")
|
|
||||||
if index >= 0:
|
|
||||||
var line := _buffer.substr(0, index).trim_suffix("\r")
|
|
||||||
_buffer = _buffer.substr(index + 1)
|
|
||||||
return line
|
|
||||||
if Time.get_ticks_msec() > deadline:
|
|
||||||
return ""
|
|
||||||
if _peer is StreamPeerTLS:
|
|
||||||
(_peer as StreamPeerTLS).poll()
|
|
||||||
var available := _peer.get_available_bytes()
|
|
||||||
if available > 0:
|
|
||||||
var chunk := _peer.get_data(available)
|
|
||||||
if chunk[0] == OK:
|
|
||||||
_buffer += (chunk[1] as PackedByteArray).get_string_from_utf8()
|
|
||||||
continue
|
|
||||||
if not _is_connected(_peer):
|
|
||||||
return ""
|
|
||||||
OS.delay_msec(POLL_DELAY_MSEC)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
func _open_data_socket() -> StreamPeerTCP:
|
|
||||||
last_error = ""
|
|
||||||
var reply := _command("EPSV")
|
|
||||||
var host := _host
|
|
||||||
var port := parse_epsv(str(reply.get("text", "")))
|
|
||||||
if reply.get("code", 0) != 229 or port <= 0:
|
|
||||||
reply = _command("PASV")
|
|
||||||
var parsed := parse_pasv(str(reply.get("text", "")))
|
|
||||||
if reply.get("code", 0) != 227 or parsed.is_empty():
|
|
||||||
last_error = "Passiver Modus nicht möglich: %s" % _reply_text(reply)
|
|
||||||
return null
|
|
||||||
host = parsed["host"]
|
|
||||||
port = parsed["port"]
|
|
||||||
|
|
||||||
var tcp := StreamPeerTCP.new()
|
|
||||||
var err := tcp.connect_to_host(host, port)
|
|
||||||
if err != OK:
|
|
||||||
last_error = "Datenverbindung fehlgeschlagen (Fehler %d)" % err
|
|
||||||
return null
|
|
||||||
if not _wait_for_tcp(tcp, _timeout_msec):
|
|
||||||
tcp.disconnect_from_host()
|
|
||||||
last_error = "Zeitüberschreitung bei der Datenverbindung"
|
|
||||||
return null
|
|
||||||
return tcp
|
|
||||||
|
|
||||||
|
|
||||||
## Wraps the data socket in TLS for explicit FTPS. Called after the server
|
|
||||||
## accepted the transfer command, which is when the handshake actually starts.
|
|
||||||
func _secure_data_peer(socket: StreamPeerTCP) -> StreamPeer:
|
|
||||||
if _encryption != Encryption.EXPLICIT_TLS:
|
|
||||||
return socket
|
|
||||||
|
|
||||||
var tls := StreamPeerTLS.new()
|
|
||||||
var err := tls.connect_to_stream(socket, _host, _tls_options)
|
|
||||||
if err != OK:
|
|
||||||
socket.disconnect_from_host()
|
|
||||||
last_error = "TLS der Datenverbindung fehlgeschlagen (Fehler %d)" % err
|
|
||||||
return null
|
|
||||||
|
|
||||||
var deadline := Time.get_ticks_msec() + _timeout_msec
|
|
||||||
while tls.get_status() == StreamPeerTLS.STATUS_HANDSHAKING:
|
|
||||||
if Time.get_ticks_msec() > deadline:
|
|
||||||
tls.disconnect_from_stream()
|
|
||||||
last_error = "TLS-Handshake der Datenverbindung: Zeitüberschreitung"
|
|
||||||
return null
|
|
||||||
tls.poll()
|
|
||||||
OS.delay_msec(POLL_DELAY_MSEC)
|
|
||||||
if tls.get_status() != StreamPeerTLS.STATUS_CONNECTED:
|
|
||||||
tls.disconnect_from_stream()
|
|
||||||
last_error = "TLS-Handshake der Datenverbindung fehlgeschlagen (Status %d)" % tls.get_status()
|
|
||||||
return null
|
|
||||||
return tls
|
|
||||||
|
|
||||||
|
|
||||||
func _read_all(peer: StreamPeer, deadline: int, expected_size: int = -1) -> PackedByteArray:
|
|
||||||
var payload := PackedByteArray()
|
|
||||||
while true:
|
|
||||||
if peer is StreamPeerTLS:
|
|
||||||
(peer as StreamPeerTLS).poll()
|
|
||||||
if _is_connected(peer):
|
|
||||||
var available := peer.get_available_bytes()
|
|
||||||
if available > 0:
|
|
||||||
var chunk := peer.get_data(available)
|
|
||||||
if chunk[0] == OK:
|
|
||||||
payload.append_array(chunk[1])
|
|
||||||
continue
|
|
||||||
if expected_size >= 0:
|
|
||||||
if payload.size() >= expected_size:
|
|
||||||
break
|
|
||||||
if not _is_connected(peer):
|
|
||||||
break
|
|
||||||
elif not _is_connected(peer):
|
|
||||||
break
|
|
||||||
if Time.get_ticks_msec() > deadline:
|
|
||||||
last_error = "Zeitüberschreitung bei der Datenübertragung"
|
|
||||||
break
|
|
||||||
OS.delay_msec(POLL_DELAY_MSEC)
|
|
||||||
return payload
|
|
||||||
|
|
||||||
|
|
||||||
func close_data_connection(peer: StreamPeer) -> void:
|
|
||||||
if peer == null:
|
|
||||||
return
|
|
||||||
if peer is StreamPeerTLS:
|
|
||||||
(peer as StreamPeerTLS).disconnect_from_stream()
|
|
||||||
elif peer is StreamPeerTCP:
|
|
||||||
(peer as StreamPeerTCP).disconnect_from_host()
|
|
||||||
|
|
||||||
|
|
||||||
func _wait_for_tcp(tcp: StreamPeerTCP, timeout_msec: int) -> bool:
|
|
||||||
var deadline := Time.get_ticks_msec() + timeout_msec
|
|
||||||
while tcp.get_status() == StreamPeerTCP.STATUS_CONNECTING:
|
|
||||||
if Time.get_ticks_msec() > deadline:
|
|
||||||
return false
|
|
||||||
tcp.poll()
|
|
||||||
OS.delay_msec(POLL_DELAY_MSEC)
|
|
||||||
return tcp.get_status() == StreamPeerTCP.STATUS_CONNECTED
|
|
||||||
|
|
||||||
|
|
||||||
func _is_connected(peer: StreamPeer) -> bool:
|
|
||||||
if peer is StreamPeerTLS:
|
|
||||||
return (peer as StreamPeerTLS).get_status() == StreamPeerTLS.STATUS_CONNECTED
|
|
||||||
return (peer as StreamPeerTCP).get_status() == StreamPeerTCP.STATUS_CONNECTED
|
|
||||||
|
|
||||||
|
|
||||||
func _reply_text(reply: Dictionary) -> String:
|
|
||||||
if reply.is_empty():
|
|
||||||
return last_error
|
|
||||||
return str(reply.get("text", "")).strip_edges().replace("\n", " ")
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
uid://3n477aydpya3
|
|
||||||
409
rinkplanner/src/core/sync/google_drive_store.gd
Normal file
409
rinkplanner/src/core/sync/google_drive_store.gd
Normal file
|
|
@ -0,0 +1,409 @@
|
||||||
|
class_name GoogleDriveStore
|
||||||
|
extends RemoteStore
|
||||||
|
|
||||||
|
## Google Drive backend for the routine sync.
|
||||||
|
##
|
||||||
|
## The app uses the non-sensitive `drive.file` scope: it can only see and
|
||||||
|
## change files that Rinkplanner itself created. Everything lives in a single
|
||||||
|
## folder ("Rinkplanner" by default) inside the user's own My Drive.
|
||||||
|
|
||||||
|
const API_URL := "https://www.googleapis.com/drive/v3"
|
||||||
|
const UPLOAD_URL := "https://www.googleapis.com/upload/drive/v3"
|
||||||
|
const FOLDER_MIME := "application/vnd.google-apps.folder"
|
||||||
|
const LIST_FIELDS := "nextPageToken,files(id,name,mimeType,modifiedTime,size)"
|
||||||
|
const FILE_FIELDS := "id,name,modifiedTime,size"
|
||||||
|
|
||||||
|
var _settings: Dictionary
|
||||||
|
var _app: Dictionary
|
||||||
|
var _auth: CloudAuth
|
||||||
|
var _http := CloudHttp.new()
|
||||||
|
var _directory := ""
|
||||||
|
var _folder_id := "root"
|
||||||
|
var _files: Dictionary = {}
|
||||||
|
var _last_status := 0
|
||||||
|
var _lookup_error := ""
|
||||||
|
|
||||||
|
|
||||||
|
func _init(settings: Dictionary, app: Dictionary) -> void:
|
||||||
|
_settings = settings.duplicate(true)
|
||||||
|
_app = app.duplicate(true)
|
||||||
|
_directory = str(_settings.get("directory", "")).strip_edges().trim_prefix("/").trim_suffix("/")
|
||||||
|
var tokens := _provider_tokens()
|
||||||
|
_auth = CloudAuth.new()
|
||||||
|
_auth.configure(
|
||||||
|
"google_drive",
|
||||||
|
str(_app.get("google_client_id", "")),
|
||||||
|
str(_app.get("google_client_secret", "")),
|
||||||
|
tokens
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func open() -> String:
|
||||||
|
last_error = ""
|
||||||
|
if str(_app.get("google_client_id", "")).is_empty():
|
||||||
|
return SyncAppConfig.missing_hint("google_drive")
|
||||||
|
if _directory.is_empty():
|
||||||
|
# Never mirror into My Drive root: that would expose unrelated files.
|
||||||
|
_directory = "Rinkplanner"
|
||||||
|
if _directory.contains("/"):
|
||||||
|
return "Der Cloud-Ordner darf keine Unterordner enthalten."
|
||||||
|
last_error = _auth.ensure_access_token()
|
||||||
|
if not last_error.is_empty():
|
||||||
|
return last_error
|
||||||
|
return _ensure_folder()
|
||||||
|
|
||||||
|
|
||||||
|
func list_files() -> Array[Dictionary]:
|
||||||
|
var files: Array[Dictionary] = []
|
||||||
|
_files.clear()
|
||||||
|
var page_token := ""
|
||||||
|
while true:
|
||||||
|
var query := "'%s' in parents and trashed = false" % escape_query(_folder_id)
|
||||||
|
var url := (
|
||||||
|
API_URL
|
||||||
|
+ "/files?q=" + query.uri_encode()
|
||||||
|
+ "&fields=" + LIST_FIELDS.uri_encode()
|
||||||
|
+ "&pageSize=1000"
|
||||||
|
)
|
||||||
|
if not page_token.is_empty():
|
||||||
|
url += "&pageToken=" + page_token.uri_encode()
|
||||||
|
var data := _get_json(url)
|
||||||
|
if _last_status != 200:
|
||||||
|
return files
|
||||||
|
var entries: Variant = data.get("files", [])
|
||||||
|
if entries is Array:
|
||||||
|
for raw_entry: Variant in entries:
|
||||||
|
if not raw_entry is Dictionary:
|
||||||
|
continue
|
||||||
|
var entry: Dictionary = raw_entry
|
||||||
|
if str(entry.get("mimeType", "")) == FOLDER_MIME:
|
||||||
|
continue
|
||||||
|
var name := str(entry.get("name", ""))
|
||||||
|
if name.is_empty():
|
||||||
|
continue
|
||||||
|
var info := {
|
||||||
|
"name": name,
|
||||||
|
"size": _to_int(entry.get("size", -1)),
|
||||||
|
"modify": parse_timestamp(str(entry.get("modifiedTime", ""))),
|
||||||
|
}
|
||||||
|
files.append(info)
|
||||||
|
_files[name] = {
|
||||||
|
"id": str(entry.get("id", "")),
|
||||||
|
"size": info["size"],
|
||||||
|
"modify": info["modify"],
|
||||||
|
}
|
||||||
|
page_token = str(data.get("nextPageToken", ""))
|
||||||
|
if page_token.is_empty():
|
||||||
|
break
|
||||||
|
return files
|
||||||
|
|
||||||
|
|
||||||
|
func download(remote_name: String, local_path: String) -> String:
|
||||||
|
var file_id := _lookup_id(remote_name)
|
||||||
|
if not _lookup_error.is_empty():
|
||||||
|
return _lookup_error
|
||||||
|
if file_id.is_empty():
|
||||||
|
return "Datei nicht in Google Drive gefunden: %s" % remote_name
|
||||||
|
var response := _request(
|
||||||
|
HTTPClient.METHOD_GET,
|
||||||
|
API_URL + "/files/" + file_id.uri_encode() + "?alt=media",
|
||||||
|
PackedStringArray(),
|
||||||
|
PackedByteArray(),
|
||||||
|
CloudHttp.TRANSFER_TIMEOUT_MSEC
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
return _http.last_error
|
||||||
|
_last_status = int(response["status"])
|
||||||
|
if _last_status != 200:
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
last_error = CloudHttp.error_text(data, response)
|
||||||
|
return last_error
|
||||||
|
var payload: PackedByteArray = response["body"]
|
||||||
|
var expected := -1
|
||||||
|
if _files.has(remote_name):
|
||||||
|
expected = int((_files[remote_name] as Dictionary).get("size", -1))
|
||||||
|
if expected >= 0 and payload.size() != expected:
|
||||||
|
return "Download unvollständig: %d von %d Bytes" % [payload.size(), expected]
|
||||||
|
var file := FileAccess.open(local_path, FileAccess.WRITE)
|
||||||
|
if file == null:
|
||||||
|
return "Lokale Datei nicht schreibbar: %s" % local_path
|
||||||
|
file.store_buffer(payload)
|
||||||
|
file.close()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func upload(local_path: String, remote_name: String) -> String:
|
||||||
|
var file := FileAccess.open(local_path, FileAccess.READ)
|
||||||
|
if file == null:
|
||||||
|
return "Lokale Datei nicht lesbar: %s" % local_path
|
||||||
|
var payload := file.get_buffer(file.get_length())
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
var file_id := _lookup_id(remote_name)
|
||||||
|
if not _lookup_error.is_empty():
|
||||||
|
return _lookup_error
|
||||||
|
var metadata := {"name": remote_name}
|
||||||
|
if file_id.is_empty():
|
||||||
|
metadata["parents"] = [_folder_id]
|
||||||
|
var multipart := _multipart_body(metadata, payload)
|
||||||
|
var url := (
|
||||||
|
UPLOAD_URL
|
||||||
|
+ "/files"
|
||||||
|
+ ("" if file_id.is_empty() else "/" + file_id.uri_encode())
|
||||||
|
+ "?uploadType=multipart&fields=" + FILE_FIELDS.uri_encode()
|
||||||
|
)
|
||||||
|
var method := (
|
||||||
|
HTTPClient.METHOD_POST if file_id.is_empty() else HTTPClient.METHOD_PATCH
|
||||||
|
)
|
||||||
|
var response := _request(
|
||||||
|
method,
|
||||||
|
url,
|
||||||
|
PackedStringArray(["Content-Type: " + str(multipart["content_type"])]),
|
||||||
|
multipart["body"],
|
||||||
|
CloudHttp.TRANSFER_TIMEOUT_MSEC
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
return _http.last_error
|
||||||
|
_last_status = int(response["status"])
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
if _last_status < 200 or _last_status >= 300 or not data is Dictionary:
|
||||||
|
last_error = CloudHttp.error_text(data, response)
|
||||||
|
return last_error
|
||||||
|
_cache_file(data)
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func delete_file(remote_name: String) -> String:
|
||||||
|
var file_id := _lookup_id(remote_name)
|
||||||
|
if not _lookup_error.is_empty():
|
||||||
|
return _lookup_error
|
||||||
|
if file_id.is_empty():
|
||||||
|
return ""
|
||||||
|
var response := _request(
|
||||||
|
HTTPClient.METHOD_DELETE,
|
||||||
|
API_URL + "/files/" + file_id.uri_encode(),
|
||||||
|
PackedStringArray(),
|
||||||
|
PackedByteArray()
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
return _http.last_error
|
||||||
|
_last_status = int(response["status"])
|
||||||
|
if _last_status == 200 or _last_status == 204 or _last_status == 404:
|
||||||
|
_files.erase(remote_name)
|
||||||
|
return ""
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
last_error = CloudHttp.error_text(data, response)
|
||||||
|
return last_error
|
||||||
|
|
||||||
|
|
||||||
|
func rename(from_name: String, to_name: String) -> String:
|
||||||
|
var file_id := _lookup_id(from_name)
|
||||||
|
if not _lookup_error.is_empty():
|
||||||
|
return _lookup_error
|
||||||
|
if file_id.is_empty():
|
||||||
|
return "Datei nicht in Google Drive gefunden: %s" % from_name
|
||||||
|
var response := _send_json(
|
||||||
|
HTTPClient.METHOD_PATCH,
|
||||||
|
API_URL + "/files/" + file_id.uri_encode() + "?fields=" + FILE_FIELDS.uri_encode(),
|
||||||
|
{"name": to_name}
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
return _http.last_error
|
||||||
|
_last_status = int(response["status"])
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
if _last_status < 200 or _last_status >= 300 or not data is Dictionary:
|
||||||
|
last_error = CloudHttp.error_text(data, response)
|
||||||
|
return last_error
|
||||||
|
_files.erase(from_name)
|
||||||
|
_cache_file(data)
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func close() -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func _ensure_folder() -> String:
|
||||||
|
var query := (
|
||||||
|
"name = '%s' and mimeType = '%s' and 'root' in parents and trashed = false"
|
||||||
|
% [escape_query(_directory), FOLDER_MIME]
|
||||||
|
)
|
||||||
|
var url := (
|
||||||
|
API_URL
|
||||||
|
+ "/files?q=" + query.uri_encode()
|
||||||
|
+ "&fields=" + "files(id,name)".uri_encode()
|
||||||
|
+ "&pageSize=10"
|
||||||
|
)
|
||||||
|
var data := _get_json(url)
|
||||||
|
if _last_status != 200:
|
||||||
|
return last_error
|
||||||
|
var entries: Variant = data.get("files", [])
|
||||||
|
if entries is Array and not entries.is_empty():
|
||||||
|
_folder_id = str((entries[0] as Dictionary).get("id", "root"))
|
||||||
|
return ""
|
||||||
|
var create := _send_json(HTTPClient.METHOD_POST, API_URL + "/files?fields=" + "id,name".uri_encode(), {
|
||||||
|
"name": _directory,
|
||||||
|
"mimeType": FOLDER_MIME,
|
||||||
|
"parents": ["root"],
|
||||||
|
})
|
||||||
|
if _last_status < 200 or _last_status >= 300:
|
||||||
|
return last_error
|
||||||
|
_folder_id = str(create.get("id", ""))
|
||||||
|
if _folder_id.is_empty():
|
||||||
|
return "Google Drive hat keinen Ordner angelegt."
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
func _lookup_id(name: String) -> String:
|
||||||
|
_lookup_error = ""
|
||||||
|
if _files.has(name):
|
||||||
|
return str((_files[name] as Dictionary).get("id", ""))
|
||||||
|
var query := (
|
||||||
|
"name = '%s' and '%s' in parents and trashed = false"
|
||||||
|
% [escape_query(name), escape_query(_folder_id)]
|
||||||
|
)
|
||||||
|
var url := (
|
||||||
|
API_URL
|
||||||
|
+ "/files?q=" + query.uri_encode()
|
||||||
|
+ "&fields=" + FILE_FIELDS.uri_encode()
|
||||||
|
+ "&pageSize=10"
|
||||||
|
)
|
||||||
|
var data := _get_json(url)
|
||||||
|
if _last_status != 200:
|
||||||
|
_lookup_error = last_error
|
||||||
|
return ""
|
||||||
|
var entries: Variant = data.get("files", [])
|
||||||
|
if not entries is Array or entries.is_empty():
|
||||||
|
return ""
|
||||||
|
var entry: Dictionary = entries[0]
|
||||||
|
_cache_file(entry)
|
||||||
|
return str(entry.get("id", ""))
|
||||||
|
|
||||||
|
|
||||||
|
func _cache_file(data: Dictionary) -> void:
|
||||||
|
var name := str(data.get("name", ""))
|
||||||
|
if name.is_empty():
|
||||||
|
return
|
||||||
|
_files[name] = {
|
||||||
|
"id": str(data.get("id", "")),
|
||||||
|
"size": _to_int(data.get("size", -1)),
|
||||||
|
"modify": parse_timestamp(str(data.get("modifiedTime", ""))),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func _provider_tokens() -> Dictionary:
|
||||||
|
var all_tokens: Variant = _settings.get("tokens", {})
|
||||||
|
if all_tokens is Dictionary:
|
||||||
|
var entry: Variant = (all_tokens as Dictionary).get("google_drive", {})
|
||||||
|
if entry is Dictionary:
|
||||||
|
return (entry as Dictionary).duplicate(true)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
func _request(
|
||||||
|
method: int,
|
||||||
|
url: String,
|
||||||
|
extra_headers: PackedStringArray,
|
||||||
|
body: PackedByteArray,
|
||||||
|
timeout_msec: int = CloudHttp.DEFAULT_TIMEOUT_MSEC
|
||||||
|
) -> Dictionary:
|
||||||
|
var response := _http.request(method, url, _headers(extra_headers), body, timeout_msec)
|
||||||
|
if response.is_empty():
|
||||||
|
return {}
|
||||||
|
if int(response.get("status", 0)) == 401:
|
||||||
|
_auth.access_token = ""
|
||||||
|
var refresh_error := _auth.ensure_access_token()
|
||||||
|
if not refresh_error.is_empty():
|
||||||
|
last_error = refresh_error
|
||||||
|
return {}
|
||||||
|
response = _http.request(method, url, _headers(extra_headers), body, timeout_msec)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
func _headers(extra: PackedStringArray) -> PackedStringArray:
|
||||||
|
var headers := PackedStringArray(extra)
|
||||||
|
headers.append("Authorization: Bearer " + _auth.access_token)
|
||||||
|
return headers
|
||||||
|
|
||||||
|
|
||||||
|
func _get_json(url: String) -> Dictionary:
|
||||||
|
var response := _request(
|
||||||
|
HTTPClient.METHOD_GET,
|
||||||
|
url,
|
||||||
|
PackedStringArray(),
|
||||||
|
PackedByteArray()
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
_last_status = 0
|
||||||
|
last_error = _http.last_error
|
||||||
|
return {}
|
||||||
|
_last_status = int(response["status"])
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
if _last_status < 200 or _last_status >= 300:
|
||||||
|
last_error = CloudHttp.error_text(data, response)
|
||||||
|
return {}
|
||||||
|
last_error = ""
|
||||||
|
return data if data is Dictionary else {}
|
||||||
|
|
||||||
|
|
||||||
|
func _send_json(method: int, url: String, payload: Dictionary) -> Dictionary:
|
||||||
|
var body := CloudHttp.json_stringify(payload).to_utf8_buffer()
|
||||||
|
var response := _request(
|
||||||
|
method,
|
||||||
|
url,
|
||||||
|
PackedStringArray(["Content-Type: application/json; charset=UTF-8"]),
|
||||||
|
body
|
||||||
|
)
|
||||||
|
if response.is_empty():
|
||||||
|
_last_status = 0
|
||||||
|
last_error = _http.last_error
|
||||||
|
return {}
|
||||||
|
_last_status = int(response["status"])
|
||||||
|
var data: Variant = CloudHttp.json_parse(response["body"])
|
||||||
|
if _last_status < 200 or _last_status >= 300:
|
||||||
|
last_error = CloudHttp.error_text(data, response)
|
||||||
|
return {}
|
||||||
|
last_error = ""
|
||||||
|
return data if data is Dictionary else {}
|
||||||
|
|
||||||
|
|
||||||
|
func _multipart_body(metadata: Dictionary, payload: PackedByteArray) -> Dictionary:
|
||||||
|
var boundary := "rinkplanner-" + str(Time.get_ticks_usec())
|
||||||
|
var prefix := (
|
||||||
|
"--%s\r\n"
|
||||||
|
+ "Content-Type: application/json; charset=UTF-8\r\n\r\n"
|
||||||
|
+ "%s\r\n"
|
||||||
|
+ "--%s\r\n"
|
||||||
|
+ "Content-Type: application/octet-stream\r\n\r\n"
|
||||||
|
) % [boundary, CloudHttp.json_stringify(metadata), boundary]
|
||||||
|
var suffix := "\r\n--%s--\r\n" % boundary
|
||||||
|
var body := PackedByteArray()
|
||||||
|
body.append_array(prefix.to_utf8_buffer())
|
||||||
|
body.append_array(payload)
|
||||||
|
body.append_array(suffix.to_utf8_buffer())
|
||||||
|
return {
|
||||||
|
"body": body,
|
||||||
|
"content_type": "multipart/related; boundary=" + boundary,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static func escape_query(value: String) -> String:
|
||||||
|
return value.replace("\\", "\\\\").replace("'", "\\'")
|
||||||
|
|
||||||
|
|
||||||
|
static func parse_timestamp(value: String) -> int:
|
||||||
|
var text := value.strip_edges().trim_suffix("Z")
|
||||||
|
if text.contains("."):
|
||||||
|
text = text.split(".", true, 1)[0]
|
||||||
|
if text.length() < 19:
|
||||||
|
return -1
|
||||||
|
return int(Time.get_unix_time_from_datetime_string(text))
|
||||||
|
|
||||||
|
|
||||||
|
static func _to_int(value: Variant) -> int:
|
||||||
|
if value == null:
|
||||||
|
return -1
|
||||||
|
if value is int or value is float:
|
||||||
|
return int(value)
|
||||||
|
var text := str(value).strip_edges()
|
||||||
|
return int(text) if text.is_valid_int() else -1
|
||||||
1
rinkplanner/src/core/sync/google_drive_store.gd.uid
Normal file
1
rinkplanner/src/core/sync/google_drive_store.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://drj84omv865yc
|
||||||
60
rinkplanner/src/core/sync/remote_store.gd
Normal file
60
rinkplanner/src/core/sync/remote_store.gd
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
class_name RemoteStore
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
## Common interface of the cloud backends. [RoutineSync] only talks to this
|
||||||
|
## class, so the comparison rules stay independent of Dropbox/Google details.
|
||||||
|
|
||||||
|
var last_error: String = ""
|
||||||
|
|
||||||
|
|
||||||
|
static func create(
|
||||||
|
provider: String,
|
||||||
|
settings: Dictionary,
|
||||||
|
app: Dictionary
|
||||||
|
) -> RemoteStore:
|
||||||
|
match provider:
|
||||||
|
"dropbox":
|
||||||
|
return DropboxStore.new(settings, app)
|
||||||
|
"google_drive":
|
||||||
|
return GoogleDriveStore.new(settings, app)
|
||||||
|
return null
|
||||||
|
|
||||||
|
|
||||||
|
static func provider_label(provider: String) -> String:
|
||||||
|
match provider:
|
||||||
|
"dropbox":
|
||||||
|
return "Dropbox"
|
||||||
|
"google_drive":
|
||||||
|
return "Google Drive"
|
||||||
|
return "Cloud"
|
||||||
|
|
||||||
|
|
||||||
|
## Authenticates, resolves the target folder and prepares the backend.
|
||||||
|
func open() -> String:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
## Returns [{name, size, modify}] for all files in the target folder. Folders
|
||||||
|
## and unrelated files are filtered by [RoutineSync].
|
||||||
|
func list_files() -> Array[Dictionary]:
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
func download(_remote_name: String, _local_path: String) -> String:
|
||||||
|
return "Download ist für diesen Anbieter nicht implementiert."
|
||||||
|
|
||||||
|
|
||||||
|
func upload(_local_path: String, _remote_name: String) -> String:
|
||||||
|
return "Upload ist für diesen Anbieter nicht implementiert."
|
||||||
|
|
||||||
|
|
||||||
|
func delete_file(_remote_name: String) -> String:
|
||||||
|
return "Löschen ist für diesen Anbieter nicht implementiert."
|
||||||
|
|
||||||
|
|
||||||
|
func rename(_from_name: String, _to_name: String) -> String:
|
||||||
|
return "Umbenennen ist für diesen Anbieter nicht implementiert."
|
||||||
|
|
||||||
|
|
||||||
|
func close() -> void:
|
||||||
|
pass
|
||||||
1
rinkplanner/src/core/sync/remote_store.gd.uid
Normal file
1
rinkplanner/src/core/sync/remote_store.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cbvjyx473huoq
|
||||||
|
|
@ -1,16 +1,19 @@
|
||||||
class_name RoutineSync
|
class_name RoutineSync
|
||||||
extends RefCounted
|
extends RefCounted
|
||||||
|
|
||||||
## Executes the manual sync between `user://routines` and an FTP directory.
|
## Executes the manual sync between `user://routines` and the user's cloud
|
||||||
## Intended to run on a worker thread: it only reports through [member result],
|
## folder (Google Drive or Dropbox). Intended to run on a worker thread: it only
|
||||||
## [member error] and [member progress], never through signals.
|
## reports through [member result], [member error] and [member progress], never
|
||||||
|
## through signals.
|
||||||
|
##
|
||||||
|
## The cloud account belongs to the user. Rinkplanner never talks to a shared
|
||||||
|
## server and never sees credentials of other users.
|
||||||
|
|
||||||
const LOCAL_DIR := "user://routines"
|
const LOCAL_DIR := "user://routines"
|
||||||
const STATE_PATH := "user://sync_state.cfg"
|
const STATE_PATH := "user://sync_state.cfg"
|
||||||
const TEMP_SUFFIX := ".part"
|
const TEMP_SUFFIX := ".part"
|
||||||
const UPLOAD_SUFFIX := ".uploading"
|
|
||||||
## New routines are JSON; legacy `.tres` files stay in the sync so existing
|
## New routines are JSON; legacy `.tres` files stay in the sync so existing
|
||||||
## installations do not lose their server copies. Audio attachments (the music
|
## installations do not lose their cloud copies. Audio attachments (the music
|
||||||
## of a routine) live in the same folder and are synced like the routine files.
|
## of a routine) live in the same folder and are synced like the routine files.
|
||||||
const SYNC_EXTENSIONS := [
|
const SYNC_EXTENSIONS := [
|
||||||
".json",
|
".json",
|
||||||
|
|
@ -19,10 +22,12 @@ const SYNC_EXTENSIONS := [
|
||||||
".ogg",
|
".ogg",
|
||||||
".wav",
|
".wav",
|
||||||
]
|
]
|
||||||
|
const PROVIDERS := ["dropbox", "google_drive"]
|
||||||
|
|
||||||
var progress: String = ""
|
var progress: String = ""
|
||||||
var error: String = ""
|
var error: String = ""
|
||||||
var result: Dictionary = {}
|
var result: Dictionary = {}
|
||||||
|
var provider: String = ""
|
||||||
|
|
||||||
|
|
||||||
func run(settings: Dictionary) -> void:
|
func run(settings: Dictionary) -> void:
|
||||||
|
|
@ -37,60 +42,48 @@ func run(settings: Dictionary) -> void:
|
||||||
"errors": [],
|
"errors": [],
|
||||||
}
|
}
|
||||||
error = ""
|
error = ""
|
||||||
|
provider = str(settings.get("provider", "")).strip_edges()
|
||||||
|
|
||||||
|
if not PROVIDERS.has(provider):
|
||||||
|
error = "Kein Cloud-Anbieter ausgewählt. Bitte die Sync-Einstellungen öffnen."
|
||||||
|
return
|
||||||
|
|
||||||
var host := str(settings.get("host", "")).strip_edges()
|
|
||||||
var user := str(settings.get("user", "")).strip_edges()
|
|
||||||
var password := str(settings.get("password", ""))
|
|
||||||
var port := int(settings.get("port", 21))
|
|
||||||
var directory := str(settings.get("directory", "")).strip_edges().trim_prefix("/").trim_suffix("/")
|
var directory := str(settings.get("directory", "")).strip_edges().trim_prefix("/").trim_suffix("/")
|
||||||
var encryption := (
|
if directory.contains("/") or directory.contains("\\"):
|
||||||
FtpClient.Encryption.EXPLICIT_TLS
|
error = "Der Cloud-Ordner darf keine Unterordner enthalten."
|
||||||
if bool(settings.get("ftps", true))
|
return
|
||||||
else FtpClient.Encryption.NONE
|
|
||||||
)
|
|
||||||
var verify := bool(settings.get("verify_certificate", true))
|
|
||||||
|
|
||||||
if host.is_empty() or user.is_empty():
|
var tokens := provider_tokens(settings, provider)
|
||||||
error = "Host und Benutzer müssen in den Sync-Einstellungen gesetzt sein."
|
if str(tokens.get("refresh_token", "")).is_empty():
|
||||||
|
error = (
|
||||||
|
"Nicht mit %s verbunden. Bitte in den Sync-Einstellungen das Konto verbinden."
|
||||||
|
% RemoteStore.provider_label(provider)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
var app := SyncAppConfig.load_config()
|
||||||
|
if not SyncAppConfig.is_configured(provider, app):
|
||||||
|
error = SyncAppConfig.missing_hint(provider)
|
||||||
return
|
return
|
||||||
|
|
||||||
_ensure_local_dir()
|
_ensure_local_dir()
|
||||||
var client := FtpClient.new()
|
var store := RemoteStore.create(provider, settings, app)
|
||||||
|
if store == null:
|
||||||
progress = "Verbinde mit %s:%d …" % [host, port]
|
error = "Der Cloud-Anbieter wird von dieser Version nicht unterstützt."
|
||||||
var err := client.connect_to(host, port, encryption, verify)
|
|
||||||
if not err.is_empty():
|
|
||||||
error = err
|
|
||||||
client.close()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
progress = "Anmeldung …"
|
progress = "Verbinde mit %s …" % RemoteStore.provider_label(provider)
|
||||||
err = client.login(user, password)
|
var err := store.open()
|
||||||
if not err.is_empty():
|
if not err.is_empty():
|
||||||
error = err
|
error = err
|
||||||
client.close()
|
store.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
if not directory.is_empty():
|
progress = "Lese Cloud-Ordner …"
|
||||||
err = client.change_dir(directory)
|
var remote := _remote_files(store)
|
||||||
if not err.is_empty():
|
if not store.last_error.is_empty():
|
||||||
progress = "Lege Zielordner an …"
|
error = store.last_error
|
||||||
var mkdir_error := client.make_dir(directory)
|
store.close()
|
||||||
if not mkdir_error.is_empty():
|
|
||||||
error = "%s (%s)" % [mkdir_error, err]
|
|
||||||
client.close()
|
|
||||||
return
|
|
||||||
err = client.change_dir(directory)
|
|
||||||
if not err.is_empty():
|
|
||||||
error = err
|
|
||||||
client.close()
|
|
||||||
return
|
|
||||||
|
|
||||||
progress = "Lese Serververzeichnis …"
|
|
||||||
var remote := _remote_files(client)
|
|
||||||
if not client.last_error.is_empty():
|
|
||||||
error = client.last_error
|
|
||||||
client.close()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var local := local_files()
|
var local := local_files()
|
||||||
|
|
@ -108,27 +101,27 @@ func run(settings: Dictionary) -> void:
|
||||||
progress = "%s: %s" % [name, SyncPlan.action_name(action)]
|
progress = "%s: %s" % [name, SyncPlan.action_name(action)]
|
||||||
match action:
|
match action:
|
||||||
SyncPlan.Action.UPLOAD:
|
SyncPlan.Action.UPLOAD:
|
||||||
var upload_error := _upload(client, name)
|
var upload_error := _upload(store, name)
|
||||||
if upload_error.is_empty():
|
if upload_error.is_empty():
|
||||||
result["uploaded"].append(name)
|
result["uploaded"].append(name)
|
||||||
transferred = true
|
transferred = true
|
||||||
else:
|
else:
|
||||||
result["errors"].append(upload_error)
|
result["errors"].append(upload_error)
|
||||||
SyncPlan.Action.DOWNLOAD:
|
SyncPlan.Action.DOWNLOAD:
|
||||||
var download_error := _download(client, name)
|
var download_error := _download(store, name)
|
||||||
if download_error.is_empty():
|
if download_error.is_empty():
|
||||||
result["downloaded"].append(name)
|
result["downloaded"].append(name)
|
||||||
transferred = true
|
transferred = true
|
||||||
else:
|
else:
|
||||||
result["errors"].append(download_error)
|
result["errors"].append(download_error)
|
||||||
SyncPlan.Action.CONFLICT:
|
SyncPlan.Action.CONFLICT:
|
||||||
var conflict_error := _keep_both(client, name, used_names)
|
var conflict_error := _keep_both(store, name, used_names)
|
||||||
if conflict_error.is_empty():
|
if conflict_error.is_empty():
|
||||||
transferred = true
|
transferred = true
|
||||||
else:
|
else:
|
||||||
result["errors"].append(conflict_error)
|
result["errors"].append(conflict_error)
|
||||||
SyncPlan.Action.TAKE_SERVER:
|
SyncPlan.Action.TAKE_SERVER:
|
||||||
var adopt_error := _take_server(client, name, used_names)
|
var adopt_error := _take_server(store, name, used_names)
|
||||||
if adopt_error.is_empty():
|
if adopt_error.is_empty():
|
||||||
transferred = true
|
transferred = true
|
||||||
else:
|
else:
|
||||||
|
|
@ -138,46 +131,34 @@ func run(settings: Dictionary) -> void:
|
||||||
|
|
||||||
if transferred:
|
if transferred:
|
||||||
progress = "Aktualisiere Sync-Stand …"
|
progress = "Aktualisiere Sync-Stand …"
|
||||||
_save_state(client, state)
|
_save_state(store, state)
|
||||||
|
|
||||||
client.close()
|
store.close()
|
||||||
progress = "Fertig."
|
progress = "Fertig."
|
||||||
|
|
||||||
|
|
||||||
func _upload(client: FtpClient, name: String) -> String:
|
func _upload(store: RemoteStore, name: String) -> String:
|
||||||
var local_path := _local_path(name)
|
var err := store.upload(_local_path(name), name)
|
||||||
var temporary := name + UPLOAD_SUFFIX
|
|
||||||
var err := client.upload(local_path, temporary)
|
|
||||||
if not err.is_empty():
|
|
||||||
return "Upload %s: %s" % [name, err]
|
|
||||||
|
|
||||||
var rename_error := client.rename(temporary, name)
|
|
||||||
if rename_error.is_empty():
|
|
||||||
return ""
|
|
||||||
# Some servers refuse to overwrite on rename: remove the temp file and
|
|
||||||
# upload directly (non-atomic, but the only portable fallback).
|
|
||||||
client.delete_file(temporary)
|
|
||||||
err = client.upload(local_path, name)
|
|
||||||
if not err.is_empty():
|
if not err.is_empty():
|
||||||
return "Upload %s: %s" % [name, err]
|
return "Upload %s: %s" % [name, err]
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
func _download(client: FtpClient, name: String) -> String:
|
func _download(store: RemoteStore, name: String) -> String:
|
||||||
var target := _local_path(name)
|
var target := _local_path(name)
|
||||||
var temporary := target + TEMP_SUFFIX
|
var temporary := target + TEMP_SUFFIX
|
||||||
var err := client.download(name, temporary)
|
var err := store.download(name, temporary)
|
||||||
if not err.is_empty():
|
if not err.is_empty():
|
||||||
return "Download %s: %s" % [name, err]
|
return "Download %s: %s" % [name, err]
|
||||||
return _replace_file(temporary, target)
|
return _replace_file(temporary, target)
|
||||||
|
|
||||||
|
|
||||||
## First sync of a file that exists on both sides (no common state): the
|
## First sync of a file that exists on both sides (no common state): the
|
||||||
## server copy keeps the normal name, the local copy is preserved next to it.
|
## cloud copy keeps the normal name, the local copy is preserved next to it.
|
||||||
func _take_server(client: FtpClient, name: String, used_names: Dictionary) -> String:
|
func _take_server(store: RemoteStore, name: String, used_names: Dictionary) -> String:
|
||||||
var target := _local_path(name)
|
var target := _local_path(name)
|
||||||
var temporary := target + TEMP_SUFFIX
|
var temporary := target + TEMP_SUFFIX
|
||||||
var err := client.download(name, temporary)
|
var err := store.download(name, temporary)
|
||||||
if not err.is_empty():
|
if not err.is_empty():
|
||||||
return "Übernahme %s: %s" % [name, err]
|
return "Übernahme %s: %s" % [name, err]
|
||||||
|
|
||||||
|
|
@ -212,7 +193,7 @@ func _take_server(client: FtpClient, name: String, used_names: Dictionary) -> St
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
func _keep_both(client: FtpClient, name: String, used_names: Dictionary) -> String:
|
func _keep_both(store: RemoteStore, name: String, used_names: Dictionary) -> String:
|
||||||
var stamp := SyncPlan.timestamp_label()
|
var stamp := SyncPlan.timestamp_label()
|
||||||
var conflict_name := SyncPlan.unique_name(
|
var conflict_name := SyncPlan.unique_name(
|
||||||
SyncPlan.conflict_file_name(name, stamp),
|
SyncPlan.conflict_file_name(name, stamp),
|
||||||
|
|
@ -220,7 +201,7 @@ func _keep_both(client: FtpClient, name: String, used_names: Dictionary) -> Stri
|
||||||
)
|
)
|
||||||
var target := _local_path(conflict_name)
|
var target := _local_path(conflict_name)
|
||||||
var temporary := target + TEMP_SUFFIX
|
var temporary := target + TEMP_SUFFIX
|
||||||
var err := client.download(name, temporary)
|
var err := store.download(name, temporary)
|
||||||
if not err.is_empty():
|
if not err.is_empty():
|
||||||
return "Konflikt %s: %s" % [name, err]
|
return "Konflikt %s: %s" % [name, err]
|
||||||
|
|
||||||
|
|
@ -259,9 +240,9 @@ func _replace_file(temporary: String, target: String) -> String:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
func _save_state(client: FtpClient, state: Dictionary) -> void:
|
func _save_state(store: RemoteStore, state: Dictionary) -> void:
|
||||||
# Refresh the server listing once so uploaded files get their new MDTM.
|
# Refresh the cloud listing once so uploaded files get their new timestamp.
|
||||||
var remote_after := _remote_files(client)
|
var remote_after := _remote_files(store)
|
||||||
var local_after := local_files()
|
var local_after := local_files()
|
||||||
var touched: Array = []
|
var touched: Array = []
|
||||||
touched.append_array(result["uploaded"])
|
touched.append_array(result["uploaded"])
|
||||||
|
|
@ -280,6 +261,15 @@ func _save_state(client: FtpClient, state: Dictionary) -> void:
|
||||||
save_state(STATE_PATH, state)
|
save_state(STATE_PATH, state)
|
||||||
|
|
||||||
|
|
||||||
|
static func provider_tokens(settings: Dictionary, provider_name: String) -> Dictionary:
|
||||||
|
var all_tokens: Variant = settings.get("tokens", {})
|
||||||
|
if all_tokens is Dictionary:
|
||||||
|
var entry: Variant = (all_tokens as Dictionary).get(provider_name, {})
|
||||||
|
if entry is Dictionary:
|
||||||
|
return (entry as Dictionary).duplicate(true)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
static func is_synced_file(name: String) -> bool:
|
static func is_synced_file(name: String) -> bool:
|
||||||
var lower := name.to_lower()
|
var lower := name.to_lower()
|
||||||
for extension: String in SYNC_EXTENSIONS:
|
for extension: String in SYNC_EXTENSIONS:
|
||||||
|
|
@ -293,9 +283,9 @@ static func is_routine_file(name: String) -> bool:
|
||||||
return is_synced_file(name)
|
return is_synced_file(name)
|
||||||
|
|
||||||
|
|
||||||
func _remote_files(client: FtpClient) -> Dictionary:
|
func _remote_files(store: RemoteStore) -> Dictionary:
|
||||||
var files: Dictionary = {}
|
var files: Dictionary = {}
|
||||||
for entry: Dictionary in client.list_files():
|
for entry: Dictionary in store.list_files():
|
||||||
var name := str(entry.get("name", ""))
|
var name := str(entry.get("name", ""))
|
||||||
if not is_synced_file(name):
|
if not is_synced_file(name):
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
92
rinkplanner/src/core/sync/sync_app_config.gd
Normal file
92
rinkplanner/src/core/sync/sync_app_config.gd
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
class_name SyncAppConfig
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
## OAuth app credentials of Rinkplanner itself. These are not user secrets:
|
||||||
|
## the client ID / app key identify the installed app, while every user
|
||||||
|
## authorises their own account at runtime. The values are bundled at build
|
||||||
|
## time in `res://sync_apps.cfg` (see docs/cloud-setup.md) and can be
|
||||||
|
## overridden per installation with `user://sync_apps.cfg`.
|
||||||
|
##
|
||||||
|
## `docs/credentials.txt` stays a developer file and is never read by the app.
|
||||||
|
|
||||||
|
const BUNDLED_PATH := "res://sync_apps.cfg"
|
||||||
|
const USER_PATH := "user://sync_apps.cfg"
|
||||||
|
const SECTION := "apps"
|
||||||
|
const KEYS := [
|
||||||
|
"google_client_id",
|
||||||
|
"google_client_secret",
|
||||||
|
"dropbox_app_key",
|
||||||
|
"dropbox_app_secret",
|
||||||
|
]
|
||||||
|
|
||||||
|
const ENV_KEYS := {
|
||||||
|
"google_client_id": "RINKPLANNER_GOOGLE_CLIENT_ID",
|
||||||
|
"google_client_secret": "RINKPLANNER_GOOGLE_CLIENT_SECRET",
|
||||||
|
"dropbox_app_key": "RINKPLANNER_DROPBOX_APP_KEY",
|
||||||
|
"dropbox_app_secret": "RINKPLANNER_DROPBOX_APP_SECRET",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static func load_config() -> Dictionary:
|
||||||
|
var values := _empty()
|
||||||
|
for key: String in KEYS:
|
||||||
|
var env_name := str(ENV_KEYS[key])
|
||||||
|
var env_value := OS.get_environment(env_name).strip_edges()
|
||||||
|
if not env_value.is_empty():
|
||||||
|
values[key] = env_value
|
||||||
|
var bundled := read_file(BUNDLED_PATH)
|
||||||
|
for key: String in KEYS:
|
||||||
|
var value := str(bundled.get(key, ""))
|
||||||
|
if not value.is_empty():
|
||||||
|
values[key] = value
|
||||||
|
var user := read_file(USER_PATH)
|
||||||
|
for key: String in KEYS:
|
||||||
|
var value := str(user.get(key, ""))
|
||||||
|
if not value.is_empty():
|
||||||
|
values[key] = value
|
||||||
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
static func read_file(path: String) -> Dictionary:
|
||||||
|
var values := _empty()
|
||||||
|
if not FileAccess.file_exists(path):
|
||||||
|
return values
|
||||||
|
var config := ConfigFile.new()
|
||||||
|
if config.load(path) != OK:
|
||||||
|
return values
|
||||||
|
for key: String in KEYS:
|
||||||
|
values[key] = str(config.get_value(SECTION, key, "")).strip_edges()
|
||||||
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
static func is_configured(provider: String, app: Dictionary) -> bool:
|
||||||
|
if provider == "google_drive":
|
||||||
|
return (
|
||||||
|
not str(app.get("google_client_id", "")).is_empty()
|
||||||
|
and not str(app.get("google_client_secret", "")).is_empty()
|
||||||
|
)
|
||||||
|
if provider == "dropbox":
|
||||||
|
return not str(app.get("dropbox_app_key", "")).is_empty()
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
|
static func missing_hint(provider: String) -> String:
|
||||||
|
if provider == "google_drive":
|
||||||
|
return (
|
||||||
|
"Google Drive ist in diesem Build nicht eingerichtet. "
|
||||||
|
+ "Es fehlen GOOGLE_CLIENT_ID und GOOGLE_CLIENT_SECRET "
|
||||||
|
+ "(siehe docs/cloud-setup.md)."
|
||||||
|
)
|
||||||
|
if provider == "dropbox":
|
||||||
|
return (
|
||||||
|
"Dropbox ist in diesem Build nicht eingerichtet. "
|
||||||
|
+ "Es fehlt DROPBOX_APP_KEY (siehe docs/cloud-setup.md)."
|
||||||
|
)
|
||||||
|
return "Unbekannter Cloud-Anbieter."
|
||||||
|
|
||||||
|
|
||||||
|
static func _empty() -> Dictionary:
|
||||||
|
var values := {}
|
||||||
|
for key: String in KEYS:
|
||||||
|
values[key] = ""
|
||||||
|
return values
|
||||||
1
rinkplanner/src/core/sync/sync_app_config.gd.uid
Normal file
1
rinkplanner/src/core/sync/sync_app_config.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://d0h7eoxsm5r1w
|
||||||
|
|
@ -64,6 +64,7 @@ const AUTOSAVE_PATH := RoutineFile.AUTOSAVE_JSON
|
||||||
const LEGACY_AUTOSAVE_PATH := RoutineFile.AUTOSAVE_LEGACY
|
const LEGACY_AUTOSAVE_PATH := RoutineFile.AUTOSAVE_LEGACY
|
||||||
const SESSION_PATH := "user://session.cfg"
|
const SESSION_PATH := "user://session.cfg"
|
||||||
const SYNC_SETTINGS_PATH := "user://sync.cfg"
|
const SYNC_SETTINGS_PATH := "user://sync.cfg"
|
||||||
|
const SYNC_PROVIDERS := ["dropbox", "google_drive"]
|
||||||
const AUTOSAVE_DELAY_SECONDS := 1.5
|
const AUTOSAVE_DELAY_SECONDS := 1.5
|
||||||
const MAX_HISTORY := 50
|
const MAX_HISTORY := 50
|
||||||
const COMPACT_LAYOUT_WIDTH := 1280.0
|
const COMPACT_LAYOUT_WIDTH := 1280.0
|
||||||
|
|
@ -100,6 +101,7 @@ const MAX_MUSIC_FILE_BYTES := 64 * 1024 * 1024
|
||||||
@onready var status_label: Label = %StatusLabel
|
@onready var status_label: Label = %StatusLabel
|
||||||
@onready var delete_segment_button: Button = %DeleteSegmentButton
|
@onready var delete_segment_button: Button = %DeleteSegmentButton
|
||||||
@onready var section_list: VBoxContainer = %SectionList
|
@onready var section_list: VBoxContainer = %SectionList
|
||||||
|
@onready var section_scroll: ScrollContainer = %SectionScroll
|
||||||
@onready var add_section_button: Button = %AddSectionButton
|
@onready var add_section_button: Button = %AddSectionButton
|
||||||
@onready var move_up_button: Button = %MoveUpButton
|
@onready var move_up_button: Button = %MoveUpButton
|
||||||
@onready var move_down_button: Button = %MoveDownButton
|
@onready var move_down_button: Button = %MoveDownButton
|
||||||
|
|
@ -178,13 +180,16 @@ const MAX_MUSIC_FILE_BYTES := 64 * 1024 * 1024
|
||||||
@onready var calibration_distance_edit: LineEdit = %CalibrationDistanceEdit
|
@onready var calibration_distance_edit: LineEdit = %CalibrationDistanceEdit
|
||||||
@onready var calibration_time_edit: LineEdit = %CalibrationTimeEdit
|
@onready var calibration_time_edit: LineEdit = %CalibrationTimeEdit
|
||||||
@onready var sync_settings_dialog: ConfirmationDialog = %SyncSettingsDialog
|
@onready var sync_settings_dialog: ConfirmationDialog = %SyncSettingsDialog
|
||||||
@onready var sync_host_edit: LineEdit = %SyncHostEdit
|
@onready var sync_provider_option: OptionButton = %SyncProviderOption
|
||||||
@onready var sync_port_edit: LineEdit = %SyncPortEdit
|
@onready var sync_account_value: Label = %SyncAccountValue
|
||||||
@onready var sync_user_edit: LineEdit = %SyncUserEdit
|
@onready var sync_connect_button: Button = %SyncConnectButton
|
||||||
@onready var sync_password_edit: LineEdit = %SyncPasswordEdit
|
|
||||||
@onready var sync_directory_edit: LineEdit = %SyncDirectoryEdit
|
@onready var sync_directory_edit: LineEdit = %SyncDirectoryEdit
|
||||||
@onready var sync_ftps_check: CheckBox = %SyncFtpsCheck
|
@onready var cloud_auth_dialog: ConfirmationDialog = %CloudAuthDialog
|
||||||
@onready var sync_verify_check: CheckBox = %SyncVerifyCheck
|
@onready var cloud_auth_status: Label = %CloudAuthStatus
|
||||||
|
@onready var cloud_auth_url_edit: LineEdit = %CloudAuthUrlEdit
|
||||||
|
@onready var cloud_auth_user_code: Label = %CloudAuthUserCode
|
||||||
|
@onready var cloud_auth_code_edit: LineEdit = %CloudAuthCodeEdit
|
||||||
|
@onready var cloud_auth_code_hint: Label = %CloudAuthCodeHint
|
||||||
@onready var export_dialog: ConfirmationDialog = %ExportDialog
|
@onready var export_dialog: ConfirmationDialog = %ExportDialog
|
||||||
@onready var export_name_edit: LineEdit = %ExportNameEdit
|
@onready var export_name_edit: LineEdit = %ExportNameEdit
|
||||||
@onready var export_format_option: OptionButton = %ExportFormatOption
|
@onready var export_format_option: OptionButton = %ExportFormatOption
|
||||||
|
|
@ -240,6 +245,12 @@ var _pending_timeline_label_time: float = 0.0
|
||||||
var _sync_thread: Thread
|
var _sync_thread: Thread
|
||||||
var _sync_job: RoutineSync
|
var _sync_job: RoutineSync
|
||||||
var _sync_running: bool = false
|
var _sync_running: bool = false
|
||||||
|
var _oauth_thread: Thread
|
||||||
|
var _oauth_job: CloudOAuthJob
|
||||||
|
var _oauth_provider: String = ""
|
||||||
|
var _oauth_verifier: String = ""
|
||||||
|
var _oauth_cancelled: bool = false
|
||||||
|
var _oauth_browser_opened: bool = false
|
||||||
var _presentation_3d: Presentation3D
|
var _presentation_3d: Presentation3D
|
||||||
var _view_3d_active: bool = false
|
var _view_3d_active: bool = false
|
||||||
|
|
||||||
|
|
@ -340,6 +351,10 @@ func _ready() -> void:
|
||||||
export_folder_button.pressed.connect(_on_export_folder_pressed)
|
export_folder_button.pressed.connect(_on_export_folder_pressed)
|
||||||
export_copy_path_button.pressed.connect(_on_export_copy_path_pressed)
|
export_copy_path_button.pressed.connect(_on_export_copy_path_pressed)
|
||||||
sync_settings_dialog.confirmed.connect(_on_sync_settings_confirmed)
|
sync_settings_dialog.confirmed.connect(_on_sync_settings_confirmed)
|
||||||
|
sync_provider_option.item_selected.connect(_on_sync_provider_selected)
|
||||||
|
sync_connect_button.pressed.connect(_on_sync_connect_pressed)
|
||||||
|
cloud_auth_dialog.confirmed.connect(_on_cloud_auth_confirmed)
|
||||||
|
cloud_auth_dialog.canceled.connect(_on_cloud_auth_canceled)
|
||||||
label_button.pressed.connect(_open_label_dialog)
|
label_button.pressed.connect(_open_label_dialog)
|
||||||
labels_toggle.toggled.connect(_on_labels_toggled)
|
labels_toggle.toggled.connect(_on_labels_toggled)
|
||||||
segment_label_dialog.confirmed.connect(_on_label_confirmed)
|
segment_label_dialog.confirmed.connect(_on_label_confirmed)
|
||||||
|
|
@ -2789,6 +2804,7 @@ func reset_playback() -> void:
|
||||||
_stop_music()
|
_stop_music()
|
||||||
_update_play_button()
|
_update_play_button()
|
||||||
rink_canvas.clear_playback_state()
|
rink_canvas.clear_playback_state()
|
||||||
|
_update_section_buttons()
|
||||||
if _view_3d_active and _presentation_3d != null:
|
if _view_3d_active and _presentation_3d != null:
|
||||||
_presentation_3d.clear_pose()
|
_presentation_3d.clear_pose()
|
||||||
_update_playback_ui()
|
_update_playback_ui()
|
||||||
|
|
@ -2798,7 +2814,10 @@ func reset_playback() -> void:
|
||||||
func seek_playback(time: float) -> void:
|
func seek_playback(time: float) -> void:
|
||||||
_playback_time = clampf(time, 0.0, _playback_total_duration)
|
_playback_time = clampf(time, 0.0, _playback_total_duration)
|
||||||
if _playback_total_duration <= 0.0:
|
if _playback_total_duration <= 0.0:
|
||||||
|
_playback_section_id = ""
|
||||||
|
_playback_segment_id = ""
|
||||||
rink_canvas.clear_playback_state()
|
rink_canvas.clear_playback_state()
|
||||||
|
_update_section_buttons()
|
||||||
else:
|
else:
|
||||||
_update_playback_state(0.0, true)
|
_update_playback_state(0.0, true)
|
||||||
if _playing:
|
if _playing:
|
||||||
|
|
@ -2833,6 +2852,7 @@ func _process(delta: float) -> void:
|
||||||
advance_playback(delta)
|
advance_playback(delta)
|
||||||
_sync_music_to_playback()
|
_sync_music_to_playback()
|
||||||
_poll_sync_thread()
|
_poll_sync_thread()
|
||||||
|
_poll_oauth_thread()
|
||||||
|
|
||||||
if _sync_running and _sync_job != null and not _sync_job.progress.is_empty():
|
if _sync_running and _sync_job != null and not _sync_job.progress.is_empty():
|
||||||
status_label.text = "Sync: " + _sync_job.progress
|
status_label.text = "Sync: " + _sync_job.progress
|
||||||
|
|
@ -2922,6 +2942,7 @@ func _refresh_playback_timeline() -> void:
|
||||||
_playback_section_id = ""
|
_playback_section_id = ""
|
||||||
_playback_segment_id = ""
|
_playback_segment_id = ""
|
||||||
rink_canvas.clear_playback_state()
|
rink_canvas.clear_playback_state()
|
||||||
|
_update_section_buttons()
|
||||||
if _view_3d_active and _presentation_3d != null:
|
if _view_3d_active and _presentation_3d != null:
|
||||||
_presentation_3d.clear_pose()
|
_presentation_3d.clear_pose()
|
||||||
else:
|
else:
|
||||||
|
|
@ -2942,7 +2963,9 @@ func _update_playback_state(
|
||||||
force_heading: bool = false
|
force_heading: bool = false
|
||||||
) -> void:
|
) -> void:
|
||||||
if _playback_entries.is_empty() or _routine == null:
|
if _playback_entries.is_empty() or _routine == null:
|
||||||
|
_playback_section_id = ""
|
||||||
rink_canvas.clear_playback_state()
|
rink_canvas.clear_playback_state()
|
||||||
|
_update_section_buttons()
|
||||||
if _view_3d_active and _presentation_3d != null:
|
if _view_3d_active and _presentation_3d != null:
|
||||||
_presentation_3d.clear_pose()
|
_presentation_3d.clear_pose()
|
||||||
return
|
return
|
||||||
|
|
@ -3006,9 +3029,16 @@ func _update_playback_state(
|
||||||
)
|
)
|
||||||
|
|
||||||
_playback_position = position
|
_playback_position = position
|
||||||
|
var section_changed := _playback_section_id != section_id
|
||||||
_playback_section_id = section_id
|
_playback_section_id = section_id
|
||||||
_playback_segment_id = segment.segment_id
|
_playback_segment_id = segment.segment_id
|
||||||
|
|
||||||
|
if section_changed:
|
||||||
|
var section := _routine.get_section_by_id(section_id)
|
||||||
|
if section != null:
|
||||||
|
rink_canvas.show_section_banner(section.title)
|
||||||
|
_update_section_buttons()
|
||||||
|
|
||||||
rink_canvas.set_playback_state(
|
rink_canvas.set_playback_state(
|
||||||
position,
|
position,
|
||||||
_playback_heading,
|
_playback_heading,
|
||||||
|
|
@ -4285,19 +4315,21 @@ func _apply_responsive_layout() -> void:
|
||||||
|
|
||||||
func load_sync_settings() -> Dictionary:
|
func load_sync_settings() -> Dictionary:
|
||||||
var settings := {
|
var settings := {
|
||||||
"host": "",
|
"provider": "dropbox",
|
||||||
"port": 21,
|
|
||||||
"user": "",
|
|
||||||
"password": "",
|
|
||||||
"directory": "",
|
"directory": "",
|
||||||
"ftps": true,
|
"tokens": {},
|
||||||
"verify_certificate": true,
|
|
||||||
}
|
}
|
||||||
var config := ConfigFile.new()
|
var config := ConfigFile.new()
|
||||||
if config.load(SYNC_SETTINGS_PATH) != OK:
|
if config.load(SYNC_SETTINGS_PATH) != OK:
|
||||||
return settings
|
return settings
|
||||||
for key: String in settings.keys():
|
for key: String in settings.keys():
|
||||||
settings[key] = config.get_value("connection", key, settings[key])
|
settings[key] = config.get_value("connection", key, settings[key])
|
||||||
|
var tokens: Variant = settings.get("tokens", {})
|
||||||
|
if not tokens is Dictionary:
|
||||||
|
settings["tokens"] = {}
|
||||||
|
var provider := str(settings.get("provider", ""))
|
||||||
|
if not SYNC_PROVIDERS.has(provider):
|
||||||
|
settings["provider"] = "dropbox"
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4306,34 +4338,348 @@ func save_sync_settings(settings: Dictionary) -> void:
|
||||||
for key: String in settings.keys():
|
for key: String in settings.keys():
|
||||||
config.set_value("connection", key, settings[key])
|
config.set_value("connection", key, settings[key])
|
||||||
config.save(SYNC_SETTINGS_PATH)
|
config.save(SYNC_SETTINGS_PATH)
|
||||||
|
_protect_sync_settings()
|
||||||
|
|
||||||
|
|
||||||
|
func _protect_sync_settings() -> void:
|
||||||
|
# Refresh tokens are app-private, but make the file owner-only on Unix as
|
||||||
|
# well. Android's user:// storage is already sandboxed; Windows has ACLs.
|
||||||
|
if OS.get_name() not in ["Linux", "macOS", "FreeBSD", "NetBSD", "OpenBSD"]:
|
||||||
|
return
|
||||||
|
OS.execute(
|
||||||
|
"chmod",
|
||||||
|
PackedStringArray([
|
||||||
|
"600",
|
||||||
|
ProjectSettings.globalize_path(SYNC_SETTINGS_PATH),
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
func _open_sync_settings_dialog() -> void:
|
func _open_sync_settings_dialog() -> void:
|
||||||
var settings := load_sync_settings()
|
var settings := load_sync_settings()
|
||||||
sync_host_edit.text = str(settings.get("host", ""))
|
_ensure_sync_provider_items()
|
||||||
sync_port_edit.text = str(settings.get("port", 21))
|
_apply_sync_provider_to_ui(str(settings.get("provider", "dropbox")))
|
||||||
sync_user_edit.text = str(settings.get("user", ""))
|
|
||||||
sync_password_edit.text = str(settings.get("password", ""))
|
|
||||||
sync_directory_edit.text = str(settings.get("directory", ""))
|
sync_directory_edit.text = str(settings.get("directory", ""))
|
||||||
sync_ftps_check.button_pressed = bool(settings.get("ftps", true))
|
_update_sync_account(settings)
|
||||||
sync_verify_check.button_pressed = bool(settings.get("verify_certificate", true))
|
sync_settings_dialog.popup_centered(Vector2i(620, 500))
|
||||||
sync_settings_dialog.popup_centered(Vector2i(620, 620))
|
sync_directory_edit.grab_focus()
|
||||||
sync_host_edit.grab_focus()
|
|
||||||
|
|
||||||
|
func _ensure_sync_provider_items() -> void:
|
||||||
|
if sync_provider_option.item_count > 0:
|
||||||
|
return
|
||||||
|
var app := SyncAppConfig.load_config()
|
||||||
|
var has_dropbox := SyncAppConfig.is_configured("dropbox", app)
|
||||||
|
var has_google := SyncAppConfig.is_configured("google_drive", app)
|
||||||
|
if not has_dropbox and not has_google:
|
||||||
|
# Developer build without app credentials: show both so the missing
|
||||||
|
# configuration is visible instead of an empty dropdown.
|
||||||
|
has_dropbox = true
|
||||||
|
has_google = true
|
||||||
|
if has_dropbox:
|
||||||
|
sync_provider_option.add_item("Dropbox", 0)
|
||||||
|
sync_provider_option.set_item_metadata(
|
||||||
|
sync_provider_option.item_count - 1,
|
||||||
|
"dropbox"
|
||||||
|
)
|
||||||
|
if has_google:
|
||||||
|
sync_provider_option.add_item("Google Drive", 1)
|
||||||
|
sync_provider_option.set_item_metadata(
|
||||||
|
sync_provider_option.item_count - 1,
|
||||||
|
"google_drive"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _apply_sync_provider_to_ui(provider: String) -> void:
|
||||||
|
for index: int in range(sync_provider_option.item_count):
|
||||||
|
if str(sync_provider_option.get_item_metadata(index)) == provider:
|
||||||
|
sync_provider_option.select(index)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
func _selected_sync_provider() -> String:
|
||||||
|
_ensure_sync_provider_items()
|
||||||
|
var index := sync_provider_option.selected
|
||||||
|
if index < 0 or index >= sync_provider_option.item_count:
|
||||||
|
return "dropbox"
|
||||||
|
return str(sync_provider_option.get_item_metadata(index))
|
||||||
|
|
||||||
|
|
||||||
|
func _update_sync_account(settings: Dictionary) -> void:
|
||||||
|
var provider := _selected_sync_provider()
|
||||||
|
var tokens := RoutineSync.provider_tokens(settings, provider)
|
||||||
|
var connected := not str(tokens.get("refresh_token", "")).is_empty()
|
||||||
|
if connected:
|
||||||
|
var account := str(tokens.get("account", "")).strip_edges()
|
||||||
|
sync_account_value.text = account if not account.is_empty() else "Verbunden"
|
||||||
|
sync_connect_button.text = "Trennen"
|
||||||
|
else:
|
||||||
|
sync_account_value.text = "Nicht verbunden"
|
||||||
|
sync_connect_button.text = "Verbinden…"
|
||||||
|
|
||||||
|
|
||||||
|
func _on_sync_provider_selected(_index: int) -> void:
|
||||||
|
_update_sync_account(load_sync_settings())
|
||||||
|
|
||||||
|
|
||||||
func _on_sync_settings_confirmed() -> void:
|
func _on_sync_settings_confirmed() -> void:
|
||||||
var port := int(sync_port_edit.text.strip_edges())
|
var settings := load_sync_settings()
|
||||||
if port <= 0 or port > 65535:
|
var provider := _selected_sync_provider()
|
||||||
port = 21
|
var directory := (
|
||||||
save_sync_settings({
|
sync_directory_edit.text.strip_edges()
|
||||||
"host": sync_host_edit.text.strip_edges(),
|
.replace("/", "-")
|
||||||
"port": port,
|
.replace("\\", "-")
|
||||||
"user": sync_user_edit.text.strip_edges(),
|
)
|
||||||
"password": sync_password_edit.text,
|
if directory.is_empty() and provider == "google_drive":
|
||||||
"directory": sync_directory_edit.text.strip_edges(),
|
directory = "Rinkplanner"
|
||||||
"ftps": sync_ftps_check.button_pressed,
|
var changed := (
|
||||||
"verify_certificate": sync_verify_check.button_pressed,
|
str(settings.get("provider", "")) != provider
|
||||||
})
|
or str(settings.get("directory", "")) != directory
|
||||||
|
)
|
||||||
|
settings["provider"] = provider
|
||||||
|
settings["directory"] = directory
|
||||||
|
save_sync_settings(settings)
|
||||||
|
if changed:
|
||||||
|
_reset_sync_state()
|
||||||
|
|
||||||
|
|
||||||
|
func _reset_sync_state() -> void:
|
||||||
|
if FileAccess.file_exists(RoutineSync.STATE_PATH):
|
||||||
|
DirAccess.remove_absolute(
|
||||||
|
ProjectSettings.globalize_path(RoutineSync.STATE_PATH)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_sync_connect_pressed() -> void:
|
||||||
|
var provider := _selected_sync_provider()
|
||||||
|
var settings := load_sync_settings()
|
||||||
|
var tokens := RoutineSync.provider_tokens(settings, provider)
|
||||||
|
if not str(tokens.get("refresh_token", "")).is_empty():
|
||||||
|
_disconnect_sync_provider(provider)
|
||||||
|
return
|
||||||
|
|
||||||
|
var app := SyncAppConfig.load_config()
|
||||||
|
if not SyncAppConfig.is_configured(provider, app):
|
||||||
|
_show_message(SyncAppConfig.missing_hint(provider))
|
||||||
|
return
|
||||||
|
|
||||||
|
if provider == "google_drive":
|
||||||
|
_start_google_login(app)
|
||||||
|
else:
|
||||||
|
_start_dropbox_login(app)
|
||||||
|
|
||||||
|
|
||||||
|
func _disconnect_sync_provider(provider: String) -> void:
|
||||||
|
var settings := load_sync_settings()
|
||||||
|
var tokens: Dictionary = settings.get("tokens", {})
|
||||||
|
tokens.erase(provider)
|
||||||
|
settings["tokens"] = tokens
|
||||||
|
save_sync_settings(settings)
|
||||||
|
_reset_sync_state()
|
||||||
|
_update_sync_account(settings)
|
||||||
|
_show_message(
|
||||||
|
(
|
||||||
|
"%s wurde von diesem Gerät getrennt. "
|
||||||
|
+ "Die Dateien im Cloud-Konto bleiben erhalten."
|
||||||
|
) % RemoteStore.provider_label(provider)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _start_google_login(app: Dictionary) -> void:
|
||||||
|
_abort_oauth_job()
|
||||||
|
_oauth_provider = "google_drive"
|
||||||
|
_oauth_cancelled = false
|
||||||
|
_oauth_browser_opened = false
|
||||||
|
_oauth_verifier = ""
|
||||||
|
_oauth_job = CloudOAuthJob.new()
|
||||||
|
_configure_cloud_auth_dialog("google_drive")
|
||||||
|
cloud_auth_dialog.popup_centered(Vector2i(620, 420))
|
||||||
|
var started := _start_oauth_thread(_oauth_job.run_google_device.bind(
|
||||||
|
str(app.get("google_client_id", "")),
|
||||||
|
str(app.get("google_client_secret", ""))
|
||||||
|
))
|
||||||
|
if not started:
|
||||||
|
cloud_auth_status.text = "Die Google-Anmeldung konnte nicht gestartet werden."
|
||||||
|
|
||||||
|
|
||||||
|
func _start_dropbox_login(app: Dictionary) -> void:
|
||||||
|
_abort_oauth_job()
|
||||||
|
_oauth_provider = "dropbox"
|
||||||
|
_oauth_cancelled = false
|
||||||
|
_oauth_browser_opened = true
|
||||||
|
_oauth_verifier = CloudOAuthJob.new_verifier()
|
||||||
|
var url := CloudOAuthJob.dropbox_authorize_url(
|
||||||
|
str(app.get("dropbox_app_key", "")),
|
||||||
|
_oauth_verifier
|
||||||
|
)
|
||||||
|
_configure_cloud_auth_dialog("dropbox")
|
||||||
|
cloud_auth_url_edit.text = url
|
||||||
|
cloud_auth_dialog.popup_centered(Vector2i(620, 420))
|
||||||
|
OS.shell_open(url)
|
||||||
|
|
||||||
|
|
||||||
|
func _configure_cloud_auth_dialog(provider: String) -> void:
|
||||||
|
cloud_auth_status.text = (
|
||||||
|
"Fordere Anmeldecode an …" if provider == "google_drive"
|
||||||
|
else "Dropbox im Browser öffnen und den Code hier einfügen."
|
||||||
|
)
|
||||||
|
cloud_auth_url_edit.text = ""
|
||||||
|
cloud_auth_user_code.text = ""
|
||||||
|
cloud_auth_code_edit.text = ""
|
||||||
|
cloud_auth_user_code.visible = provider == "google_drive"
|
||||||
|
cloud_auth_code_edit.visible = provider == "dropbox"
|
||||||
|
cloud_auth_code_hint.visible = provider == "dropbox"
|
||||||
|
cloud_auth_code_hint.text = "Code aus der Dropbox-Seite hier einfügen."
|
||||||
|
cloud_auth_dialog.title = (
|
||||||
|
"Google Drive verbinden" if provider == "google_drive"
|
||||||
|
else "Dropbox verbinden"
|
||||||
|
)
|
||||||
|
cloud_auth_dialog.dialog_hide_on_ok = false
|
||||||
|
cloud_auth_dialog.get_ok_button().text = (
|
||||||
|
"Browser öffnen" if provider == "google_drive" else "Verbinden"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_cloud_auth_confirmed() -> void:
|
||||||
|
if _oauth_provider.is_empty():
|
||||||
|
cloud_auth_dialog.hide()
|
||||||
|
return
|
||||||
|
if _oauth_provider == "google_drive":
|
||||||
|
var url := cloud_auth_url_edit.text.strip_edges()
|
||||||
|
if not url.is_empty():
|
||||||
|
OS.shell_open(url)
|
||||||
|
return
|
||||||
|
|
||||||
|
var code := cloud_auth_code_edit.text.strip_edges()
|
||||||
|
if code.is_empty():
|
||||||
|
cloud_auth_status.text = "Bitte den Code aus der Dropbox-Seite einfügen."
|
||||||
|
return
|
||||||
|
if _oauth_thread != null and _oauth_thread.is_alive():
|
||||||
|
return
|
||||||
|
var app := SyncAppConfig.load_config()
|
||||||
|
if not SyncAppConfig.is_configured("dropbox", app):
|
||||||
|
cloud_auth_status.text = SyncAppConfig.missing_hint("dropbox")
|
||||||
|
return
|
||||||
|
_oauth_cancelled = false
|
||||||
|
_oauth_job = CloudOAuthJob.new()
|
||||||
|
cloud_auth_status.text = "Tausche Anmeldecode …"
|
||||||
|
var started := _start_oauth_thread(_oauth_job.run_dropbox_exchange.bind(
|
||||||
|
str(app.get("dropbox_app_key", "")),
|
||||||
|
str(app.get("dropbox_app_secret", "")),
|
||||||
|
_oauth_verifier,
|
||||||
|
code
|
||||||
|
))
|
||||||
|
if not started:
|
||||||
|
cloud_auth_status.text = "Die Dropbox-Anmeldung konnte nicht gestartet werden."
|
||||||
|
|
||||||
|
|
||||||
|
func _start_oauth_thread(callable: Callable) -> bool:
|
||||||
|
_oauth_thread = Thread.new()
|
||||||
|
var thread_error := _oauth_thread.start(callable)
|
||||||
|
if thread_error != OK:
|
||||||
|
_oauth_thread = null
|
||||||
|
_oauth_job = null
|
||||||
|
return false
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
|
func _poll_oauth_thread() -> void:
|
||||||
|
if _oauth_thread == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
if _oauth_job != null:
|
||||||
|
if (
|
||||||
|
not _oauth_job.verification_url.is_empty()
|
||||||
|
and cloud_auth_url_edit.text != _oauth_job.verification_url
|
||||||
|
):
|
||||||
|
cloud_auth_url_edit.text = _oauth_job.verification_url
|
||||||
|
if (
|
||||||
|
not _oauth_job.user_code.is_empty()
|
||||||
|
and cloud_auth_user_code.text != _oauth_job.user_code
|
||||||
|
):
|
||||||
|
cloud_auth_user_code.text = _oauth_job.user_code
|
||||||
|
if (
|
||||||
|
_oauth_provider == "google_drive"
|
||||||
|
and not _oauth_browser_opened
|
||||||
|
and not _oauth_job.verification_url.is_empty()
|
||||||
|
):
|
||||||
|
_oauth_browser_opened = true
|
||||||
|
OS.shell_open(_oauth_job.verification_url)
|
||||||
|
if (
|
||||||
|
not _oauth_job.status.is_empty()
|
||||||
|
and cloud_auth_status.text != _oauth_job.status
|
||||||
|
):
|
||||||
|
cloud_auth_status.text = _oauth_job.status
|
||||||
|
|
||||||
|
if _oauth_thread.is_alive():
|
||||||
|
return
|
||||||
|
|
||||||
|
_oauth_thread.wait_to_finish()
|
||||||
|
_oauth_thread = null
|
||||||
|
var job := _oauth_job
|
||||||
|
_oauth_job = null
|
||||||
|
if job == null:
|
||||||
|
return
|
||||||
|
if _oauth_cancelled:
|
||||||
|
_reset_oauth_state()
|
||||||
|
return
|
||||||
|
|
||||||
|
if not job.error.is_empty():
|
||||||
|
cloud_auth_status.text = job.error
|
||||||
|
if _oauth_provider == "dropbox":
|
||||||
|
# The user can paste a fresh code and try again.
|
||||||
|
cloud_auth_dialog.get_ok_button().text = "Verbinden"
|
||||||
|
else:
|
||||||
|
cloud_auth_url_edit.text = ""
|
||||||
|
_oauth_provider = ""
|
||||||
|
cloud_auth_dialog.get_ok_button().text = "Schließen"
|
||||||
|
return
|
||||||
|
|
||||||
|
_save_oauth_tokens(_oauth_provider, job.result)
|
||||||
|
var connected_provider := _oauth_provider
|
||||||
|
cloud_auth_dialog.hide()
|
||||||
|
_reset_oauth_state()
|
||||||
|
_update_sync_account(load_sync_settings())
|
||||||
|
_show_message(
|
||||||
|
"%s ist verbunden. Der Abgleich läuft über Datei → Jetzt synchronisieren."
|
||||||
|
% RemoteStore.provider_label(connected_provider)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _save_oauth_tokens(provider: String, tokens: Dictionary) -> void:
|
||||||
|
var settings := load_sync_settings()
|
||||||
|
var all_tokens: Dictionary = settings.get("tokens", {})
|
||||||
|
all_tokens[provider] = tokens.duplicate(true)
|
||||||
|
settings["tokens"] = all_tokens
|
||||||
|
save_sync_settings(settings)
|
||||||
|
_reset_sync_state()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_cloud_auth_canceled() -> void:
|
||||||
|
_oauth_cancelled = true
|
||||||
|
if _oauth_job != null:
|
||||||
|
_oauth_job.cancelled = true
|
||||||
|
cloud_auth_dialog.hide()
|
||||||
|
if _oauth_thread == null:
|
||||||
|
_reset_oauth_state()
|
||||||
|
|
||||||
|
|
||||||
|
func _reset_oauth_state() -> void:
|
||||||
|
_oauth_provider = ""
|
||||||
|
_oauth_verifier = ""
|
||||||
|
_oauth_cancelled = false
|
||||||
|
_oauth_browser_opened = false
|
||||||
|
|
||||||
|
|
||||||
|
func _abort_oauth_job() -> void:
|
||||||
|
if _oauth_job != null:
|
||||||
|
_oauth_job.cancelled = true
|
||||||
|
if _oauth_thread != null:
|
||||||
|
if _oauth_thread.is_alive():
|
||||||
|
_oauth_thread.wait_to_finish()
|
||||||
|
_oauth_thread = null
|
||||||
|
_oauth_job = null
|
||||||
|
_reset_oauth_state()
|
||||||
|
|
||||||
|
|
||||||
## Manual sync: push/pull every routine file, keep both versions on conflict.
|
## Manual sync: push/pull every routine file, keep both versions on conflict.
|
||||||
|
|
@ -4348,7 +4694,12 @@ func start_sync() -> void:
|
||||||
save_to_path(_current_path)
|
save_to_path(_current_path)
|
||||||
|
|
||||||
var settings := load_sync_settings()
|
var settings := load_sync_settings()
|
||||||
if str(settings.get("host", "")).is_empty() or str(settings.get("user", "")).is_empty():
|
var provider := str(settings.get("provider", ""))
|
||||||
|
var tokens := RoutineSync.provider_tokens(settings, provider)
|
||||||
|
if (
|
||||||
|
not SYNC_PROVIDERS.has(provider)
|
||||||
|
or str(tokens.get("refresh_token", "")).is_empty()
|
||||||
|
):
|
||||||
_open_sync_settings_dialog()
|
_open_sync_settings_dialog()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -4408,7 +4759,7 @@ func _format_sync_summary(result: Dictionary) -> String:
|
||||||
lines.append("Heruntergeladen: %d" % downloaded.size())
|
lines.append("Heruntergeladen: %d" % downloaded.size())
|
||||||
if not downloaded.is_empty():
|
if not downloaded.is_empty():
|
||||||
lines.append(" " + ", ".join(downloaded))
|
lines.append(" " + ", ".join(downloaded))
|
||||||
lines.append("Vom Server übernommen: %d" % adopted.size())
|
lines.append("Vom Cloud-Konto übernommen: %d" % adopted.size())
|
||||||
for index: int in range(adopted.size()):
|
for index: int in range(adopted.size()):
|
||||||
var backup := ""
|
var backup := ""
|
||||||
if index < backups.size():
|
if index < backups.size():
|
||||||
|
|
@ -4441,7 +4792,7 @@ func _reload_after_sync(result: Dictionary) -> void:
|
||||||
if is_dirty():
|
if is_dirty():
|
||||||
_refresh_synced_music(result)
|
_refresh_synced_music(result)
|
||||||
_show_message(
|
_show_message(
|
||||||
"Die geöffnete Kür wurde vom Server aktualisiert, hat aber "
|
"Die geöffnete Kür wurde aus der Cloud aktualisiert, hat aber "
|
||||||
+ "ungespeicherte Änderungen. Bitte manuell speichern oder neu laden."
|
+ "ungespeicherte Änderungen. Bitte manuell speichern oder neu laden."
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
@ -4465,6 +4816,11 @@ func _refresh_synced_music(result: Dictionary) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree() -> void:
|
func _exit_tree() -> void:
|
||||||
|
if _oauth_job != null:
|
||||||
|
_oauth_job.cancelled = true
|
||||||
|
if _oauth_thread != null:
|
||||||
|
_oauth_thread.wait_to_finish()
|
||||||
|
_oauth_thread = null
|
||||||
if _sync_thread != null:
|
if _sync_thread != null:
|
||||||
_sync_thread.wait_to_finish()
|
_sync_thread.wait_to_finish()
|
||||||
_sync_thread = null
|
_sync_thread = null
|
||||||
|
|
@ -4781,7 +5137,7 @@ func _rebuild_section_list() -> void:
|
||||||
var section: RoutineSection = _routine.sections[index]
|
var section: RoutineSection = _routine.sections[index]
|
||||||
var button := Button.new()
|
var button := Button.new()
|
||||||
button.toggle_mode = true
|
button.toggle_mode = true
|
||||||
button.button_pressed = section.section_id == _active_section.section_id
|
button.button_pressed = false
|
||||||
button.text = "%d · %s" % [index + 1, section.title]
|
button.text = "%d · %s" % [index + 1, section.title]
|
||||||
button.tooltip_text = section.title
|
button.tooltip_text = section.title
|
||||||
button.custom_minimum_size = Vector2(0.0, 56.0)
|
button.custom_minimum_size = Vector2(0.0, 56.0)
|
||||||
|
|
@ -4794,12 +5150,54 @@ func _rebuild_section_list() -> void:
|
||||||
_update_section_buttons()
|
_update_section_buttons()
|
||||||
|
|
||||||
|
|
||||||
|
## Section shown as "current" in the right list: while the playback has a
|
||||||
|
## position, that section; otherwise the editing selection.
|
||||||
|
func _highlight_section_id() -> String:
|
||||||
|
if (
|
||||||
|
not _playback_section_id.is_empty()
|
||||||
|
and _routine != null
|
||||||
|
and _routine.get_section_by_id(_playback_section_id) != null
|
||||||
|
):
|
||||||
|
return _playback_section_id
|
||||||
|
if _active_section != null:
|
||||||
|
return _active_section.section_id
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
func _update_section_buttons() -> void:
|
func _update_section_buttons() -> void:
|
||||||
|
var highlight_id := _highlight_section_id()
|
||||||
|
var active_id := ""
|
||||||
|
if _active_section != null:
|
||||||
|
active_id = _active_section.section_id
|
||||||
|
if _routine == null:
|
||||||
|
move_up_button.disabled = true
|
||||||
|
move_down_button.disabled = true
|
||||||
|
delete_button.disabled = true
|
||||||
|
return
|
||||||
|
|
||||||
for section_id: String in _section_buttons.keys():
|
for section_id: String in _section_buttons.keys():
|
||||||
var button: Button = _section_buttons[section_id]
|
var button: Button = _section_buttons[section_id]
|
||||||
button.set_pressed_no_signal(section_id == _active_section.section_id)
|
var section := _routine.get_section_by_id(section_id)
|
||||||
|
var index := _find_section_index(section_id)
|
||||||
|
if section != null:
|
||||||
|
var marker := "▶ " if section_id == highlight_id else ""
|
||||||
|
button.text = "%s%d · %s" % [marker, index + 1, section.title]
|
||||||
|
if section_id == highlight_id:
|
||||||
|
button.add_theme_color_override(
|
||||||
|
"font_color",
|
||||||
|
Color(0.72, 0.85, 1.0, 1.0)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
button.remove_theme_color_override("font_color")
|
||||||
|
button.set_pressed_no_signal(section_id == active_id)
|
||||||
|
|
||||||
var active_index := _find_section_index(_active_section.section_id)
|
var highlighted_button: Button = _section_buttons.get(highlight_id)
|
||||||
|
if highlighted_button != null and section_scroll != null:
|
||||||
|
section_scroll.ensure_control_visible(highlighted_button)
|
||||||
|
|
||||||
|
var active_index := -1
|
||||||
|
if _active_section != null:
|
||||||
|
active_index = _find_section_index(_active_section.section_id)
|
||||||
move_up_button.disabled = active_index <= 0
|
move_up_button.disabled = active_index <= 0
|
||||||
move_down_button.disabled = (
|
move_down_button.disabled = (
|
||||||
active_index < 0 or active_index >= _routine.sections.size() - 1
|
active_index < 0 or active_index >= _routine.sections.size() - 1
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,11 @@ const SEGMENT_HIT_RADIUS_PX := 14.0
|
||||||
const HANDLE_HIT_RADIUS_PX := 22.0
|
const HANDLE_HIT_RADIUS_PX := 22.0
|
||||||
const HANDLE_RADIUS_PX := 7.0
|
const HANDLE_RADIUS_PX := 7.0
|
||||||
const TOUCH_MOUSE_GUARD_MSEC := 300
|
const TOUCH_MOUSE_GUARD_MSEC := 300
|
||||||
|
const SECTION_BANNER_DURATION := 2.0
|
||||||
|
const SECTION_BANNER_FADE_IN := 0.15
|
||||||
|
const SECTION_BANNER_FADE_OUT := 0.6
|
||||||
|
const SECTION_BANNER_TOP := 18.0
|
||||||
|
const SECTION_BANNER_FONT_SIZE := 22
|
||||||
|
|
||||||
@export var fit_padding_px: float = 32.0
|
@export var fit_padding_px: float = 32.0
|
||||||
@export var drawing_enabled: bool = true
|
@export var drawing_enabled: bool = true
|
||||||
|
|
@ -96,6 +101,11 @@ var _playback_section_id: String = ""
|
||||||
var _playback_edge: PathSegment.Edge = PathSegment.Edge.OUTSIDE
|
var _playback_edge: PathSegment.Edge = PathSegment.Edge.OUTSIDE
|
||||||
var _playback_direction: PathSegment.Direction = PathSegment.Direction.FORWARD
|
var _playback_direction: PathSegment.Direction = PathSegment.Direction.FORWARD
|
||||||
|
|
||||||
|
var _section_banner_text: String = ""
|
||||||
|
var _section_banner_elapsed: float = 0.0
|
||||||
|
var _section_banner_remaining: float = 0.0
|
||||||
|
var _section_banner_duration: float = 0.0
|
||||||
|
|
||||||
# Screen-space polyline cache. During playback only the marker moves, so the
|
# Screen-space polyline cache. During playback only the marker moves, so the
|
||||||
# sampled paths can be reused instead of re-baking every curve each frame.
|
# sampled paths can be reused instead of re-baking every curve each frame.
|
||||||
var _curve_cache: Dictionary[int, Dictionary] = {}
|
var _curve_cache: Dictionary[int, Dictionary] = {}
|
||||||
|
|
@ -106,6 +116,7 @@ var _curve_cache_origin: Vector2 = Vector2.INF
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
focus_mode = Control.FOCUS_ALL
|
focus_mode = Control.FOCUS_ALL
|
||||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
|
set_process(false)
|
||||||
fit_rink()
|
fit_rink()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -214,6 +225,7 @@ func set_playback_state(
|
||||||
func clear_playback_state() -> void:
|
func clear_playback_state() -> void:
|
||||||
_playback_visible = false
|
_playback_visible = false
|
||||||
_playback_section_id = ""
|
_playback_section_id = ""
|
||||||
|
hide_section_banner()
|
||||||
queue_redraw()
|
queue_redraw()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -221,6 +233,69 @@ func get_playback_section_id() -> String:
|
||||||
return _playback_section_id
|
return _playback_section_id
|
||||||
|
|
||||||
|
|
||||||
|
## Shows the current section name at the top of the rink. It fades in briefly,
|
||||||
|
## stays readable and fades out before [param duration] seconds are over.
|
||||||
|
func show_section_banner(text: String, duration: float = SECTION_BANNER_DURATION) -> void:
|
||||||
|
var cleaned := text.strip_edges()
|
||||||
|
if cleaned.is_empty():
|
||||||
|
hide_section_banner()
|
||||||
|
return
|
||||||
|
_section_banner_text = cleaned
|
||||||
|
_section_banner_duration = maxf(duration, SECTION_BANNER_FADE_IN + SECTION_BANNER_FADE_OUT)
|
||||||
|
_section_banner_elapsed = 0.0
|
||||||
|
_section_banner_remaining = _section_banner_duration
|
||||||
|
set_process(true)
|
||||||
|
queue_redraw()
|
||||||
|
|
||||||
|
|
||||||
|
func hide_section_banner() -> void:
|
||||||
|
_section_banner_text = ""
|
||||||
|
_section_banner_elapsed = 0.0
|
||||||
|
_section_banner_remaining = 0.0
|
||||||
|
_section_banner_duration = 0.0
|
||||||
|
set_process(false)
|
||||||
|
queue_redraw()
|
||||||
|
|
||||||
|
|
||||||
|
func get_section_banner_text() -> String:
|
||||||
|
return _section_banner_text
|
||||||
|
|
||||||
|
|
||||||
|
func get_section_banner_alpha() -> float:
|
||||||
|
return _banner_alpha()
|
||||||
|
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
if _section_banner_text.is_empty() or _section_banner_duration <= 0.0:
|
||||||
|
set_process(false)
|
||||||
|
return
|
||||||
|
_section_banner_elapsed += delta
|
||||||
|
_section_banner_remaining = maxf(
|
||||||
|
_section_banner_duration - _section_banner_elapsed,
|
||||||
|
0.0
|
||||||
|
)
|
||||||
|
if _section_banner_remaining <= 0.0:
|
||||||
|
hide_section_banner()
|
||||||
|
return
|
||||||
|
queue_redraw()
|
||||||
|
|
||||||
|
|
||||||
|
func _banner_alpha() -> float:
|
||||||
|
if _section_banner_text.is_empty() or _section_banner_duration <= 0.0:
|
||||||
|
return 0.0
|
||||||
|
var fade_in := clampf(
|
||||||
|
_section_banner_elapsed / SECTION_BANNER_FADE_IN,
|
||||||
|
0.0,
|
||||||
|
1.0
|
||||||
|
)
|
||||||
|
var fade_out := clampf(
|
||||||
|
_section_banner_remaining / SECTION_BANNER_FADE_OUT,
|
||||||
|
0.0,
|
||||||
|
1.0
|
||||||
|
)
|
||||||
|
return minf(fade_in, fade_out)
|
||||||
|
|
||||||
|
|
||||||
## Aborts any in-progress draw/handle gesture and clears the selection.
|
## Aborts any in-progress draw/handle gesture and clears the selection.
|
||||||
func cancel_interaction() -> void:
|
func cancel_interaction() -> void:
|
||||||
_abort_handle_drag()
|
_abort_handle_drag()
|
||||||
|
|
@ -285,6 +360,8 @@ func _draw() -> void:
|
||||||
if _playback_visible:
|
if _playback_visible:
|
||||||
_draw_playback_marker()
|
_draw_playback_marker()
|
||||||
|
|
||||||
|
_draw_section_banner()
|
||||||
|
|
||||||
|
|
||||||
func _draw_center_line() -> void:
|
func _draw_center_line() -> void:
|
||||||
var half_width := _rink.get_half_width()
|
var half_width := _rink.get_half_width()
|
||||||
|
|
@ -431,6 +508,59 @@ func _draw_playback_marker() -> void:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _draw_section_banner() -> void:
|
||||||
|
var alpha := _banner_alpha()
|
||||||
|
if alpha <= 0.0:
|
||||||
|
return
|
||||||
|
var font := ThemeDB.fallback_font
|
||||||
|
var text_size := font.get_string_size(
|
||||||
|
_section_banner_text,
|
||||||
|
HORIZONTAL_ALIGNMENT_LEFT,
|
||||||
|
-1,
|
||||||
|
SECTION_BANNER_FONT_SIZE
|
||||||
|
)
|
||||||
|
var padding := Vector2(20.0, 9.0)
|
||||||
|
var box := Vector2(
|
||||||
|
text_size.x + padding.x * 2.0,
|
||||||
|
SECTION_BANNER_FONT_SIZE + padding.y * 2.0
|
||||||
|
)
|
||||||
|
var rise := (1.0 - smoothstep(0.0, SECTION_BANNER_FADE_IN, _section_banner_elapsed)) * 8.0
|
||||||
|
var top_left := Vector2(
|
||||||
|
(size.x - box.x) * 0.5,
|
||||||
|
SECTION_BANNER_TOP + rise
|
||||||
|
)
|
||||||
|
var rect := Rect2(top_left, box)
|
||||||
|
var background := Color(0.035, 0.065, 0.12, 0.82 * alpha)
|
||||||
|
var border := Color(0.55, 0.72, 0.94, 0.85 * alpha)
|
||||||
|
var accent := Color(0.38, 0.65, 0.98, alpha)
|
||||||
|
var text_color := Color(0.96, 0.98, 1.0, alpha)
|
||||||
|
var shadow := Color(0.0, 0.0, 0.0, 0.35 * alpha)
|
||||||
|
|
||||||
|
draw_rect(Rect2(rect.position + Vector2(2.0, 3.0), rect.size), shadow, true)
|
||||||
|
draw_rect(rect, background, true)
|
||||||
|
draw_rect(rect, border, false, 1.5)
|
||||||
|
draw_rect(
|
||||||
|
Rect2(
|
||||||
|
Vector2(rect.position.x, rect.end.y - 3.0),
|
||||||
|
Vector2(rect.size.x, 3.0)
|
||||||
|
),
|
||||||
|
accent,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
draw_string(
|
||||||
|
font,
|
||||||
|
Vector2(
|
||||||
|
rect.position.x + padding.x,
|
||||||
|
rect.position.y + padding.y + font.get_ascent(SECTION_BANNER_FONT_SIZE)
|
||||||
|
),
|
||||||
|
_section_banner_text,
|
||||||
|
HORIZONTAL_ALIGNMENT_LEFT,
|
||||||
|
-1,
|
||||||
|
SECTION_BANNER_FONT_SIZE,
|
||||||
|
text_color
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
func _draw_section(section: RoutineSection, alpha: float) -> void:
|
func _draw_section(section: RoutineSection, alpha: float) -> void:
|
||||||
var step_px := GHOST_SAMPLE_STEP_PX if alpha < 1.0 else CURVE_SAMPLE_STEP_PX
|
var step_px := GHOST_SAMPLE_STEP_PX if alpha < 1.0 else CURVE_SAMPLE_STEP_PX
|
||||||
for segment: PathSegment in section.segments:
|
for segment: PathSegment in section.segments:
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ var _element_labels: Array[Dictionary] = []
|
||||||
var _custom_labels: Array[Dictionary] = []
|
var _custom_labels: Array[Dictionary] = []
|
||||||
var _items: Array[Dictionary] = []
|
var _items: Array[Dictionary] = []
|
||||||
var _hover_index: int = -1
|
var _hover_index: int = -1
|
||||||
|
var _hover_item_index: int = -1
|
||||||
|
var _default_tooltip := ""
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
|
@ -35,6 +37,7 @@ func _ready() -> void:
|
||||||
"Klick: Timeline-Label hinzufügen · "
|
"Klick: Timeline-Label hinzufügen · "
|
||||||
+ "Klick auf ein goldenes Label: bearbeiten"
|
+ "Klick auf ein goldenes Label: bearbeiten"
|
||||||
)
|
)
|
||||||
|
_default_tooltip = tooltip_text
|
||||||
resized.connect(_rebuild_items)
|
resized.connect(_rebuild_items)
|
||||||
_rebuild_items()
|
_rebuild_items()
|
||||||
|
|
||||||
|
|
@ -76,8 +79,39 @@ func get_display_items() -> Array[Dictionary]:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
## Track time of the label under [param position], or -1 outside a label.
|
||||||
|
func get_label_time_at(position: Vector2) -> float:
|
||||||
|
var index := _item_index_at(position)
|
||||||
|
if index < 0:
|
||||||
|
return -1.0
|
||||||
|
return float(_items[index].get("time_seconds", -1.0))
|
||||||
|
|
||||||
|
|
||||||
|
## Tooltip for the label under [param position]; falls back to the lane hint.
|
||||||
|
func get_tooltip_at(position: Vector2) -> String:
|
||||||
|
var index := _item_index_at(position)
|
||||||
|
if index < 0:
|
||||||
|
return _default_tooltip
|
||||||
|
var item: Dictionary = _items[index]
|
||||||
|
var time_text := format_time(float(item.get("time_seconds", 0.0)))
|
||||||
|
if bool(item.get("custom", false)):
|
||||||
|
return "Label: %s\nZeit: %s" % [str(item.get("display", "")), time_text]
|
||||||
|
return "%s · %s" % [
|
||||||
|
str(item.get("display", "")),
|
||||||
|
time_text,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
static func format_time(time_seconds: float) -> String:
|
||||||
|
return ("%.1f s" % time_seconds).replace(".", ",")
|
||||||
|
|
||||||
|
|
||||||
func _rebuild_items() -> void:
|
func _rebuild_items() -> void:
|
||||||
_items.clear()
|
_items.clear()
|
||||||
|
_hover_index = -1
|
||||||
|
_hover_item_index = -1
|
||||||
|
mouse_default_cursor_shape = Control.CURSOR_ARROW
|
||||||
|
tooltip_text = _default_tooltip
|
||||||
if _duration <= 0.0:
|
if _duration <= 0.0:
|
||||||
queue_redraw()
|
queue_redraw()
|
||||||
return
|
return
|
||||||
|
|
@ -211,14 +245,19 @@ func _draw() -> void:
|
||||||
|
|
||||||
func _gui_input(event: InputEvent) -> void:
|
func _gui_input(event: InputEvent) -> void:
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
var hovered := _custom_index_at(event.position.x)
|
var item_index := _item_index_at(event.position)
|
||||||
if hovered != _hover_index:
|
if item_index != _hover_item_index:
|
||||||
_hover_index = hovered
|
_hover_item_index = item_index
|
||||||
|
var custom_index := -1
|
||||||
|
if item_index >= 0 and bool(_items[item_index]["custom"]):
|
||||||
|
custom_index = int(_items[item_index]["index"])
|
||||||
|
_hover_index = custom_index
|
||||||
mouse_default_cursor_shape = (
|
mouse_default_cursor_shape = (
|
||||||
Control.CURSOR_POINTING_HAND
|
Control.CURSOR_POINTING_HAND
|
||||||
if hovered >= 0
|
if custom_index >= 0
|
||||||
else Control.CURSOR_ARROW
|
else Control.CURSOR_ARROW
|
||||||
)
|
)
|
||||||
|
tooltip_text = get_tooltip_at(event.position)
|
||||||
queue_redraw()
|
queue_redraw()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -238,12 +277,36 @@ func _gui_input(event: InputEvent) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _notification(what: int) -> void:
|
func _notification(what: int) -> void:
|
||||||
if what == NOTIFICATION_MOUSE_EXIT and _hover_index >= 0:
|
if what == NOTIFICATION_MOUSE_EXIT:
|
||||||
_hover_index = -1
|
_hover_index = -1
|
||||||
|
_hover_item_index = -1
|
||||||
mouse_default_cursor_shape = Control.CURSOR_ARROW
|
mouse_default_cursor_shape = Control.CURSOR_ARROW
|
||||||
|
tooltip_text = _default_tooltip
|
||||||
queue_redraw()
|
queue_redraw()
|
||||||
|
|
||||||
|
|
||||||
|
func _item_index_at(position: Vector2) -> int:
|
||||||
|
var best_index := -1
|
||||||
|
var best_distance := 100000.0
|
||||||
|
for index: int in range(_items.size()):
|
||||||
|
var item: Dictionary = _items[index]
|
||||||
|
var x := float(item["x"])
|
||||||
|
var baseline := size.y - 5.0 - float(int(item["row"])) * ROW_HEIGHT
|
||||||
|
var origin := Vector2(x + 2.0, baseline)
|
||||||
|
var local := (position - origin).rotated(-ROTATION)
|
||||||
|
var width := float(item["width"])
|
||||||
|
if local.x < -4.0 or local.x > width + 8.0:
|
||||||
|
continue
|
||||||
|
if local.y < -FONT_SIZE - 6.0 or local.y > 6.0:
|
||||||
|
continue
|
||||||
|
var center := Vector2(width * 0.5, -FONT_SIZE * 0.5)
|
||||||
|
var distance := (local - center).length_squared()
|
||||||
|
if distance < best_distance:
|
||||||
|
best_distance = distance
|
||||||
|
best_index = index
|
||||||
|
return best_index
|
||||||
|
|
||||||
|
|
||||||
func _custom_index_at(x: float) -> int:
|
func _custom_index_at(x: float) -> int:
|
||||||
var best_index := -1
|
var best_index := -1
|
||||||
var best_distance := 100000.0
|
var best_distance := 100000.0
|
||||||
|
|
|
||||||
21
rinkplanner/sync_apps.example.cfg
Normal file
21
rinkplanner/sync_apps.example.cfg
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
; Vorlage für die OAuth-App-Zugänge von Rinkplanner.
|
||||||
|
;
|
||||||
|
; Diese Werte gehören zur App, nicht zu einem Nutzerkonto. Jeder Nutzer
|
||||||
|
; autorisiert später sein eigenes Google-/Dropbox-Konto; die App speichert nur
|
||||||
|
; dessen Refresh-Token lokal unter user://sync.cfg.
|
||||||
|
;
|
||||||
|
; Die Datei wird beim Build als res://sync_apps.cfg eingebettet. Für die
|
||||||
|
; Entwicklung kann sie auch unter user://sync_apps.cfg liegen oder über
|
||||||
|
; Umgebungsvariablen gesetzt werden (siehe docs/cloud-setup.md).
|
||||||
|
;
|
||||||
|
; Wichtig: ConfigFile-Kommentare beginnen mit ';'. Werte sind Strings und
|
||||||
|
; müssen in Anführungszeichen stehen.
|
||||||
|
;
|
||||||
|
; Nicht mit echten Werten einchecken: rinkplanner/sync_apps.cfg ist in
|
||||||
|
; .gitignore eingetragen. docs/credentials.txt bleibt die Entwicklerdatei.
|
||||||
|
|
||||||
|
[apps]
|
||||||
|
google_client_id=""
|
||||||
|
google_client_secret=""
|
||||||
|
dropbox_app_key=""
|
||||||
|
dropbox_app_secret=""
|
||||||
|
|
@ -64,7 +64,7 @@ $GODOT --headless --path rinkplanner --script res://tests/run_touch_tests.gd
|
||||||
# Run canvas performance stress test
|
# Run canvas performance stress test
|
||||||
$GODOT --headless --path rinkplanner --script res://tests/run_perf_tests.gd
|
$GODOT --headless --path rinkplanner --script res://tests/run_perf_tests.gd
|
||||||
|
|
||||||
# Run FTP sync planning/parser/settings tests
|
# Run cloud sync planning/helper/settings tests
|
||||||
$GODOT --headless --path rinkplanner --script res://tests/run_sync_tests.gd
|
$GODOT --headless --path rinkplanner --script res://tests/run_sync_tests.gd
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,18 @@ func _run() -> void:
|
||||||
controller.rink_canvas.get_playback_section_id() == section_one.section_id,
|
controller.rink_canvas.get_playback_section_id() == section_one.section_id,
|
||||||
"canvas highlights the playing section"
|
"canvas highlights the playing section"
|
||||||
)
|
)
|
||||||
|
_check(
|
||||||
|
controller.rink_canvas.get_section_banner_text() == section_one.title,
|
||||||
|
"section banner names the section at playback"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
controller._section_buttons[section_one.section_id].text.begins_with("▶ "),
|
||||||
|
"section list marks the playing section"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
controller._section_buttons[section_two.section_id].button_pressed,
|
||||||
|
"section list keeps the editing selection"
|
||||||
|
)
|
||||||
|
|
||||||
controller.seek_playback(3.0)
|
controller.seek_playback(3.0)
|
||||||
_check_vec(
|
_check_vec(
|
||||||
|
|
@ -167,6 +179,23 @@ func _run() -> void:
|
||||||
controller.rink_canvas.get_playback_section_id() == section_two.section_id,
|
controller.rink_canvas.get_playback_section_id() == section_two.section_id,
|
||||||
"canvas highlights the second section"
|
"canvas highlights the second section"
|
||||||
)
|
)
|
||||||
|
_check(
|
||||||
|
controller.rink_canvas.get_section_banner_text() == section_two.title,
|
||||||
|
"section banner follows the new section"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
controller._section_buttons[section_two.section_id].text.begins_with("▶ "),
|
||||||
|
"section list marks the second section"
|
||||||
|
)
|
||||||
|
controller.rink_canvas._process(2.1)
|
||||||
|
_check(
|
||||||
|
controller.rink_canvas.get_section_banner_text().is_empty(),
|
||||||
|
"section banner fades out within two seconds"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
controller.rink_canvas.get_section_banner_alpha() == 0.0,
|
||||||
|
"faded section banner has no alpha"
|
||||||
|
)
|
||||||
|
|
||||||
controller.play_button.pressed.emit()
|
controller.play_button.pressed.emit()
|
||||||
_check(controller.is_playing(), "play button starts playback")
|
_check(controller.is_playing(), "play button starts playback")
|
||||||
|
|
@ -318,6 +347,38 @@ func _run() -> void:
|
||||||
_check(has_spin_caption, "spin caption appears without a free-text label")
|
_check(has_spin_caption, "spin caption appears without a free-text label")
|
||||||
_check(has_zero_caption, "zero-duration element stays on the timeline")
|
_check(has_zero_caption, "zero-duration element stays on the timeline")
|
||||||
|
|
||||||
|
# Hovering an element label exposes its track time as a tooltip.
|
||||||
|
controller.timeline_label_lane.size = Vector2(600.0, 44.0)
|
||||||
|
controller.timeline_label_lane._rebuild_items()
|
||||||
|
var hover_item: Dictionary = {}
|
||||||
|
for item: Dictionary in controller.timeline_label_lane.get_display_items():
|
||||||
|
if not bool(item["custom"]):
|
||||||
|
hover_item = item
|
||||||
|
break
|
||||||
|
_check(not hover_item.is_empty(), "element label can be hovered")
|
||||||
|
if not hover_item.is_empty():
|
||||||
|
var hover_x := float(hover_item["x"]) + 4.0
|
||||||
|
var hover_y := (
|
||||||
|
controller.timeline_label_lane.size.y
|
||||||
|
- 5.0
|
||||||
|
- float(int(hover_item["row"])) * 16.0
|
||||||
|
- 5.0
|
||||||
|
)
|
||||||
|
var hover_position := Vector2(hover_x, hover_y)
|
||||||
|
_check_approx(
|
||||||
|
controller.timeline_label_lane.get_label_time_at(hover_position),
|
||||||
|
float(hover_item["time_seconds"]),
|
||||||
|
"hovering an element label yields its track time"
|
||||||
|
)
|
||||||
|
var tooltip := controller.timeline_label_lane.get_tooltip_at(hover_position)
|
||||||
|
_check(
|
||||||
|
not tooltip.contains("Zeit im Track")
|
||||||
|
and tooltip.contains(
|
||||||
|
TimelineLabelLane.format_time(float(hover_item["time_seconds"]))
|
||||||
|
),
|
||||||
|
"element label tooltip contains only label and track time"
|
||||||
|
)
|
||||||
|
|
||||||
_check(
|
_check(
|
||||||
controller.add_timeline_label(5.0, "Musikstart"),
|
controller.add_timeline_label(5.0, "Musikstart"),
|
||||||
"custom timeline label is added"
|
"custom timeline label is added"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
extends SceneTree
|
extends SceneTree
|
||||||
|
|
||||||
## Headless tests for the manual FTP sync: planning rules, conflict naming,
|
## Headless tests for the cloud sync: planning rules, conflict naming, state
|
||||||
## state persistence, protocol parsing and the settings UI wiring.
|
## persistence, OAuth/PKCE helpers, provider path conventions and the settings
|
||||||
|
## UI wiring.
|
||||||
##
|
##
|
||||||
## Run with:
|
## Run with:
|
||||||
## godot --headless --path rinkplanner --script res://tests/run_sync_tests.gd
|
## godot --headless --path rinkplanner --script res://tests/run_sync_tests.gd
|
||||||
|
|
@ -19,7 +20,8 @@ func _init() -> void:
|
||||||
func _run() -> void:
|
func _run() -> void:
|
||||||
_test_plan()
|
_test_plan()
|
||||||
_test_naming()
|
_test_naming()
|
||||||
_test_parsers()
|
_test_cloud_helpers()
|
||||||
|
_test_app_config()
|
||||||
_test_state_roundtrip()
|
_test_state_roundtrip()
|
||||||
await _test_controller_wiring()
|
await _test_controller_wiring()
|
||||||
_finish()
|
_finish()
|
||||||
|
|
@ -55,17 +57,17 @@ func _test_plan() -> void:
|
||||||
actions[entry["name"]] = entry["action"]
|
actions[entry["name"]] = entry["action"]
|
||||||
|
|
||||||
_check(actions.get("neu.json") == SyncPlan.Action.UPLOAD, "nur lokal wird hochgeladen")
|
_check(actions.get("neu.json") == SyncPlan.Action.UPLOAD, "nur lokal wird hochgeladen")
|
||||||
_check(actions.get("server-neu.json") == SyncPlan.Action.DOWNLOAD, "nur Server wird geladen")
|
_check(actions.get("server-neu.json") == SyncPlan.Action.DOWNLOAD, "nur Cloud wird geladen")
|
||||||
_check(
|
_check(
|
||||||
actions.get("beide.json") == SyncPlan.Action.CONFLICT,
|
actions.get("beide.json") == SyncPlan.Action.CONFLICT,
|
||||||
"beidseitige Änderung ist ein Konflikt"
|
"beidseitige Änderung ist ein Konflikt"
|
||||||
)
|
)
|
||||||
_check(actions.get("lokal.json") == SyncPlan.Action.UPLOAD, "lokale Änderung wird hochgeladen")
|
_check(actions.get("lokal.json") == SyncPlan.Action.UPLOAD, "lokale Änderung wird hochgeladen")
|
||||||
_check(actions.get("server.json") == SyncPlan.Action.DOWNLOAD, "Server-Änderung wird geladen")
|
_check(actions.get("server.json") == SyncPlan.Action.DOWNLOAD, "Cloud-Änderung wird geladen")
|
||||||
_check(actions.get("gleich.json") == SyncPlan.Action.SKIP, "unverändert wird übersprungen")
|
_check(actions.get("gleich.json") == SyncPlan.Action.SKIP, "unverändert wird übersprungen")
|
||||||
_check(
|
_check(
|
||||||
actions.get("entfernt.json") == SyncPlan.Action.SKIP,
|
actions.get("entfernt.json") == SyncPlan.Action.SKIP,
|
||||||
"Server-Datei verschwunden: nicht wiederherstellen"
|
"Cloud-Datei verschwunden: nicht wiederherstellen"
|
||||||
)
|
)
|
||||||
|
|
||||||
var first_sync := SyncPlan.build(
|
var first_sync := SyncPlan.build(
|
||||||
|
|
@ -75,7 +77,7 @@ func _test_plan() -> void:
|
||||||
)
|
)
|
||||||
_check(
|
_check(
|
||||||
first_sync.size() == 1 and first_sync[0]["action"] == SyncPlan.Action.TAKE_SERVER,
|
first_sync.size() == 1 and first_sync[0]["action"] == SyncPlan.Action.TAKE_SERVER,
|
||||||
"erster Abgleich ohne Stand übernimmt die Serverfassung"
|
"erster Abgleich ohne Stand übernimmt die Cloud-Fassung"
|
||||||
)
|
)
|
||||||
|
|
||||||
var local_deleted := SyncPlan.build(
|
var local_deleted := SyncPlan.build(
|
||||||
|
|
@ -140,26 +142,129 @@ func _test_naming() -> void:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func _test_parsers() -> void:
|
func _test_cloud_helpers() -> void:
|
||||||
var pasv := FtpClient.parse_pasv("227 Entering Passive Mode (10,1,2,3,200,10)")
|
var url := CloudHttp.parse_url(
|
||||||
_check(
|
"https://api.dropboxapi.com/2/files/list_folder?limit=10"
|
||||||
pasv.get("host") == "10.1.2.3" and pasv.get("port") == 200 * 256 + 10,
|
|
||||||
"PASV-Antwort wird geparst"
|
|
||||||
)
|
)
|
||||||
_check(
|
_check(
|
||||||
FtpClient.parse_epsv("229 Entering Extended Passive Mode (|||6446|)") == 6446,
|
url.get("scheme") == "https"
|
||||||
"EPSV-Antwort wird geparst"
|
and url.get("host") == "api.dropboxapi.com"
|
||||||
|
and int(url.get("port", 0)) == 443
|
||||||
|
and url.get("path") == "/2/files/list_folder?limit=10",
|
||||||
|
"HTTPS-URL wird zerlegt"
|
||||||
|
)
|
||||||
|
var loopback := CloudHttp.parse_url("http://127.0.0.1:53682/callback")
|
||||||
|
_check(
|
||||||
|
loopback.get("host") == "127.0.0.1"
|
||||||
|
and int(loopback.get("port", 0)) == 53682,
|
||||||
|
"Loopback-URL mit Port wird zerlegt"
|
||||||
|
)
|
||||||
|
_check(CloudHttp.parse_url("ftp://example.org").is_empty(), "FTP-URL wird abgelehnt")
|
||||||
|
_check(
|
||||||
|
CloudHttp.resolve_url("https://api.example.org/a/b", "/c/d")
|
||||||
|
== "https://api.example.org:443/c/d",
|
||||||
|
"absolute Weiterleitung wird aufgelöst"
|
||||||
)
|
)
|
||||||
_check(
|
_check(
|
||||||
FtpClient.parse_epsv("229 Entering Extended Passive Mode (|||)") == -1,
|
CloudHttp.resolve_url("https://api.example.org/a/b", "c")
|
||||||
"ungültige EPSV-Antwort liefert -1"
|
== "https://api.example.org:443/a/c",
|
||||||
|
"relative Weiterleitung wird aufgelöst"
|
||||||
)
|
)
|
||||||
var expected := int(Time.get_unix_time_from_datetime_string("2026-10-30T09:48:28"))
|
|
||||||
_check(
|
_check(
|
||||||
FtpClient.parse_mdtm("20261030094828") == expected,
|
CloudHttp.json_stringify_ascii({"name": "Kür"}).contains("\\u00fc"),
|
||||||
"MDTM wird als Unix-Zeit gelesen"
|
"Header-JSON escaped Umlaute"
|
||||||
)
|
)
|
||||||
_check(FtpClient.parse_mdtm("kaputt") == -1, "ungültiges MDTM liefert -1")
|
|
||||||
|
# RFC 7636, Appendix B.
|
||||||
|
var verifier := "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
|
||||||
|
_check(
|
||||||
|
CloudOAuthJob.pkce_challenge(verifier)
|
||||||
|
== "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
|
||||||
|
"PKCE S256 entspricht dem Referenzwert"
|
||||||
|
)
|
||||||
|
var generated := CloudOAuthJob.new_verifier()
|
||||||
|
_check(
|
||||||
|
generated.length() >= 43 and not generated.contains("="),
|
||||||
|
"PKCE-Verifier ist lang genug und ohne Padding"
|
||||||
|
)
|
||||||
|
var authorize := CloudOAuthJob.dropbox_authorize_url("app-key", verifier)
|
||||||
|
_check(
|
||||||
|
authorize.contains("client_id=app-key")
|
||||||
|
and authorize.contains("token_access_type=offline")
|
||||||
|
and authorize.contains("code_challenge_method=S256")
|
||||||
|
and not authorize.contains("redirect_uri"),
|
||||||
|
"Dropbox-Autorisierungs-URL nutzt Offline-Zugriff und PKCE"
|
||||||
|
)
|
||||||
|
|
||||||
|
_check(
|
||||||
|
DropboxStore.remote_path("", "kuer.json") == "/kuer.json",
|
||||||
|
"Dropbox-Pfad im App-Ordner"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
DropboxStore.remote_path("/Rinkplanner", "kuer.json")
|
||||||
|
== "/Rinkplanner/kuer.json",
|
||||||
|
"Dropbox-Pfad im Unterordner"
|
||||||
|
)
|
||||||
|
var content_headers := DropboxStore.content_headers("token", {"path": "/kuer.json"})
|
||||||
|
var content_type_count := 0
|
||||||
|
for value: String in content_headers:
|
||||||
|
if value.to_lower().begins_with("content-type:"):
|
||||||
|
content_type_count += 1
|
||||||
|
_check(
|
||||||
|
content_type_count == 1,
|
||||||
|
"Dropbox-Content-Request hat genau einen Content-Type"
|
||||||
|
)
|
||||||
|
var dropbox_time := DropboxStore.parse_timestamp("2026-11-09T12:34:56Z")
|
||||||
|
_check(dropbox_time > 0, "Dropbox-Zeitstempel wird gelesen")
|
||||||
|
_check(DropboxStore.parse_timestamp("kaputt") == -1, "ungültiger Dropbox-Zeitstempel liefert -1")
|
||||||
|
|
||||||
|
var google_time := GoogleDriveStore.parse_timestamp("2026-11-09T12:34:56.123Z")
|
||||||
|
_check(google_time == dropbox_time, "Google-Zeitstempel wird ohne Millisekunden gelesen")
|
||||||
|
_check(
|
||||||
|
GoogleDriveStore.escape_query("O'Brien") == "O\\'Brien",
|
||||||
|
"Google-Drive-Suchtext wird escaped"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _test_app_config() -> void:
|
||||||
|
var path := "user://test_sync_apps.cfg"
|
||||||
|
var config := ConfigFile.new()
|
||||||
|
config.set_value("apps", "google_client_id", "gid")
|
||||||
|
config.set_value("apps", "google_client_secret", "gsecret")
|
||||||
|
config.set_value("apps", "dropbox_app_key", "dkey")
|
||||||
|
config.save(path)
|
||||||
|
var app := SyncAppConfig.read_file(path)
|
||||||
|
_check(app["google_client_id"] == "gid", "App-Konfiguration liest Google-Client-ID")
|
||||||
|
_check(app["dropbox_app_key"] == "dkey", "App-Konfiguration liest Dropbox-App-Key")
|
||||||
|
_check(SyncAppConfig.is_configured("google_drive", app), "Google gilt als eingerichtet")
|
||||||
|
_check(SyncAppConfig.is_configured("dropbox", app), "Dropbox gilt als eingerichtet")
|
||||||
|
app["google_client_secret"] = ""
|
||||||
|
_check(not SyncAppConfig.is_configured("google_drive", app), "fehlendes Secret blockiert Google")
|
||||||
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
|
||||||
|
|
||||||
|
# ConfigFile erwartet ';' als Kommentar und Strings in Anführungszeichen.
|
||||||
|
var literal_path := "user://test_sync_apps_literal.cfg"
|
||||||
|
var literal := FileAccess.open(literal_path, FileAccess.WRITE)
|
||||||
|
literal.store_string(
|
||||||
|
"; Kommentar\n\n[apps]\n"
|
||||||
|
+ "google_client_id=\"\"\n"
|
||||||
|
+ "dropbox_app_key=\"key123\"\n"
|
||||||
|
)
|
||||||
|
literal.close()
|
||||||
|
var literal_app := SyncAppConfig.read_file(literal_path)
|
||||||
|
_check(
|
||||||
|
literal_app["dropbox_app_key"] == "key123",
|
||||||
|
"App-Konfiguration liest quoted Strings"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
literal_app["google_client_id"] == "",
|
||||||
|
"leere quoted Strings bleiben leer"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
not SyncAppConfig.is_configured("google_drive", literal_app),
|
||||||
|
"leere Google-Client-ID bleibt unkonfiguriert"
|
||||||
|
)
|
||||||
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(literal_path))
|
||||||
|
|
||||||
|
|
||||||
func _test_state_roundtrip() -> void:
|
func _test_state_roundtrip() -> void:
|
||||||
|
|
@ -173,7 +278,7 @@ func _test_state_roundtrip() -> void:
|
||||||
_check(loaded.size() == 2, "Sync-Stand wird gespeichert und geladen")
|
_check(loaded.size() == 2, "Sync-Stand wird gespeichert und geladen")
|
||||||
_check(
|
_check(
|
||||||
int(loaded.get("kuer.json", {}).get("remote_modify", 0)) == 222,
|
int(loaded.get("kuer.json", {}).get("remote_modify", 0)) == 222,
|
||||||
"Sync-Stand behält die Server-Zeit"
|
"Sync-Stand behält die Cloud-Zeit"
|
||||||
)
|
)
|
||||||
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
|
||||||
|
|
||||||
|
|
@ -211,22 +316,33 @@ func _test_controller_wiring() -> void:
|
||||||
if controller == null:
|
if controller == null:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
var app_config := SyncAppConfig.load_config()
|
||||||
|
var provider := "dropbox"
|
||||||
|
if (
|
||||||
|
not SyncAppConfig.is_configured("dropbox", app_config)
|
||||||
|
and SyncAppConfig.is_configured("google_drive", app_config)
|
||||||
|
):
|
||||||
|
provider = "google_drive"
|
||||||
|
var tokens := {
|
||||||
|
provider: {
|
||||||
|
"refresh_token": "refresh",
|
||||||
|
"access_token": "access",
|
||||||
|
"expires_at": 9999999999,
|
||||||
|
"account": "konto@example.org",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
controller.save_sync_settings({
|
controller.save_sync_settings({
|
||||||
"host": "ftp.example.org",
|
"provider": provider,
|
||||||
"port": 2121,
|
"directory": "Kueren",
|
||||||
"user": "konto",
|
"tokens": tokens,
|
||||||
"password": "geheim",
|
|
||||||
"directory": "rinkplanner",
|
|
||||||
"ftps": false,
|
|
||||||
"verify_certificate": false,
|
|
||||||
})
|
})
|
||||||
var loaded := controller.load_sync_settings()
|
var loaded := controller.load_sync_settings()
|
||||||
_check(loaded["host"] == "ftp.example.org", "Sync-Einstellungen speichern den Host")
|
_check(loaded["provider"] == provider, "Sync-Einstellungen speichern den Anbieter")
|
||||||
_check(int(loaded["port"]) == 2121, "Sync-Einstellungen speichern den Port")
|
_check(loaded["directory"] == "Kueren", "Sync-Einstellungen speichern den Cloud-Ordner")
|
||||||
_check(loaded["ftps"] == false, "Sync-Einstellungen speichern FTPS")
|
|
||||||
_check(
|
_check(
|
||||||
loaded["verify_certificate"] == false,
|
RoutineSync.provider_tokens(loaded, provider).get("refresh_token") == "refresh",
|
||||||
"Sync-Einstellungen speichern die Zertifikatsprüfung"
|
"Sync-Einstellungen speichern den Refresh-Token"
|
||||||
)
|
)
|
||||||
|
|
||||||
controller._open_sync_settings_dialog()
|
controller._open_sync_settings_dialog()
|
||||||
|
|
@ -235,23 +351,39 @@ func _test_controller_wiring() -> void:
|
||||||
"Einstellungsdialog öffnet sich"
|
"Einstellungsdialog öffnet sich"
|
||||||
)
|
)
|
||||||
_check(
|
_check(
|
||||||
controller.sync_host_edit.text == "ftp.example.org",
|
controller._selected_sync_provider() == provider,
|
||||||
"Dialog ist mit den gespeicherten Werten gefüllt"
|
"Dialog wählt den gespeicherten Anbieter"
|
||||||
)
|
)
|
||||||
_check(
|
_check(
|
||||||
controller.sync_password_edit.secret,
|
controller.sync_directory_edit.text == "Kueren",
|
||||||
"Passwortfeld ist verdeckt"
|
"Dialog ist mit dem gespeicherten Ordner gefüllt"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
controller.sync_account_value.text == "konto@example.org",
|
||||||
|
"Dialog zeigt das verbundene Konto"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
controller.sync_connect_button.text == "Trennen",
|
||||||
|
"Verbundenes Konto bietet Trennen an"
|
||||||
)
|
)
|
||||||
controller.sync_settings_dialog.hide()
|
controller.sync_settings_dialog.hide()
|
||||||
|
|
||||||
# Ohne Host öffnet "Jetzt synchronisieren" die Einstellungen statt zu starten.
|
# Ohne Refresh-Token öffnet "Jetzt synchronisieren" die Einstellungen.
|
||||||
controller.save_sync_settings({"host": "", "port": 21, "user": "", "password": ""})
|
controller.save_sync_settings({
|
||||||
|
"provider": "dropbox",
|
||||||
|
"directory": "Rinkplanner",
|
||||||
|
"tokens": {},
|
||||||
|
})
|
||||||
controller.start_sync()
|
controller.start_sync()
|
||||||
_check(
|
_check(
|
||||||
controller.sync_settings_dialog.visible,
|
controller.sync_settings_dialog.visible,
|
||||||
"Sync ohne Zugangsdaten öffnet die Einstellungen"
|
"Sync ohne Cloud-Konto öffnet die Einstellungen"
|
||||||
|
)
|
||||||
|
_check(not controller._sync_running, "ohne Cloud-Konto startet kein Sync")
|
||||||
|
_check(
|
||||||
|
controller.sync_account_value.text == "Nicht verbunden",
|
||||||
|
"Dialog zeigt den fehlenden Account"
|
||||||
)
|
)
|
||||||
_check(not controller._sync_running, "ohne Zugangsdaten startet kein Sync")
|
|
||||||
controller.sync_settings_dialog.hide()
|
controller.sync_settings_dialog.hide()
|
||||||
|
|
||||||
scene.queue_free()
|
scene.queue_free()
|
||||||
|
|
|
||||||
76
tools/sync_apps_config.sh
Executable file
76
tools/sync_apps_config.sh
Executable file
|
|
@ -0,0 +1,76 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Erzeugt rinkplanner/sync_apps.cfg aus docs/credentials.txt.
|
||||||
|
#
|
||||||
|
# Die OAuth-App-Zugänge sind öffentliche App-Identitäten, keine Nutzergeheimnisse.
|
||||||
|
# Sie werden beim Build als res://sync_apps.cfg eingebettet. Die Datei ist
|
||||||
|
# trotzdem gitignored, damit versehentliche Änderungen nicht im Repository landen.
|
||||||
|
#
|
||||||
|
# Aufruf:
|
||||||
|
# ./tools/sync_apps_config.sh
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
CREDENTIALS="$REPO_ROOT/docs/credentials.txt"
|
||||||
|
TARGET="$REPO_ROOT/rinkplanner/sync_apps.cfg"
|
||||||
|
|
||||||
|
if [[ ! -f "$CREDENTIALS" ]]; then
|
||||||
|
echo "FEHLER: $CREDENTIALS fehlt." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Liest den letzten Wert eines KEY=WERT-Eintrags. Bewusst ohne assoziative
|
||||||
|
# Arrays, damit das Skript auch mit dem bash 3.2 von macOS läuft.
|
||||||
|
read_value() {
|
||||||
|
local key="$1"
|
||||||
|
local line
|
||||||
|
line="$(grep -E "^[[:space:]]*${key}[[:space:]]*=" "$CREDENTIALS" | tail -n 1 || true)"
|
||||||
|
if [[ -z "$line" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
local value="${line#*=}"
|
||||||
|
value="${value%$'\r'}"
|
||||||
|
value="$(printf '%s' "$value" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
|
||||||
|
printf '%s' "$value"
|
||||||
|
}
|
||||||
|
|
||||||
|
write_value() {
|
||||||
|
local cfg_key="$1"
|
||||||
|
local cred_key="$2"
|
||||||
|
local value
|
||||||
|
value="$(read_value "$cred_key")"
|
||||||
|
# ConfigFile-Werte sind Godot-Varianten: Strings müssen in Anführungszeichen
|
||||||
|
# stehen, sonst wird z. B. ein App-Key als Identifier geparst.
|
||||||
|
value="${value//\\/\\\\}"
|
||||||
|
value="${value//\"/\\\"}"
|
||||||
|
printf '%s="%s"\n' "$cfg_key" "$value"
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
printf '%s\n' \
|
||||||
|
"; Automatisch erzeugt von tools/sync_apps_config.sh" \
|
||||||
|
"; Nicht einchecken; siehe sync_apps.example.cfg." \
|
||||||
|
"" \
|
||||||
|
"[apps]"
|
||||||
|
write_value google_client_id GOOGLE_CLIENT_ID
|
||||||
|
write_value google_client_secret GOOGLE_CLIENT_SECRET
|
||||||
|
write_value dropbox_app_key DROPBOX_APP_KEY
|
||||||
|
write_value dropbox_app_secret DROPBOX_APP_SECRET
|
||||||
|
} >"$TARGET"
|
||||||
|
|
||||||
|
chmod 600 "$TARGET"
|
||||||
|
echo "Geschrieben: $TARGET"
|
||||||
|
|
||||||
|
missing=0
|
||||||
|
for key in GOOGLE_CLIENT_ID GOOGLE_CLIENT_SECRET DROPBOX_APP_KEY; do
|
||||||
|
if [[ -z "$(read_value "$key")" ]]; then
|
||||||
|
echo "Hinweis: $key ist in docs/credentials.txt leer." >&2
|
||||||
|
missing=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ "$missing" -eq 1 ]]; then
|
||||||
|
echo "Der Cloud-Sync bleibt ohne diese Werte deaktiviert." >&2
|
||||||
|
fi
|
||||||
|
if [[ -n "$(read_value GOOGLE_USER)$(read_value DROPBOX_USER)" ]]; then
|
||||||
|
echo "Hinweis: GOOGLE_USER/PASSWORD und DROPBOX_USER/PASSWORD werden nicht" >&2
|
||||||
|
echo "verwendet. Die Cloud-APIs brauchen OAuth-App-Zugänge, keine Nutzerpasswörter." >&2
|
||||||
|
fi
|
||||||
Loading…
Add table
Add a link
Reference in a new issue