Library phase 1: SQLite item library with folders, migration of old files as layers, import split into items
This commit is contained in:
1 parent
4216211a20
commit
ad8b72c3d3
16 files changed
+897
-499
No files matched your search
+36
-45
@@ -31,7 +31,7 @@ opened in a browser.
|
||||
|
||||
| `data/`
|
||||
| Local, gitignored data files, e.g. `offline.pmtiles` and uploaded
|
||||
GPX/FIT files under `data/gpx/`.
|
||||
tracks and points (`library.sqlite`, `library/`, older `gpx/`).
|
||||
|
||||
| `lib/maptool/`
|
||||
| Application code beyond routing: the GPX/FIT parsers and file store.
|
||||
@@ -341,35 +341,39 @@ upload GPX, FIT or GeoJSON files by dragging them in, organize them
|
||||
into folders (also by dragging), and toggle each one on the map
|
||||
individually.
|
||||
|
||||
Storage:: Files are stored as-is under `data/gpx/`, in a
|
||||
folder hierarchy the user manages directly — `Maptool::GpxStore`
|
||||
(`lib/maptool/gpx_store.rb`) provides `save`, `create_folder`,
|
||||
`delete_file`, `delete_folder` and `move`. Every path coming from the
|
||||
client (a folder to create/upload/move into, a file path in a URL) is
|
||||
resolved with `File.expand_path` and checked against the store root
|
||||
before touching the filesystem, so `../..`-style path traversal can't
|
||||
escape `data/gpx/`; `delete_folder` additionally refuses an empty path
|
||||
or one that resolves to the store root itself, so it can never `rm
|
||||
-rf` the whole store.
|
||||
`GET /api/gpx/tree` returns the resulting folder/file tree as JSON,
|
||||
which the panel renders recursively (folders as `<details>`, files as
|
||||
a checkbox, both with a delete button).
|
||||
Storage:: An item-based library in `data/library.sqlite`
|
||||
(`Maptool::Library`, `lib/maptool/library.rb`; full design and the
|
||||
later phases in `docs/library-design.adoc`): folders, and in them
|
||||
points, tracks, routes and shapes, each with a stable id, timestamps,
|
||||
a tombstone on delete and a global change counter (`rev`) for sync.
|
||||
An upload is kept as-is under `data/library/sources/<uuid>/` and split
|
||||
into items; a feature already in the target folder (same fingerprint)
|
||||
isn't added twice. Points from a GPX holding exactly one track carry
|
||||
that track as `parent_id`. Files from before the library (`data/gpx/`,
|
||||
still `GpxStore`) were migrated on first start, each into a subfolder
|
||||
named after it as one `layer` item still drawn from that file —
|
||||
`data/gpx/` itself is never written to any more except to edit notes
|
||||
inside such a layer. Folder paths from the client are split on `/`
|
||||
and `.`/`..` rejected; nothing from the client is a filesystem path.
|
||||
`GET /api/library/tree` returns folders and *nodes* — one checkbox
|
||||
each: a track/route/layer (`item:<id>`, drawn with its child points)
|
||||
or a folder's loose points and shapes (`points:<folder id>`).
|
||||
|
||||
Drag & drop:: The dropzone at the top of the panel accepts one or more
|
||||
`.gpx`/`.fit`/`.geojson` files, or a `.zip` (`POST /api/gpx`,
|
||||
`.gpx`/`.fit`/`.geojson` files, or a `.zip` (`POST /api/library/import`,
|
||||
multipart) into the top level, or click it to browse instead. A
|
||||
`.geojson` file needs no format conversion — it's already the shape
|
||||
`gpx.js` expects — so `GpxStore#geojson` just serves it straight from
|
||||
disk (see "Rendering" below); useful for a file already in this app's
|
||||
own schema, e.g. one exported elsewhere in that shape, or a previous
|
||||
`GET /api/gpx/file` response saved and re-uploaded. A `.zip` —
|
||||
`GET /api/library/node` response saved and re-uploaded. A `.zip` —
|
||||
Garmin's bulk/FIT export format — isn't stored itself:
|
||||
`save_zip_entries` (`app.rb`) expands it with `rubyzip` and saves each
|
||||
`.gpx`/`.fit`/`.geojson` entry it contains individually (flattened —
|
||||
any folder structure inside the zip is discarded), skipping anything
|
||||
else (readme files, etc.) it might hold. An already-uploaded file (a
|
||||
`.gpx-tree__file` row, `draggable`) can be dragged onto a folder to
|
||||
move it there (`POST /api/gpx/move`), or dropped anywhere else in the
|
||||
move it there (`POST /api/library/move`), or dropped anywhere else in the
|
||||
tree to move it back to the top level; an OS file can also be dropped
|
||||
directly onto a folder to upload straight into it. Both drag sources
|
||||
land on the same drop targets and are told apart by a custom
|
||||
@@ -379,29 +383,15 @@ map) gets moved, its map layers are re-added under the new path so it
|
||||
stays visible; if it (or its containing folder) gets deleted, its
|
||||
layers are removed instead.
|
||||
|
||||
Rendering:: Checking a file fetches `GET /api/gpx/file/<path>`, routed
|
||||
by extension to `Maptool::Gpx` or `Maptool::Fit`
|
||||
(`lib/maptool/gpx.rb`/`fit.rb`) for parsing, and both convert to the
|
||||
same GeoJSON `FeatureCollection` shape so the frontend doesn't need to
|
||||
know which format it got. `GpxStore#geojson` caches that conversion
|
||||
alongside the source file (`<path>.geojson`, invalidated by mtime) —
|
||||
REXML parsing a several-thousand-waypoint POI export (a park4night
|
||||
area export, say) can take tens of seconds, and without a cache that
|
||||
cost repeats on every single toggle. `GpxStore#save` also calls
|
||||
`geojson` itself right after writing the file, so that cost is paid
|
||||
once during the upload (covered by the frontend's own "Uploading…"
|
||||
status) instead of on whichever toggle happens to be first — a silent
|
||||
multi-second hang on a checkbox click reads as broken in a way the
|
||||
same wait during an upload doesn't. A file that fails to parse still
|
||||
saves fine either way; the error just surfaces on first view instead.
|
||||
A `.geojson` upload skips this path entirely — `geojson` reads and
|
||||
returns it directly, no cache file, no `Gpx`/`Fit` involved.
|
||||
`GpxStore#save` converting eagerly means `cached` is `true` for
|
||||
almost everything in the tree — the one exception is a `.gpx`/`.fit`
|
||||
dropped straight into `data/gpx/` on the filesystem, bypassing the
|
||||
app, and not yet opened. Badging the common case would just be noise,
|
||||
so the file tree's icon (`PENDING_ICON`, `public/js/icons.js`) marks
|
||||
that exception instead of the (near-universal) ready state.
|
||||
Rendering:: Checking a node fetches `GET /api/library/node/<key>`:
|
||||
its items as one GeoJSON `FeatureCollection` (each feature's
|
||||
`properties.id` is its item id), or for a migrated layer its old file
|
||||
converted by `Maptool::Gpx`/`Maptool::Fit` through `GpxStore#geojson`,
|
||||
which caches that conversion next to the file (`<path>.geojson`,
|
||||
invalidated by mtime) — REXML parsing a several-thousand-waypoint POI
|
||||
export can take tens of seconds. An import pays that parse once, at
|
||||
upload time, under the frontend's "Uploading…" status. A file that
|
||||
fails to parse is rejected at import (422).
|
||||
+
|
||||
The tree always shows a `.gpx`/`.fit` file under its real, as-uploaded
|
||||
name, even once cached — it briefly grew a `.geojson` suffix there
|
||||
@@ -421,11 +411,11 @@ document-level click listener the same way an outside click closes a
|
||||
threaded through `onlyOneSidePanelOpen`. A directly-uploaded `.geojson`
|
||||
keeps its own name and both menu items download the same (identical)
|
||||
content — redundant there, not wrong. Both downloads (`GET
|
||||
/api/gpx/file/<path>?download=original`/`?download=geojson`) require
|
||||
/api/library/node/<key>?download=original`/`?download=geojson`) require
|
||||
login, same as upload/move/delete/create-folder, so the whole button —
|
||||
not just its menu items — is left out of the DOM when logged out
|
||||
rather than shown and failing on click (see "Authentication" below);
|
||||
`GET /api/gpx/file` itself stays open to anyone otherwise (viewing a
|
||||
`GET /api/library/node` itself stays open to anyone otherwise (viewing a
|
||||
file on the map isn't a write action), just not `?download=...` on it.
|
||||
Each menu item is a real `<a href>` (so right-click/middle-click still
|
||||
do something sensible), but a plain navigation would land a logged-out
|
||||
@@ -754,10 +744,11 @@ exposed via Docker/nginx as `map.priesol.net`.
|
||||
|
||||
The GPX store's read endpoints (viewing the map, the folder tree,
|
||||
individual files) are public — anyone with the URL can look. Its write
|
||||
endpoints (`POST /api/gpx`, `POST /api/gpx/folder`, `DELETE
|
||||
/api/gpx/file/*`, `DELETE /api/gpx/folder/*`, `POST /api/gpx/move`)
|
||||
endpoints (`POST /api/library/import`, `POST /api/library/folder`,
|
||||
`DELETE /api/library/node/:key`, `DELETE /api/library/folder/*`,
|
||||
`POST /api/library/move`, `/api/library/notes`)
|
||||
require login, guarded by `require_login!` in `app.rb` — and so does
|
||||
exporting a file (`GET /api/gpx/file/*?download=...`), even though
|
||||
exporting a node (`GET /api/library/node/:key?download=...`), even though
|
||||
plain viewing of that same URL (no `?download`) doesn't; not a write
|
||||
exactly, but treated the same as the others rather than left open.
|
||||
The tree UI (`public/js/gpx.js`) mirrors this: every control for a
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
:toc:
|
||||
:toclevels: 2
|
||||
|
||||
Status: *proposal, not implemented.* Replaces the file-based store behind
|
||||
Status: *phase 1 implemented* (`lib/maptool/library.rb`, see Decisions); phases 2–4 proposed. Replaces the file-based store behind
|
||||
Tracks & Points (`GpxStore`) with an item-based library that OsmAnd, Locus
|
||||
Map and the MapTool web app can all be synced against.
|
||||
|
||||
@@ -306,13 +306,26 @@ removed once nothing uses them.
|
||||
. Android sync client (one direction), then the other direction if the
|
||||
app APIs allow it.
|
||||
|
||||
== Decisions (phase 1)
|
||||
|
||||
* Migration: each old file → a subfolder named after it, holding the
|
||||
file as one `layer` item still drawn from its GeoJSON — not split into
|
||||
points. Splitting a layer into items can come later if needed; new
|
||||
imports are split right away.
|
||||
* Track waypoints: independent points with an optional `parent_id` (the
|
||||
GPX's single track). The tree draws them with their track; Locus can
|
||||
get them loose in the folder, OsmAnd inside the track's GPX. Both apps
|
||||
import a GPX with tracks and points together; neither exports GeoJSON
|
||||
(Locus imports it, OsmAnd doesn't), so exports are GPX.
|
||||
* Simplified against the schema above: no `sources` table (an item's
|
||||
`source_path` points at the stored upload), no `description`/`bbox`
|
||||
columns (in `properties` / computed when needed), folder styling and
|
||||
`item_links` not yet.
|
||||
* Migration runs on first start (no `library.sqlite` yet); `rake
|
||||
library:migrate` re-runs it (idempotent).
|
||||
|
||||
== Open questions
|
||||
|
||||
* Migration: one subfolder per old file, or the file's items flattened
|
||||
into its directory's folder?
|
||||
* Should a recorded track keep its own waypoints as children (GPX-style)
|
||||
or as independent points in the same folder (Locus-style)? Proposed:
|
||||
independent points.
|
||||
* Folder depth over 3 — fine to require Locus Premium?
|
||||
* Does OsmAnd's AIDL API list existing favorites/tracks? Does locus-api
|
||||
read points/tracks by folder? Decides whether direction 2 can be
|
||||
|
||||
Reference in new issue
Block a user