[HOT-FIX] Download attachment is failed on iOS (#4405)

This commit is contained in:
Dat Vu
2026-03-24 22:16:43 +07:00
committed by GitHub
parent 6a34e27340
commit 8fff83a735
3 changed files with 130 additions and 6 deletions
+12 -5
View File
@@ -29,6 +29,7 @@ class Attachment with EquatableMixin {
static const String eventICSSubtype = 'ics';
static const String eventCalendarSubtype = 'calendar';
static const String applicationRTFType = 'application/rtf';
static const String _defaultName = 'unknown-attachment';
final PartId? partId;
final Id? blobId;
@@ -72,11 +73,17 @@ class Attachment with EquatableMixin {
}
String generateFileName() {
if (name?.isNotEmpty == true) {
return name!;
} else {
return '${blobId?.value}.${type?.subtype}';
}
final rawName = (name?.trim().isNotEmpty == true)
? name!.trim()
: (blobId != null
? (type?.subtype != null
? '${blobId!.value}.${type!.subtype}'
: blobId!.value)
: _defaultName);
final sanitized = rawName.replaceAll(RegExp(r'[\\/:*?"<>|]'), '_').trim();
// Fall back if sanitized name has no meaningful content (e.g. '???' → '___')
return sanitized.contains(RegExp(r'[^_\s]')) ? sanitized : _defaultName;
}
factory Attachment.fromJson(Map<String, dynamic> json) => _$AttachmentFromJson(json);