dataFromImageDeliveryUrl static method

Map<String, dynamic> dataFromImageDeliveryUrl(
  1. String url
)

Implementation

static Map<String, dynamic> dataFromImageDeliveryUrl(String url) {
  final split = url
      .replaceAll('$uploadImageDeliveryUrl/', '')
      .replaceAll('$imageDeliveryUrl/', '')
      .split('/');
  String? imageDeliveryId = split.isNotEmpty ? split[0] : null,
      imageId = split.length > 1 ? split[1] : null,
      variantName = split.length > 2 ? split[2] : Params.public;

  if (!(url.startsWith(uploadImageDeliveryUrl) ||
          url.startsWith(imageDeliveryUrl)) ||
      imageDeliveryId == null ||
      imageId == null) {
    // throw Exception('Invalid CloudflareImage from url');
    return {};
  }
  return {
    Params.id: imageId,
    Params.imageDeliveryId: imageDeliveryId,
    Params.variantName: variantName,
    Params.variants: [
      '$imageDeliveryUrl/$imageDeliveryId/$imageId/$variantName'
    ]
  };
}