validateMediaUrl static method

bool validateMediaUrl(
  1. String url
)

Validates media URL format.

url is the media URL to validate. Returns true if the URL is valid. Throws MessageException if the URL is invalid.

Implementation

static bool validateMediaUrl(String url) {
  if (url.isEmpty) {
    throw MessageException.invalidContent('Media URL cannot be empty.');
  }

  final uri = Uri.tryParse(url);
  if (uri == null || !uri.hasScheme || !uri.hasAuthority) {
    throw MessageException.invalidContent('Invalid media URL format.');
  }

  // Must be HTTPS except for development environments
  if (uri.scheme != 'https' && uri.host != 'localhost' && !uri.host.startsWith('192.168.')) {
    throw MessageException.invalidContent('Media URL must use HTTPS protocol.');
  }

  return true;
}