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

@ -39,20 +39,34 @@ class SocialService {
/// Opens a session against [relayUrls]: one fault-tolerant pool carrying all
/// three transports (offers, messaging, trust). Relays that are down are
/// skipped; throws only when none are reachable. Caller closes it.
Future<SocialSession> openSession(List<String> relayUrls) async {
///
/// [mediaServerUrl] (a Blossom endpoint) enables offer photos: when set, the
/// session exposes a [MediaTransport] to host images. It rides HTTP, not the
/// relay pool, so it's independent of relay reachability.
Future<SocialSession> openSession(
List<String> relayUrls, {
String? mediaServerUrl,
}) async {
final pool = await RelayPool.connect(relayUrls, identity: identity);
return SocialSession(pool);
return SocialSession(pool, mediaServerUrl: mediaServerUrl);
}
}
/// One relay channel with the three transports on top the
/// "one channel, three interfaces" shape, at the app layer.
/// "one channel, three interfaces" shape, at the app layer. Media rides its own
/// HTTP endpoint (Blossom), so it's a fourth transport but not on the channel.
class SocialSession {
SocialSession(this._channel)
SocialSession(this._channel, {String? mediaServerUrl})
: offers = NostrOfferTransport(_channel),
messages = NostrMessageTransport(_channel),
trust = NostrTrustTransport(_channel),
profile = NostrProfileTransport(_channel);
profile = NostrProfileTransport(_channel),
media = (mediaServerUrl != null && mediaServerUrl.trim().isNotEmpty)
? BlossomMediaTransport(
Uri.parse(mediaServerUrl.trim()),
_channel.privateKeyHex,
)
: null;
final NostrChannel _channel;
@ -61,7 +75,14 @@ class SocialSession {
final TrustTransport trust;
final ProfileTransport profile;
Future<void> close() => _channel.close();
/// Hosts offer photos, or null when no media server is configured (offers then
/// publish without images).
final MediaTransport? media;
Future<void> close() async {
await media?.close();
await _channel.close();
}
}
Uint8List _hexToBytes(String hex) {