diff --git a/app.rb b/app.rb index 928f0d6..b7d14b7 100644 --- a/app.rb +++ b/app.rb @@ -191,11 +191,29 @@ module Maptool json paths: paths, tree: GPX_STORE.tree end - # ?download=1 exports the file's GeoJSON as an attachment instead of - # rendering it on the map — the only way to get a .gpx/.fit's converted - # form out of the app, since GpxStore#geojson's cache is otherwise an - # internal implementation detail with no filename of its own to expose. + # ?download=geojson exports the file's GeoJSON as an attachment instead + # of rendering it on the map — the only way to get a .gpx/.fit's + # converted form out of the app, since GpxStore#geojson's cache is + # otherwise an internal implementation detail with no filename of its + # own to expose. ?download=original exports the untouched, as-uploaded + # file instead (a .geojson source's "original" is that same file, so + # the two downloads are identical there — harmless, not special-cased). + # Both gated the same as the other write/manage actions below (upload, + # move, create folder) — viewing a file on the map stays open to + # anyone, exporting it as a file does not. get "/api/gpx/file/*" do + require_login! if params[:download] + + if params[:download] == "original" + begin + path = GPX_STORE.resolve_file(params[:splat].first) + rescue GpxStore::InvalidPath + halt 400 + end + halt 404 unless File.file?(path) + return send_file(path, filename: File.basename(path), disposition: "attachment") + end + begin body = GPX_STORE.geojson(params[:splat].first) rescue GpxStore::InvalidPath diff --git a/docs/architecture.adoc b/docs/architecture.adoc index 361bc60..27f33f6 100644 --- a/docs/architecture.adoc +++ b/docs/architecture.adoc @@ -343,18 +343,29 @@ name instead — `"ride.gpx"` reads as `"ride.gpx.geojson"`, matching the real cache file sitting next to it on disk — since the GeoJSON, not the original, is what's actually rendered on the map from that point on. The original is never deleted or re-parsed once cached, just -not re-shown as itself. Two ways to get that converted form out of the -app as an actual file (`GET /api/gpx/file/?download=1`) — the -cache is otherwise an implementation detail with no name of its own to -expose: the file name itself is a real link (an ``, not a ``, -specifically so clicking it downloads instead of also toggling the -row's checkbox — a native ``/`