Files
TREK/server/src/nest/maps/community-overlay.ts
T
Maurice 330644e88b places: show the community's published pictures first in Pick a picture
The service delivers the pictures review approved for a place, but TREK never
read them. A new TrekCommunityService in the maps domain asks the TREK Places
API for them (the index row for a gers place, /v1/community for an OSM one),
accepts only paths of the service's picture store, and fetches the bytes with
the installation's key, capped at 4 MB. Enrichment puts them ahead of Google
and Commons, through the same photo cache, credited as TREK Community under
CC BY 4.0. The enrichment cache now follows the community version for OSM
places too, so a newly approved picture shows on the next open.

Also lowers the client's no-non-null-assertion baseline to 380: moving Use
this text into the description card removed two.
2026-10-31 03:25:56 +00:00

61 lines
2.5 KiB
TypeScript

import { buildOsmDetails } from './maps.helpers';
import { communityKeyOf } from './trek-community.service';
import { trekCommunityByKeys, type TrekCommunityValues } from './trek-places.client';
import { normalizePlaceWebsite } from '@trek/shared';
/**
* Community values for places TREK did not find in its own index: a relation
* Photon returned, a way from Overpass. The index rows carry them already
* (the service lays them over its own answers); these places get them from
* /v1/community, so a value one installation sent shows on the next open of
* the same place everywhere.
*/
/** The details record with what the community published laid over it; untouched where nothing was. */
export function withCommunityValues(
details: Record<string, unknown>,
values: TrekCommunityValues | undefined,
): Record<string, unknown> {
if (!values?.community) return details;
const out: Record<string, unknown> = { ...details };
const website = normalizePlaceWebsite(values.contact?.website);
if (website) out.website = website;
if (values.contact?.phone) out.phone = values.contact.phone;
if (values.contact?.email) out.email = values.contact.email;
if (values.hours?.osm) {
// The same shape OSM's own hours take in the details: one line per day, open now, the periods.
const hours = buildOsmDetails({ opening_hours: values.hours.osm }, '', '');
if (hours.opening_hours) {
out.opening_hours = hours.opening_hours;
out.open_now = hours.open_now;
out.opening_periods = hours.opening_periods;
}
}
if (values.description?.text) {
out.summary = values.description.text;
// The details panel credits it to the community, not to OpenStreetMap.
out.summary_source = 'community';
}
if (typeof values.community.version === 'number') out.community_version = values.community.version;
return out;
}
/** Records built from TREK's own details layer, which carry the community answer already. */
const asked = new WeakSet<object>();
export function markCommunityAsked(details: Record<string, unknown>): Record<string, unknown> {
asked.add(details);
return details;
}
/** OSM details as Overpass and Photon gave them, with the community's values for the same element. */
export async function osmDetailsWithCommunity(
placeId: string,
details: Record<string, unknown> | null,
): Promise<Record<string, unknown> | null> {
const key = communityKeyOf(placeId);
if (!details || !key || asked.has(details)) return details;
const published = await trekCommunityByKeys([key]);
return withCommunityValues(details, published[key]);
}