feat(image): Improve image attachment loading and error handling

This commit is contained in:
cogwheel
2026-01-13 21:26:43 +05:30
parent 9380c036f5
commit 2b44ae3e5e
6 changed files with 185 additions and 51 deletions

View File

@@ -0,0 +1,22 @@
// Utility functions for handling file data in chat messages.
// Used by both user and assistant message widgets.
/// Checks if a file map represents an image.
/// Matches OpenWebUI behavior: type === 'image' OR content_type starts with 'image/'
bool isImageFile(dynamic file) {
if (file is! Map) return false;
if (file['type'] == 'image') return true;
final contentType = file['content_type']?.toString() ?? '';
return contentType.startsWith('image/');
}
/// Extracts the file URL or ID from a file map.
/// OpenWebUI stores either a full URL, data URL, or just the file ID.
///
/// Returns the URL/ID string, or null if the file has no valid URL.
String? getFileUrl(dynamic file) {
if (file is! Map) return null;
final url = file['url'];
if (url == null) return null;
return url.toString();
}