feat(mobile/upload): upload_format setting + Option A local update from server response
Settings → Sync → Upload format: "Original file" (default) / "Extracted JSON". - raw (default): reads original_path as base64, POSTs to /api/upload/raw; after success, overwrites local detail_json/timeseries_json/geojson/source_hash with the server's DEM-corrected extraction (Option A). Falls back to bas if the file is missing. - bas: POSTs pre-extracted JSON to /api/upload/bas, faster, no DEM correction. Switching modes is safe — the server deduplicates by activity id so a previous raw upload will return status:"duplicate" on a subsequent bas attempt.
This commit is contained in:
+10
-8
@@ -673,6 +673,7 @@ CREATE TABLE settings (
|
||||
| `api_token` | Bearer token for API auth (obtained via Connect, never stored in plaintext long-term) | Both |
|
||||
| `sync_mode` | `"summaries"` (default) or `"full"` — controls whether geojson+timeseries are downloaded during sync | Both |
|
||||
| `sync_upload` | `"true"` or `"false"` — whether to push local activities during sync | Both |
|
||||
| `upload_format` | `"raw"` (default) or `"bas"` — whether to upload the original FIT/GPX/TCX file (server re-extracts with DEM) or the pre-extracted JSON | Both |
|
||||
| `auto_import_path` | Directory to watch for new FIT files | **Android only** |
|
||||
|
||||
---
|
||||
@@ -700,17 +701,18 @@ Implemented in `mobile/db/sync.ts` → `uploadFeed()` / `uploadLocalActivities()
|
||||
|
||||
1. **Reconcile** against the server: fetch `GET /api/feed` and compare its activity IDs against local rows where `synced_at IS NOT NULL`. Any local activity that is marked as synced but absent from the server (e.g. server was wiped) has its `synced_at` cleared so it re-enters the upload queue. This is best-effort — if the feed fetch fails, upload proceeds with whatever is currently queued.
|
||||
2. Query `activities WHERE origin = 'local' AND synced_at IS NULL`.
|
||||
3. For each: parse `detail_json` from the DB row and construct `{ id: row.id, ...detail }`.
|
||||
4. `POST {instance_url}/api/upload/bas` with body `{ activity, timeseries?, geojson? }`.
|
||||
5. On 200 (including `{ status: "duplicate" }`): set `synced_at = unixepoch()`. On error: log to console, count as failed, continue with the next activity.
|
||||
3. For each, choose the upload path based on the `upload_format` setting (default `'raw'`):
|
||||
- **`raw` (default):** if `original_path` is set and the file still exists on disk, read it as base64 and `POST {instance_url}/api/upload/raw { filename, base64 }`. The server re-extracts the file with DEM elevation correction and returns `{ id, detail, timeseries, geojson, source_hash }`. After a successful upload, the local row's `detail_json`, `timeseries_json`, `geojson`, and `source_hash` are updated with the server's better data (Option A). Falls back to `bas` if the file is missing.
|
||||
- **`bas`:** `POST {instance_url}/api/upload/bas { activity, timeseries?, geojson? }` with the pre-extracted JSON from the DB. Faster, but no DEM elevation correction.
|
||||
4. On 200 (including `{ status: "duplicate" }`): set `synced_at = unixepoch()`. On error: log to console, count as failed, continue with next activity.
|
||||
|
||||
The UI shows live progress ("Uploading N / M…") during the batch and reports failures separately ("X uploaded, Y failed").
|
||||
|
||||
The server endpoint (`bincio/serve/server.py` → `POST /api/upload/bas`) accepts
|
||||
pre-extracted BAS JSON rather than raw FIT/GPX/TCX. It writes the activity file,
|
||||
**updates `user_dir/index.json`** with a summary entry (so `merge_all` can include
|
||||
the activity in year shards and the browser feed), writes geojson and timeseries if
|
||||
provided, then calls `merge_all()` + `write_combined_feed()`.
|
||||
**Upload format setting (`upload_format`):** controls whether to prefer the original raw file or the pre-extracted JSON. `raw` is the default and is recommended — it produces DEM-corrected elevation data on the server and back-fills the local copy. Switching between modes is safe: the server deduplicates by activity id, so switching from `raw` to `bas` just results in the server returning `{ status: "duplicate" }` (HTTP 200) and the client marking the activity as synced.
|
||||
|
||||
**Server endpoint for BAS JSON** (`POST /api/upload/bas`): accepts pre-extracted BAS JSON, writes the activity file, updates `user_dir/index.json` with a summary entry (so `merge_all` can include the activity in year shards and the browser feed), writes geojson and timeseries if provided, then calls `merge_all()` + `write_combined_feed()`.
|
||||
|
||||
**Server endpoint for raw files** (`POST /api/upload/raw`): accepts a base64-encoded FIT/GPX/TCX file, runs full server-side extraction with DEM correction, stores the result, updates the index, calls `merge_all()` + `write_combined_feed()`, and returns the full extracted data to the client.
|
||||
|
||||
> **Bug that was fixed:** earlier versions of both `/api/upload/bas` and `/api/upload/raw`
|
||||
> wrote activity files to disk but never updated `user_dir/index.json`. Since `merge_all`
|
||||
|
||||
Reference in New Issue
Block a user