mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 06:56:35 +00:00
feat(transit): let an admin route transit search through Google
Transitous has no GTFS coverage for much of Asia, so a search between two Osaka subway stops finds nothing — the stops are not in the feed at all. Add Google as an optional backend behind an admin setting, reusing the install's existing Places key, and fall back to Transitous whenever no key resolves. Uses the Routes API rather than the legacy Directions endpoint the request named: every other Google call here already speaks the v1/X-Goog-Api-Key family, and Google closed the legacy endpoint to Cloud projects created after March 2025. Google returns walking as turn-by-turn navigation steps where MOTIS returns one leg per walking segment, so consecutive walk steps are coalesced into a single leg — otherwise a finely-sliced walk pushed a real journey past the 20-leg cap and the whole itinerary was dropped. Both responses now name the backend that answered. The fallback is silent by design, which left an empty result ambiguous between "no data here" and "the provider you picked never ran", and the admin panel warns when Google is selected but no key resolves — or when only the admin's own key is set, which serves them and nobody else. Cost shaped the implementation, since Google bills where Transitous does not: both field masks are cut to the cheapest SKU tier that still answers the question, cache TTLs are longer than the Transitous path's, and route alternatives ride along inside the already-billed request. Addresses #1699
This commit is contained in:
committed by
Maurice
parent
8e2840b29d
commit
2a0ceb2687
@@ -110,3 +110,28 @@ export const adminTestNotificationRequestSchema = z.object({
|
||||
inApp: z.union([z.boolean(), z.record(z.string(), z.unknown())]).optional(),
|
||||
});
|
||||
export type AdminTestNotificationRequest = z.infer<typeof adminTestNotificationRequestSchema>;
|
||||
|
||||
// Which backend answers /api/transit (#1699). Transitous stays the default and
|
||||
// the fallback: it is free and keyless, so an install that never opens this
|
||||
// switch — or that picks Google without a key — keeps costing nothing.
|
||||
export const TRANSIT_PROVIDERS = ['transitous', 'google'] as const;
|
||||
export type TransitProvider = (typeof TRANSIT_PROVIDERS)[number];
|
||||
|
||||
export const adminTransitProviderRequestSchema = z.object({
|
||||
provider: z.enum(TRANSIT_PROVIDERS),
|
||||
});
|
||||
export type AdminTransitProviderRequest = z.infer<typeof adminTransitProviderRequestSchema>;
|
||||
|
||||
/**
|
||||
* Which of the three credential slots a third-party key resolved out of —
|
||||
* operator env, the instance-wide row, or the caller's own. The server's
|
||||
* ApiKeySource aliases this rather than restating it: the admin transit
|
||||
* response puts the value on the wire, and two copies of the union would be
|
||||
* exactly the hand-mirrored contract the project forbids.
|
||||
*
|
||||
* `null` on the wire means no key resolved at all.
|
||||
*/
|
||||
export const API_KEY_SOURCES = ['operator-env', 'instance', 'user-row'] as const;
|
||||
export type ApiKeySource = (typeof API_KEY_SOURCES)[number];
|
||||
/** The nullable form the admin transit-provider response carries. */
|
||||
export type TransitKeySource = ApiKeySource | null;
|
||||
|
||||
Reference in New Issue
Block a user