27 lines
1.1 KiB
Dart
27 lines
1.1 KiB
Dart
// lib/remote/remote_db_uris.dart
|
|
import 'dart:convert';
|
|
|
|
class RemoteDbUris {
|
|
// Schema personalizzato che non attiva ContentResolver.
|
|
static const _scheme = 'aves-remote';
|
|
|
|
/// Costruisce un URI fittizio univoco e stabile per un elemento remoto.
|
|
/// - Se hai un remoteId (hash/uuid) usa quello (preferibile).
|
|
/// - In alternativa, codifica il remotePath.
|
|
static String make({String? remoteId, String? remotePath}) {
|
|
if (remoteId != null && remoteId.trim().isNotEmpty) {
|
|
// Esempio: aves-remote://rid/<remoteId>
|
|
return '$_scheme://rid/${Uri.encodeComponent(remoteId.trim())}';
|
|
}
|
|
if (remotePath != null && remotePath.trim().isNotEmpty) {
|
|
// Esempio: aves-remote://path/<base64url(remotePath)>
|
|
final b64 = base64Url.encode(utf8.encode(remotePath.trim()));
|
|
return '$_scheme://path/$b64';
|
|
}
|
|
// Estremo fallback (pochissimo probabile)
|
|
return '$_scheme://anon/${DateTime.now().microsecondsSinceEpoch}';
|
|
}
|
|
|
|
/// Riconosce se un uri è fittizio remoto
|
|
static bool isSynthetic(String? uri) => uri != null && uri.startsWith('$_scheme://');
|
|
}
|