Show what's actually cached per-country, with a delete button per row
The only visibility into downloaded data was the whole offline.pmtiles row, and the only delete was "everything" (whole file + whole cache). GET /api/offline-tiles/cache lists what's really in data/geofabrik_cache/ right now — distinct from offline.pmtiles' own meta.sources, which only reflects the last successful build and can disagree with both the current selection and the cache (ticked-but- not-Applied, or built-from-but-since-unticked). The region picker now shows each cached country's size next to its checkbox, with its own delete button (DELETE /api/offline-tiles/cache/:code, already added but unused by the UI until now) — removing just that entry rather than clearing the whole cache.
This commit is contained in:
1 parent
d09d953cbf
commit
78362d51f2
7 files changed
+158
-6
No files matched your search
@@ -438,6 +438,21 @@ class AppTest < Minitest::Test
|
||||
refute_path_exists cache_dir
|
||||
end
|
||||
|
||||
def test_offline_tiles_cache_lists_and_deletes_one_country
|
||||
cache_dir = File.join(Maptool::App::DATA_DIR, "geofabrik_cache")
|
||||
FileUtils.mkdir_p(cache_dir)
|
||||
File.write(File.join(cache_dir, "SK.osm.pbf"), "fake")
|
||||
|
||||
extracts = json_body(request.get("/api/offline-tiles/cache"))["extracts"]
|
||||
assert_equal ["SK"], extracts.map { |e| e["code"] }
|
||||
|
||||
response = request.delete("/api/offline-tiles/cache/SK", **logged_in_env)
|
||||
assert_equal 200, response.status
|
||||
refute_path_exists File.join(cache_dir, "SK.osm.pbf")
|
||||
ensure
|
||||
FileUtils.remove_entry(cache_dir) if cache_dir && Dir.exist?(cache_dir)
|
||||
end
|
||||
|
||||
def test_offline_tiles_delete_is_409_when_a_build_is_running
|
||||
Maptool::PmtilesBuilder.set_selected_regions(Maptool::App::DATA_DIR, ["SK"])
|
||||
gate = Queue.new
|
||||
|
||||
@@ -338,6 +338,23 @@ class PmtilesBuilderTest < Minitest::Test
|
||||
assert_nil Maptool::PmtilesBuilder.terrain_meta(@data_dir)
|
||||
end
|
||||
|
||||
def test_cached_extracts_is_empty_before_any_download
|
||||
assert_empty Maptool::PmtilesBuilder.cached_extracts(@data_dir)
|
||||
end
|
||||
|
||||
# Deliberately still selected — cached_extracts reflects the cache on
|
||||
# disk, not the current selection or the last build's own meta (see
|
||||
# cached_extracts' own comment for why those three can all disagree).
|
||||
def test_cached_extracts_lists_what_was_downloaded
|
||||
select_regions("SK", "AT")
|
||||
Maptool::PmtilesBuilder.build_offline(data_dir: @data_dir, download_extract: fake_download).join
|
||||
|
||||
extracts = Maptool::PmtilesBuilder.cached_extracts(@data_dir)
|
||||
assert_equal %w[AT SK], extracts.map { |e| e["code"] }
|
||||
assert_equal [4, 4], extracts.map { |e| e["size"] } # "fake".bytesize
|
||||
assert_equal ["Wed, 10 Sep 2026 08:00:01 GMT"] * 2, extracts.map { |e| e["last_modified"] }
|
||||
end
|
||||
|
||||
def test_offline_meta_is_nil_before_any_build
|
||||
assert_nil Maptool::PmtilesBuilder.offline_meta(@data_dir)
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user