feat(market): host and publish the cover photo with each offer

Wire the Blossom MediaTransport into publishing: shareable lots carry
their varietyId, publishLots uploads the lot's cover photo and puts the
returned URL on the offer (best-effort — a hosting failure still publishes
the offer, just without a photo). Add a configurable media server (Comunes
default, empty to opt out) to settings and the market advanced config.
This commit is contained in:
vjrj 2026-07-10 21:12:36 +02:00
parent 5bc1715637
commit fa53295439
17 changed files with 280 additions and 22 deletions

View file

@ -17,6 +17,7 @@ class SocialSettings {
static const _areaKey = 'tane.social.area_geohash';
static const _relaysKey = 'tane.social.relays';
static const _searchPrecisionKey = 'tane.social.search_precision';
static const _mediaServerKey = 'tane.social.media_server';
/// How wide "your zone" searches, as a geohash prefix length: 5 ±2.4 km
/// ("very close"), 4 ±20 km ("around here"), 3 ±78 km ("my region").
@ -39,6 +40,11 @@ class SocialSettings {
'wss://relay.primal.net',
];
/// Blossom media server used to host offer photos so peers can see them. The
/// Comunes-run server is the non-commercial default; the user can point this
/// at any Blossom server, or clear it to publish offers without photos.
static const String defaultMediaServer = 'https://blossom.comunes.org';
/// The user's coarse area as a low-precision geohash (may be empty). Set
/// manually or from device location; the transport coarsens it further.
Future<String> areaGeohash() async => (await _store.read(_areaKey)) ?? '';
@ -73,6 +79,18 @@ class SocialSettings {
Future<void> setSearchPrecision(int precision) =>
_store.write(_searchPrecisionKey, '${_clampPrecision(precision)}');
/// The Blossom media server for offer photos. Falls back to
/// [defaultMediaServer] until the user configures one; an explicitly saved
/// empty value turns photo hosting off (offers still publish, without images).
Future<String> mediaServerUrl() async {
final raw = await _store.read(_mediaServerKey);
if (raw == null) return defaultMediaServer; // never configured
return raw.trim();
}
Future<void> setMediaServerUrl(String url) =>
_store.write(_mediaServerKey, url.trim());
int _clampPrecision(int p) => p < minSearchPrecision
? minSearchPrecision
: (p > maxSearchPrecision ? maxSearchPrecision : p);