feat(offline): cache the trip's area so place search works with no network

An offline instance had the trip's own places and nothing else, so "find
a pharmacy near the hotel" had nothing to answer from: every lookup went
to a server.

The index can hand over a bounding box in one request, so it does, once,
next to the map tiles. A trip to Rostock is roughly a megabyte, refreshed
only when the trip's area actually moves. Search and autocomplete fall
back to it at the API layer, which is why all ten call sites got the
offline path without any of them learning about it, and the answer says
`source: 'offline-cache'` rather than pretending to be live.

Country packages stay what they were: a SQLite file for anyone who would
rather run their own copy of the service. A browser cannot query one
without shipping a WASM SQLite, and Germany alone would not fit in
IndexedDB, so that door stays where it belongs. /v1/packages lists them,
because "you can leave" only means something if the door is visible.
This commit is contained in:
Maurice
2026-09-06 00:36:53 +02:00
committed by Maurice
parent 715993feaf
commit 87a765b763
10 changed files with 710 additions and 2 deletions
+31
View File
@@ -105,6 +105,37 @@ export class MapsController {
}
}
/**
* Every place in a box, for the offline cache. Read-only and cheap.
*
* Not a browse endpoint: the index caps the box at 1.5 degrees a side, and
* this passes the cap's refusal straight through rather than paging around
* it. The honest use is one trip's area, taken once.
*/
@Get('area')
async area(
@Query('minLat') minLat?: string,
@Query('minLng') minLng?: string,
@Query('maxLat') maxLat?: string,
@Query('maxLng') maxLng?: string,
@Query('limit') limit?: string,
) {
const bbox = {
minLat: Number(minLat),
minLng: Number(minLng),
maxLat: Number(maxLat),
maxLng: Number(maxLng),
};
if (Object.values(bbox).some((v) => !Number.isFinite(v))) {
throw new HttpException({ error: 'A valid bbox (minLat, minLng, maxLat, maxLng) is required' }, 400);
}
const capped = Math.min(Math.max(Number(limit) || 2000, 1), 5000);
const area = await this.maps.placesInArea(bbox, capped);
// A null means the index is off or unreachable. An empty area is not an
// error — the caller caches nothing and carries on.
return area ?? { results: [], truncated: false, unavailable: true };
}
@Post('autocomplete')
@HttpCode(200)
async autocomplete(