Let a cached file's GeoJSON be downloaded by clicking its tree name

Once a .gpx/.fit is cached, the tree shows it under its converted name
("ride.gpx" -> "ride.gpx.geojson", matching the real cache file next
to it on disk) instead of still reading as un-converted -- the
GeoJSON is what's actually on the map from that point on, and the
original is never deleted, just not re-shown as itself. The name is
now a real link (GET /api/gpx/file/<path>?download=1) instead of
plain text, the only way to get that converted form out of the app.

Verified in a real browser that an <a> nested in a <label> claims its
own click rather than the label forwarding it to the checkbox, so
downloading and toggling visibility don't fight over the same click.
This commit is contained in:
randy committed 2026-09-07 22:56:46 +02:00
1 parent b4f205667b
commit cd92dadf6a
5 files changed
+70 -4

No files matched your search

+18
View File
@@ -72,6 +72,24 @@ class AppTest < Minitest::Test
assert_equal "Spot", json_body(file_response)["features"][0]["properties"]["name"]
end
def test_download_of_a_converted_gpx_names_it_gpx_geojson
content = File.read(fixture_path("sample.gpx"))
post_file("/api/gpx", filename: "ride.gpx", content: content, env: logged_in_env)
response = request.get("/api/gpx/file/ride.gpx?download=1")
assert_equal 200, response.status
assert_includes response.headers["Content-Disposition"], 'filename="ride.gpx.geojson"'
end
def test_download_of_a_native_geojson_keeps_its_own_name
content = '{"type":"FeatureCollection","features":[]}'
post_file("/api/gpx", filename: "spots.geojson", content: content, env: logged_in_env)
response = request.get("/api/gpx/file/spots.geojson?download=1")
assert_equal 200, response.status
assert_includes response.headers["Content-Disposition"], 'filename="spots.geojson"'
end
def test_unparseable_gpx_returns_422
post_file("/api/gpx", filename: "bad.gpx", content: "<gpx><trk unclosed>", env: logged_in_env)