cacheGrpcMedia static method

Future<File> cacheGrpcMedia(
  1. MediaItem item,
  2. FileCategory category,
  3. String conversationId
)

Save a gRPC MediaItem to the appropriate cache folder

Implementation

static Future<File> cacheGrpcMedia(
    MediaItem item,
    FileCategory category,
    String conversationId,
    ) async {
  final folderPath = await _getFolder(category);
  final fileName = Uri.parse(item.fileUrl).pathSegments.last;
  final file = File('$folderPath/$fileName');

  if (await file.exists()) {
    if (kDebugMode) {
      print("📦 Loaded from cache: ${file.path}");
    }
    return file;
  }

  if (kDebugMode) {
    print("💾 Saving gRPC media: ${item.fileUrl}");
  }
  await file.writeAsBytes(item.content);
  return file;
}