refactor(place-import): file and shared-list readers move into their own domain over one gpx and one kml codec

This commit is contained in:
Maurice
2026-10-10 13:02:42 +02:00
parent dc42fe9a5a
commit 1389fe6984
56 changed files with 1784 additions and 911 deletions
+1 -14
View File
@@ -14,26 +14,13 @@ import { discardBody, exceedsDeclaredLength, readCappedText } from '../../utils/
import { UA, googleFtidFromMapsUrl } from './maps.helpers';
import { AMAP_SHORT_HOSTS, isAmapHost, parseAmapUrl } from './providers/amap.provider';
import { OsmClient } from './providers/osm.client';
import { GOOGLE_SHORT_HOSTS, isGoogleMapsHost } from '../common/google-maps-hosts';
// A Google Maps place page is a few hundred KB; the coordinates sit in the
// embedded map data near the top, so two megabytes is plenty and keeps an
// unbounded body out of memory.
const MAX_MAPS_PAGE_BYTES = 2_000_000;
export const GOOGLE_SHORT_HOSTS = ['goo.gl', 'maps.app.goo.gl'];
/**
* Google Maps lives on every country domain — google.de, maps.google.co.uk,
* google.com.au — so the host is matched by shape. A fixed list of .com hosts
* would quietly stop resolving the ccTLD links people actually paste. The TLD
* labels stay short (2-3 letters, optionally two of them) so that
* `google.evil.com` is not a Google host.
*/
export function isGoogleMapsHost(hostname: string): boolean {
return GOOGLE_SHORT_HOSTS.includes(hostname)
|| /^(www\.|maps\.)?google\.[a-z]{2,3}(\.[a-z]{2})?$/.test(hostname);
}
export interface ResolvedMapsUrl {
lat: number;
lng: number;
+1 -1
View File
@@ -27,7 +27,7 @@ import { NEARBY_DEFAULT_LIMIT, NEARBY_DEFAULT_RADIUS_M, nearbyCacheKey, nearestF
export { readBrandIdentity, readWikiIdentity, type WikiIdentity } from './providers/wiki-identity';
export { withPhotoFetchSlot } from './photo-fetch-slot';
export type { BrandLogo, CommonsCandidate } from './providers/wikimedia.client';
export { GOOGLE_SHORT_HOSTS, isGoogleMapsHost } from './maps-url.resolver';
export { GOOGLE_SHORT_HOSTS, isGoogleMapsHost } from '../common/google-maps-hosts';
export { PLACES_PROVIDER_SETTING, PLACES_GOOGLE_ONLY_SETTING, type KeyedProvider } from './places-provider.selector';
// Places near a point (#976): cached longer than the POI boxes, because the
@@ -29,6 +29,14 @@ export class PlacePhotoResolver {
private readonly selector: PlacesProviderSelector,
) {}
/**
* The photo for one place: disk hit, negative cache, in-flight dedupe, then
* Google (for a Google id) and Wikimedia, under the shared photo-fetch slots.
*
* @txIndependent cache bookkeeping around network fetches: the stored photo,
* the negative-cache entry and the image_url backfill are each complete on
* their own, and a failed one costs the cache, never the answer.
*/
async resolve(
userId: number,
placeId: string,
@@ -286,6 +286,9 @@ export class GooglePlacesClient {
* download. The outcome tells a place with no photo apart from a call that
* went wrong, because the negative cache keeps the first for a day and the
* second for minutes. Throws only when the transport itself does.
*
* @txIndependent two billed calls with network I/O between them: each counts
* against the daily ceiling on its own, as it is made.
*/
async firstPhoto(placeId: string, apiKey: string): Promise<GooglePhotoOutcome> {
// Fetch details to get the photo name