getStoredCDNConfig method

Future<CDNConfig?> getStoredCDNConfig()

Gets stored CDN config from SecureStorage if valid

Implementation

Future<CDNConfig?> getStoredCDNConfig() async {
  try {
    final configStr = await SecureStorage.getSecureData(_configCacheKey);
    final timestampStr = await SecureStorage.getSecureData(_configTimestampKey);

    if (configStr == null || timestampStr == null) {
      return null;
    }

    final timestamp = int.tryParse(timestampStr);
    if (timestamp == null) return null;

    final currentTime = DateTime.now().millisecondsSinceEpoch;

    if (currentTime - timestamp > _cacheDuration) {
      return null;
    }

    return CDNConfig.fromJson(jsonDecode(configStr) as Map<String, dynamic>);
  } catch (error) {
    // ignore: avoid_print
    print('Error getting stored CDN config: $error');
    return null;
  }
}