mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
fix(maps): a place's marker photo is its community picture where it has one
An OSM or index place with a reviewed TREK Community picture showed it in its gallery but only a category pin in the lists and on the map: the marker photo asked Google and Wikimedia, never the community's pictures. It now asks them first, the order the gallery shows them in, and only while the TREK Places API is on.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* The marker photo of a place: Google's first photo for a Google id, otherwise
|
||||
* The marker photo of a place: the first reviewed TREK Community picture of an
|
||||
* index or OSM place, else Google's first photo for a Google id, otherwise
|
||||
* (and as the fallback) a Wikipedia or Commons picture near its coordinates,
|
||||
* cached on disk and served through /api/maps/place-photo/:id/bytes.
|
||||
*
|
||||
@@ -8,6 +9,7 @@
|
||||
* failed" (minutes), the in-flight dedupe of concurrent requests for one place
|
||||
* and the shared photo-fetch slots. MapsService.getPlacePhoto delegates to it.
|
||||
*/
|
||||
import { readEnv } from '../../app-config';
|
||||
import { Places } from '../../db/entities/Places.entity';
|
||||
import type { PlacesRepository } from '../../db/repositories/Places.repository';
|
||||
import { PlaceChangesService } from '../place-changes/place-changes.service';
|
||||
@@ -18,6 +20,7 @@ import { withPhotoFetchSlot } from './photo-fetch-slot';
|
||||
import { PlacesProviderSelector } from './places-provider.selector';
|
||||
import { GooglePlacesClient } from './providers/google-places.provider';
|
||||
import { WikimediaClient } from './providers/wikimedia.client';
|
||||
import { isCommunityPlace, TrekCommunityService } from './trek-community.service';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@@ -31,11 +34,14 @@ export class PlacePhotoResolver {
|
||||
private readonly selector: PlacesProviderSelector,
|
||||
// PLC-14: the picture filled in here is a change of each place it lands on.
|
||||
private readonly changes: PlaceChangesService,
|
||||
private readonly community: TrekCommunityService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* the community's pictures (for an index or OSM place), Google (for a Google
|
||||
* id) and Wikimedia, under the shared photo-fetch slots: the order the place's
|
||||
* own gallery shows them in.
|
||||
*
|
||||
* @txIndependent cache bookkeeping around network fetches: the stored photo,
|
||||
* the negative-cache entry and the image_url backfill are each complete on
|
||||
@@ -125,6 +131,30 @@ export class PlacePhotoResolver {
|
||||
return { attribution: outcome.attribution };
|
||||
};
|
||||
|
||||
// A picture the community took there and a person reviewed, the one the
|
||||
// place's gallery leads with. Only index and OSM places have any, and with
|
||||
// the TREK Places API off nothing leaves for it.
|
||||
const fetchCommunityPhoto = async (): Promise<{ attribution: string | null } | null> => {
|
||||
if (!isCommunityPlace(placeId) || !readEnv().maps.trekPlacesEnabled) return null;
|
||||
const [path] = await this.community.photoPaths(placeId);
|
||||
if (!path) return null;
|
||||
const bytes = await this.community.imageBytes(path);
|
||||
if (!bytes) {
|
||||
providerFailed = true;
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const cached = await this.photoCache.put(placeId, bytes, 'TREK Community');
|
||||
return { attribution: cached.attribution };
|
||||
} catch {
|
||||
providerFailed = true;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const communityPhoto = await fetchCommunityPhoto();
|
||||
if (communityPhoto) return communityPhoto;
|
||||
|
||||
// Prefer the Google photo (higher quality); if Google yields nothing, fall
|
||||
// back to the same coordinate-based Wikipedia/OSM lookup that right-click
|
||||
// places use. Ids Google cannot resolve skip it entirely.
|
||||
|
||||
@@ -14,6 +14,11 @@ export function communityKeyOf(placeId: string): string | null {
|
||||
return match ? `osm:${match[1]}/${match[2]}` : null;
|
||||
}
|
||||
|
||||
/** Whether the TREK Places API can hold community values for the place: an index place or an OSM element. */
|
||||
export function isCommunityPlace(placeId: string): boolean {
|
||||
return placeId.startsWith('gers:') || communityKeyOf(placeId) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The picture store path of a URL the service gave out: as it is when relative,
|
||||
* the path when absolute on the configured service, null for anything else.
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
import { GooglePlacesClient } from '../maps/providers/google-places.provider';
|
||||
import { OsmClient } from '../maps/providers/osm.client';
|
||||
import { WikimediaClient } from '../maps/providers/wikimedia.client';
|
||||
import { communityKeyOf, TrekCommunityService } from '../maps/trek-community.service';
|
||||
import { isCommunityPlace, TrekCommunityService } from '../maps/trek-community.service';
|
||||
import { trekPlacesById } from '../maps/trek-places.client';
|
||||
import { PlacePhotoCacheService } from '../place-photos/place-photo-cache.service';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
@@ -173,11 +173,6 @@ interface CachePayload extends CachedEnrichment {
|
||||
* A sender who puts another number here only makes their own request compute
|
||||
* afresh: nothing of the record is what gets cached.
|
||||
*/
|
||||
/** Whether the TREK Places API can hold community values for the place: an index place or an OSM element. */
|
||||
function isCommunityPlace(placeId: string): boolean {
|
||||
return placeId.startsWith('gers:') || communityKeyOf(placeId) !== null;
|
||||
}
|
||||
|
||||
function communityVersion(placeId: string, details: Record<string, unknown> | null | undefined): number | null {
|
||||
if (!isCommunityPlace(placeId)) return null;
|
||||
const version = details?.community_version;
|
||||
|
||||
Reference in New Issue
Block a user