resolveAssetForImageMessage function
Darwin 上同步 MIME 恒为空且普通文件可能被压缩,GIF 需要异步识别并读取原文件。
Implementation
@visibleForTesting
Future<ResolvedImageAsset?> resolveAssetForImageMessage({
required String? mimeType,
required String? title,
required Future<String?> Function() loadMimeType,
required Future<String?> Function() loadFilePath,
required Future<String?> Function() loadOriginalFilePath,
Future<String?> Function(String path)? detectFormat,
}) async {
final resolvedMimeType =
(mimeType?.isNotEmpty == true ? mimeType : await loadMimeType())
?.toLowerCase();
var isGif =
resolvedMimeType == 'image/gif' ||
title?.toLowerCase().endsWith('.gif') == true;
final path = isGif
? await loadOriginalFilePath() ?? await loadFilePath()
: await loadFilePath();
if (path == null || path.isEmpty) return null;
isGif = isGif || path.toLowerCase().endsWith('.gif');
if (!isGif && resolvedMimeType?.isNotEmpty != true) {
isGif = await (detectFormat ?? ImageUtil.detectImageFormat)(path) == 'gif';
}
return ResolvedImageAsset(path: path, isGif: isGif);
}