rewritePath static method

Future<String> rewritePath(
  1. String pathUrl
)

Implementation

static Future<String> rewritePath(String pathUrl) async {
  if (pathUrl.startsWith('http')) {
    return pathUrl;
  }
  // First let's try with https://{country}.openfoodfacts.org
  final OpenFoodFactsCountry country = ProductQuery.getCountry();

  String? url = path_lib.join(
    'https://${country.offTag}.openfoodfacts.org',
    pathUrl,
  );

  if (await _testUrl(url)) {
    url = null;
  }

  // If that's not OK, let's try with world.openfoodfacts.org?lc={language}
  if (url == null) {
    final OpenFoodFactsLanguage language = ProductQuery.getLanguage();

    url = path_lib.join('https://world.openfoodfacts.org', pathUrl);

    url = '$url?lc=${language.offTag}';
  }

  return url;
}