getPodBaseUrl static method

Future<String?> getPodBaseUrl()

Extract POD base URL from WebID.

Example: https://pods.solidcommunity.au/ profile/card#me Returns: https://pods.solidcommunity.au/

Uses the same approach as solidpod to handle ports and custom paths.

Implementation

static Future<String?> getPodBaseUrl() async {
  final webId = await getWebId();
  if (webId == null) return null;

  // Same method as solidpod: replace profile/card#me with empty string
  // This preserves ports and any other URL components.

  if (!webId.contains(_profCard)) {
    // Fallback to URI parsing if WebID doesn't have standard format.
    final uri = Uri.parse(webId);
    final port = uri.hasPort ? ':${uri.port}' : '';
    return '${uri.scheme}://${uri.host}$port/';
  }

  return webId.replaceAll(_profCard, '');
}