mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Signed-off-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Atish Patel <atish@squareup.com> Co-authored-by: Codex <noreply@openai.com>
48 lines
1.5 KiB
Dart
48 lines
1.5 KiB
Dart
import 'package:http/http.dart' as http;
|
|
|
|
/// Lightweight HTTP context for talking to the Buzz relay.
|
|
///
|
|
/// In the pure-nostr architecture, all data flow happens over the relay
|
|
/// WebSocket. This client now exists only to provide a base URL (and a
|
|
/// shared HTTP client) for the media upload endpoint, which is the one
|
|
/// remaining HTTP path because Blossom uses kind:24242 NIP-98 auth on a
|
|
/// regular HTTP PUT.
|
|
class RelayClient {
|
|
final String baseUrl;
|
|
final http.Client _http;
|
|
|
|
RelayClient({required this.baseUrl, http.Client? httpClient})
|
|
: _http = httpClient ?? http.Client();
|
|
|
|
/// Shared underlying HTTP client (used by [MediaUploader]).
|
|
http.Client get httpClient => _http;
|
|
|
|
/// Fully-qualified URL for the relay's Blossom-style media upload endpoint.
|
|
String get mediaUploadUrl {
|
|
final base = Uri.parse(baseUrl);
|
|
return base.resolve('/upload').toString();
|
|
}
|
|
|
|
void dispose() => _http.close();
|
|
}
|
|
|
|
/// Thrown when an HTTP call to the relay returns a non-2xx status code.
|
|
///
|
|
/// Retained for backwards compatibility with provider code that still
|
|
/// references it during the migration to pure-nostr WebSocket flows.
|
|
class RelayException implements Exception {
|
|
final int statusCode;
|
|
final String body;
|
|
|
|
RelayException(this.statusCode, this.body);
|
|
|
|
@override
|
|
String toString() {
|
|
final trimmedBody = body.trim();
|
|
if (trimmedBody.isEmpty) {
|
|
return 'RelayException($statusCode)';
|
|
}
|
|
return 'RelayException($statusCode): $trimmedBody';
|
|
}
|
|
}
|