@umituz/react-native-design-system 4.23.100 → 4.23.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/package.json +1 -1
  2. package/src/atoms/AtomicInput.tsx +0 -2
  3. package/src/media/domain/entities/{MultimediaFlashcardTypes.ts → MediaAttachments.ts} +13 -32
  4. package/src/media/index.ts +24 -23
  5. package/src/media/infrastructure/services/MediaGenerationService.ts +1 -1
  6. package/src/media/infrastructure/services/MediaOptimizerService.ts +1 -1
  7. package/src/media/infrastructure/services/MediaUploadService.ts +1 -1
  8. package/src/media/infrastructure/services/MediaValidationService.ts +1 -1
  9. package/src/media/infrastructure/services/MultimediaFlashcardService.ts +1 -1
  10. package/src/media/infrastructure/utils/PermissionManager.ts +1 -1
  11. package/src/media/infrastructure/utils/media-collection-utils.ts +4 -2
  12. package/src/media/infrastructure/utils/mediaPickerMappers.ts +1 -1
  13. package/src/media/presentation/hooks/multimedia.types.ts +1 -1
  14. package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +4 -4
  15. package/src/media/presentation/hooks/useMedia.ts +2 -2
  16. package/src/media/presentation/hooks/useMediaGeneration.ts +1 -1
  17. package/src/media/presentation/hooks/useMediaUpload.ts +1 -1
  18. package/src/media/presentation/hooks/useMediaValidation.ts +1 -1
  19. package/src/media/presentation/hooks/useMultimediaFlashcard.ts +1 -1
  20. package/src/molecules/navigation/utils/AppNavigation.ts +3 -3
  21. package/src/storage/infrastructure/adapters/StorageService.ts +3 -3
  22. package/src/storage/infrastructure/repositories/BaseStorageOperations.ts +5 -5
  23. package/src/storage/presentation/hooks/CacheStorageOperations.ts +3 -3
  24. package/src/storage/presentation/hooks/useStore.ts +0 -1
  25. package/src/media/domain/entities/CardMultimedia.types.README.md +0 -129
  26. package/src/media/domain/entities/Media.README.md +0 -80
  27. package/src/media/domain/entities/MultimediaFlashcardTypes.README.md +0 -144
  28. package/src/media/domain/utils/MediaUtils.README.md +0 -178
  29. package/src/media/index.ts.README.md +0 -191
  30. package/src/media/infrastructure/services/CardMultimediaService.README.md +0 -176
  31. package/src/media/infrastructure/services/CardMultimediaService.ts +0 -98
  32. package/src/media/infrastructure/services/MediaGenerationService.README.md +0 -142
  33. package/src/media/infrastructure/services/MediaOptimizerService.README.md +0 -145
  34. package/src/media/infrastructure/services/MediaPickerService.README.md +0 -106
  35. package/src/media/infrastructure/services/MediaSaveService.README.md +0 -120
  36. package/src/media/infrastructure/services/MediaUploadService.README.md +0 -135
  37. package/src/media/infrastructure/services/MediaValidationService.README.md +0 -135
  38. package/src/media/infrastructure/services/MultimediaFlashcardService.README.md +0 -142
  39. package/src/media/infrastructure/utils/mediaHelpers.README.md +0 -96
  40. package/src/media/infrastructure/utils/mediaPickerMappers.README.md +0 -129
  41. package/src/media/presentation/hooks/card-multimedia.types.README.md +0 -177
  42. package/src/media/presentation/hooks/card-multimedia.types.ts +0 -53
  43. package/src/media/presentation/hooks/multimedia.types.README.md +0 -201
  44. package/src/media/presentation/hooks/useCardMediaGeneration.ts +0 -20
  45. package/src/media/presentation/hooks/useCardMediaUpload.ts +0 -84
  46. package/src/media/presentation/hooks/useCardMediaValidation.ts +0 -104
  47. package/src/media/presentation/hooks/useCardMultimediaFlashcard.README.md +0 -158
  48. package/src/media/presentation/hooks/useMedia.README.md +0 -94
  49. package/src/media/presentation/hooks/useMediaGeneration.README.md +0 -118
  50. package/src/media/presentation/hooks/useMediaUpload.README.md +0 -108
  51. package/src/media/presentation/hooks/useMediaValidation.README.md +0 -134
  52. package/src/media/presentation/hooks/useMultimediaFlashcard.README.md +0 -141
@@ -1,120 +0,0 @@
1
- # MediaSaveService
2
-
3
- ## Purpose
4
- Handles saving image and video files to the device's photo gallery, including album management and permission handling.
5
-
6
- ## File Location
7
- `/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/MediaSaveService`
8
-
9
- ## Strategy
10
-
11
- ### Core Purpose
12
- - Save media files to device gallery
13
- - Create and manage custom albums
14
- - Handle platform-specific save requirements
15
- - Manage write permissions for media library
16
-
17
- ### Usage Scenarios
18
- - Saving downloaded images to gallery
19
- - Creating app-specific albums
20
- - Saving captured media to gallery
21
- - Organizing media into custom collections
22
- - Backup workflows
23
-
24
- ### Integration Points
25
- - After media download completes
26
- - After media generation/creation
27
- - User-initiated save actions
28
- - Batch media save operations
29
-
30
- ## Forbidden
31
-
32
- ### MUST NOT
33
- - Save files without proper write permissions
34
- - Assume album creation always succeeds
35
- - Create duplicate albums with same name
36
- - Overwrite existing media without user consent
37
- - Save invalid or corrupted media files
38
- - Ignore save operation results
39
-
40
- ### MUST NEVER
41
- - Attempt to save when permission is denied
42
- - Assume save operation is instant
43
- - Save to private app storage using this service
44
- - Modify saved media after save operation completes
45
- - Bypass platform-specific save restrictions
46
-
47
- ## Rules
48
-
49
- ### Permission Management
50
- - MUST request write permission before saving
51
- - MUST check permission status before operations
52
- - MUST handle permission denial gracefully
53
- - MUST provide clear error messages for permission issues
54
- - MUST respect user's permission decisions
55
-
56
- ### Save Operations
57
- - MUST validate file URI/path before saving
58
- - MUST determine media type (image/video) correctly
59
- - MUST handle save failures appropriately
60
- - MUST return success/failure status
61
- - MUST include asset ID in successful results
62
-
63
- ### Album Management
64
- - MUST create album automatically if it doesn't exist
65
- - MUST NOT create duplicate albums with same name
66
- - MUST save to default gallery if no album specified
67
- - MUST handle album creation failures
68
- - MUST validate album names
69
-
70
- ### Error Handling
71
- - MUST catch and report save failures
72
- - MUST handle invalid file paths
73
- - MUST handle insufficient storage scenarios
74
- - MUST provide meaningful error messages
75
- - MUST allow retry after permission grant
76
-
77
- ### Platform Considerations
78
- - MUST handle iOS save requirements
79
- - MUST handle Android scoped storage (API 10+)
80
- - MUST account for platform-specific restrictions
81
- - MUST test on both platforms
82
-
83
- ## AI Agent Guidelines
84
-
85
- ### When Implementing Save Operations
86
- 1. Always check permissions before attempting save
87
- 2. Validate file URI/path exists and is accessible
88
- 3. Determine correct media type for the file
89
- 4. Handle both success and failure cases
90
- 5. Provide user feedback for save operations
91
-
92
- ### When Working with Albums
93
- - Check if album exists before creating
94
- - Use consistent album naming
95
- - Handle album creation failures gracefully
96
- - Allow saving to default gallery as fallback
97
-
98
- ### When Adding Features
99
- - Add new media types with proper validation
100
- - Extend save options without breaking changes
101
- - Maintain backward compatibility
102
- - Add error handling for new edge cases
103
-
104
- ### When Refactoring
105
- - Keep public API stable
106
- - Preserve permission handling logic
107
- - Maintain platform-specific behavior
108
- - Don't remove existing save methods without deprecation
109
-
110
- ### Common Patterns to Follow
111
- - Request permission -> Check status -> Validate file -> Save
112
- - Handle result -> Check success -> Return asset ID or error
113
- - Always wrap in try-catch for unexpected errors
114
- - Provide user feedback for save status
115
-
116
- ## Dependencies
117
-
118
- - Domain types: MediaType, MediaLibraryPermission from Media
119
- - External libraries: expo-media-library
120
- - No internal utility dependencies
@@ -1,135 +0,0 @@
1
- # MediaUploadService
2
-
3
- ## Purpose
4
- Manages media file uploads to remote servers, including compression, URL management, and download functionality.
5
-
6
- ## File Location
7
- `/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/MediaUploadService`
8
-
9
- ## Strategy
10
-
11
- ### Core Purpose
12
- - Upload media files to remote storage
13
- - Generate and manage media URLs
14
- - Support compression during upload
15
- - Download media to local storage
16
- - Generate thumbnails automatically
17
-
18
- ### Usage Scenarios
19
- - User-generated content uploads
20
- - Profile picture uploads
21
- - Document/image sharing
22
- - Media backup workflows
23
- - Content delivery networks integration
24
-
25
- ### Integration Points
26
- - Form submissions with media attachments
27
- - Social media sharing features
28
- - Cloud storage synchronization
29
- - Content management systems
30
- - Media delivery pipelines
31
-
32
- ## Forbidden
33
-
34
- ### MUST NOT
35
- - Upload invalid or corrupted files
36
- - Assume network is always available
37
- - Upload without file size limits
38
- - Ignore authentication requirements
39
- - Store sensitive credentials in service
40
- - Generate duplicate URLs for same media
41
-
42
- ### MUST NEVER
43
- - Upload without proper error handling
44
- - Assume upload progress is always available
45
- - Retry failed uploads indefinitely
46
- - Expose sensitive upload endpoints
47
- - Upload without user consent
48
- - Ignore network timeout scenarios
49
-
50
- ## Rules
51
-
52
- ### Upload Operations
53
- - MUST validate file before upload
54
- - MUST handle network errors gracefully
55
- - MUST support compression options
56
- - MUST return unique media ID
57
- - MUST provide upload progress when possible
58
- - MUST handle timeout scenarios
59
-
60
- ### Compression Options
61
- - MUST support quality adjustment (0-1)
62
- - MUST support max width/height constraints
63
- - MUST support format conversion (jpeg/png)
64
- - MUST validate compression parameters
65
- - MUST apply compression before upload
66
-
67
- ### URL Management
68
- - MUST generate unique URLs for each media
69
- - MUST support URL retrieval by media ID
70
- - MUST handle invalid media IDs
71
- - MUST maintain URL consistency
72
- - MUST support URL expiration if required
73
-
74
- ### Download Operations
75
- - MUST validate media ID before download
76
- - MUST handle download failures
77
- - MUST return local file path
78
- - MUST manage storage space
79
- - MUST support large file downloads
80
-
81
- ### Return Values
82
- - MUST include media metadata (type, size, MIME)
83
- - MUST include unique identifier
84
- - MUST include URL (full or relative)
85
- - MUST include thumbnail for applicable types
86
- - MUST include duration for audio/video
87
-
88
- ### Error Handling
89
- - MUST catch network errors
90
- - MUST handle authentication failures
91
- - MUST handle storage quota exceeded
92
- - MUST provide meaningful error messages
93
- - MUST allow retry after failure
94
-
95
- ## AI Agent Guidelines
96
-
97
- ### When Implementing Upload Features
98
- 1. Always validate file metadata before upload
99
- 2. Apply compression options if specified
100
- 3. Generate unique media identifier
101
- 4. Handle network failures gracefully
102
- 5. Return complete media attachment object
103
-
104
- ### When Working with URLs
105
- - Generate unique, predictable URLs
106
- - Support both absolute and relative URLs
107
- - Include media ID in URL structure
108
- - Handle URL generation failures
109
-
110
- ### When Adding Features
111
- - Add new media types with validation
112
- - Extend compression options carefully
113
- - Maintain backward compatibility
114
- - Add progress tracking for large files
115
- - Support batch uploads if needed
116
-
117
- ### When Refactoring
118
- - Keep upload API stable
119
- - Preserve media ID generation logic
120
- - Maintain URL structure consistency
121
- - Don't change return value structure
122
- - Add deprecation warnings for breaking changes
123
-
124
- ### Common Patterns to Follow
125
- - Validate file -> Apply compression -> Upload -> Return attachment
126
- - Handle network errors -> Retry if appropriate -> Return error
127
- - Generate URL -> Store mapping -> Return URL
128
- - Always wrap network operations in try-catch
129
- - Provide user feedback for upload progress
130
-
131
- ## Dependencies
132
-
133
- - Domain types: MediaAttachment, MediaCompressionOptions from MultimediaFlashcardTypes
134
- - Internal utilities: mediaHelpers (generateThumbnail, getMediaDuration, getMediaType)
135
- - No external library dependencies (uses native APIs and fetch)
@@ -1,135 +0,0 @@
1
- # MediaValidationService
2
-
3
- ## Purpose
4
- Validates media files before upload by checking file size, type, and other properties to ensure compatibility and performance.
5
-
6
- ## File Location
7
- `/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/MediaValidationService`
8
-
9
- ## Strategy
10
-
11
- ### Core Purpose
12
- - Validate media files before upload
13
- - Check file size constraints
14
- - Verify supported file types
15
- - Provide actionable feedback (errors, warnings, recommendations)
16
- - Prevent upload of invalid or problematic files
17
-
18
- ### Usage Scenarios
19
- - Pre-upload validation checks
20
- - Form submission workflows
21
- - File selection validation
22
- - User feedback on file issues
23
- - Quality control processes
24
-
25
- ### Integration Points
26
- - Before upload operations
27
- - After file selection
28
- - In form validation workflows
29
- - User input feedback loops
30
- - File processing pipelines
31
-
32
- ## Forbidden
33
-
34
- ### MUST NOT
35
- - Allow uploads of files exceeding size limits
36
- - Accept unsupported file types
37
- - Ignore validation results
38
- - Proceed with upload when isValid is false
39
- - Assume all files are valid
40
- - Skip validation for performance
41
-
42
- ### MUST NEVER
43
- - Upload files with errors
44
- - Modify files during validation
45
- - Cache validation results indefinitely
46
- - Assume synchronous validation
47
- - Ignore platform-specific constraints
48
- - Allow bypass of critical validation rules
49
-
50
- ## Rules
51
-
52
- ### Validation Rules
53
- - MUST check file size (max 50 MB)
54
- - MUST check file type against supported formats
55
- - MUST return validation result with isValid boolean
56
- - MUST provide errors for upload-blocking issues
57
- - MUST provide warnings for performance concerns
58
- - MUST provide recommendations for improvements
59
-
60
- ### File Size Limits
61
- - MUST reject files over 50 MB (error)
62
- - MUST warn on files over 10 MB
63
- - MUST recommend compression for large files
64
- - MUST format file sizes for readability
65
- - MUST consider media type for limits
66
-
67
- ### Supported File Types
68
- - Images: JPEG, PNG, WebP
69
- - Audio: MP3, WAV, M4A
70
- - Video: MP4, MOV
71
- - MUST validate MIME types
72
- - MUST reject unsupported types with clear error
73
-
74
- ### Validation Results
75
- - MUST include isValid boolean
76
- - MUST include errors array (upload blockers)
77
- - MUST include warnings array (performance impacts)
78
- - MUST include recommendations array (improvements)
79
- - MUST be serializable for transport
80
-
81
- ### Error Handling
82
- - MUST handle missing file metadata
83
- - MUST handle invalid file structures
84
- - MUST handle async validation operations
85
- - MUST provide specific error messages
86
- - MUST support batch validation
87
-
88
- ### Feedback Levels
89
- - Errors: Critical issues that prevent upload
90
- - Warnings: Non-critical but impactful issues
91
- - Recommendations: Suggestions for optimization
92
- - MUST clearly distinguish between levels
93
-
94
- ## AI Agent Guidelines
95
-
96
- ### When Implementing Validation
97
- 1. Always check file metadata completeness
98
- 2. Validate size limits before processing
99
- 3. Check MIME type against allowed list
100
- 4. Provide specific, actionable error messages
101
- 5. Return structured validation result
102
-
103
- ### When Working with Validation Results
104
- - Check isValid flag before proceeding
105
- - Display errors to user (block upload)
106
- - Show warnings to user (allow upload)
107
- - Present recommendations as optional
108
- - Format messages for user understanding
109
-
110
- ### When Adding Validation Rules
111
- - Add new size limits with clear thresholds
112
- - Add new file types with MIME validation
113
- - Add custom rules for specific use cases
114
- - Maintain backward compatibility
115
- - Document rule changes
116
-
117
- ### When Refactoring
118
- - Keep validation API stable
119
- - Preserve error message format
120
- - Maintain validation logic flow
121
- - Don't change result structure
122
- - Add deprecation warnings for breaking changes
123
-
124
- ### Common Patterns to Follow
125
- - Receive file -> Check metadata -> Validate rules -> Return result
126
- - Check isValid -> If false, show errors -> If true, proceed
127
- - Check size -> If large, warn and recommend compression
128
- - Check type -> If invalid, error with supported types
129
- - Always handle async validation properly
130
-
131
- ## Dependencies
132
-
133
- - Domain types: MediaValidation from MultimediaFlashcardTypes
134
- - Internal utilities: mediaHelpers (formatFileSize)
135
- - No external library dependencies (uses native File API)
@@ -1,142 +0,0 @@
1
- # MultimediaFlashcardService
2
-
3
- ## Purpose
4
- Main service that manages all media operations for media-enabled flashcards from a single point, combining upload, generation, validation, and optimization capabilities through a singleton instance.
5
-
6
- ## File Location
7
- `/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/MultimediaFlashcardService`
8
-
9
- ## Strategy
10
- - Provide unified interface for all flashcard media operations
11
- - Coordinate upload, generation, validation, and optimization services
12
- - Maintain singleton pattern for resource efficiency
13
- - Simplify media management for flashcard applications
14
- - Support general flashcard media requirements
15
- - Enable batch operations for card sets
16
- - Provide consistent API across all media operations
17
- - Reduce complexity by exposing single service instance
18
-
19
- ## Forbidden
20
- - **DO NOT** create multiple service instances (use singleton only)
21
- - **DO NOT** call media operations without validation
22
- - **DO NOT** assume AI generation is always available
23
- - **DO NOT** ignore optimization recommendations
24
- - **DO NOT** bypass singleton pattern with direct service instantiation
25
- - **DO NOT** proceed without error handling for any operation
26
- - **DO NOT** mix flashcard media with other media types
27
- - **DO NOT** assume all operations will succeed
28
-
29
- ## Rules
30
- 1. MUST use getInstance() to retrieve service instance
31
- 2. MUST NOT create new instances with constructor
32
- 3. MUST maintain single instance across application lifecycle
33
- 4. MUST validate media before upload operations
34
- 5. MUST handle all operation failures gracefully
35
- 6. MUST support MediaAttachment and MediaPosition types
36
- 7. MUST provide consistent interface through all methods
37
- 8. MUST initialize all sub-services on first use
38
- 9. MUST coordinate between sub-services for complex operations
39
- 10. MUST handle asynchronous operations properly
40
- 11. MUST return appropriate error messages for failures
41
-
42
- ## AI Agent Guidelines
43
-
44
- When working with MultimediaFlashcardService:
45
-
46
- 1. **Singleton Pattern**: Always use getInstance(), never constructor
47
- 2. **Validation First**: Validate before upload or generation
48
- 3. **Operation Flow**: Follow validate -> upload/generate -> optimize -> store
49
- 4. **Error Handling**: Handle errors at each step appropriately
50
- 5. **Resource Management**: Rely on singleton for efficient resource use
51
- 6. **Type Safety**: Use MediaAttachment and MediaPosition types
52
- 7. **Service Coordination**: Let service coordinate sub-operations
53
-
54
- ### Flashcard Creation Workflow
55
-
56
- - **Step 1 - Get Instance**: `MultimediaFlashcardService.getInstance()`
57
- - **Step 2 - Select File**: Pick file from device or camera
58
- - **Step 3 - Validate**: Run validation, check results
59
- - **Step 4 - Upload**: Upload if validation passes
60
- - **Step 5 - Optimize** (Optional): Optimize if file is large
61
- - **Step 6 - Store**: Save attachment with flashcard data
62
- - **Step 7 - Handle Errors**: Provide feedback at each step
63
-
64
- ### Media Upload Workflow
65
-
66
- - Use for user-selected media (images, audio, video)
67
- - Always validate before uploading
68
- - Consider compression for large files
69
- - Set appropriate position if applicable
70
- - Store returned attachment with flashcard
71
- - Handle upload failures with user feedback
72
-
73
- ### AI Content Generation Workflow
74
-
75
- - Use for text-to-image or text-to-audio generation
76
- - Validate prompts before generation
77
- - Check credit/balance availability
78
- - Set appropriate options (language, voice, style)
79
- - Handle generation failures gracefully
80
- - Store successful attachments with flashcard
81
-
82
- ### Media Optimization Workflow
83
-
84
- - Use when file size impacts performance
85
- - Choose quality level based on use case
86
- - Consider flashcard importance (front/back)
87
- - Calculate expected size reduction
88
- - Preserve attachments through optimization
89
- - Update flashcard with optimized media
90
-
91
- ### Media Deletion Workflow
92
-
93
- - Verify media ownership before deletion
94
- - Check flashcard associations
95
- - Confirm deletion with user if needed
96
- - Delete from all storage locations
97
- - Update flashcard references
98
- - Handle missing files gracefully
99
-
100
- ### Batch Operations
101
-
102
- - For multiple flashcards, use same service instance
103
- - Process uploads/generations in sequence
104
- - Collect results before saving
105
- - Handle partial failures appropriately
106
- - Consider parallel operations for independent media
107
- - Track progress for user feedback
108
-
109
- ### Error Handling Patterns
110
-
111
- - **Validation Errors**: Show to user, block upload
112
- - **Upload Errors**: Retry or allow alternative file
113
- - **Generation Errors**: Check credits, try different prompt
114
- - **Optimization Errors**: Continue with original media
115
- - **Deletion Errors**: Log error, notify user
116
- - **Network Errors**: Show connection message, allow retry
117
-
118
- ### Service Coordination
119
-
120
- The service automatically coordinates:
121
- - UploadService handles file uploads
122
- - GenerationService handles AI generation
123
- - ValidationService checks file validity
124
- - OptimizerService handles compression
125
- - All services work together seamlessly
126
-
127
- ### Performance Considerations
128
-
129
- - Singleton reduces memory footprint
130
- - Single instance maintains state efficiently
131
- - Sub-services initialized once
132
- - All operations are asynchronous
133
- - Consider lazy loading for large card sets
134
- - Cache media URLs when possible
135
-
136
- ## Dependencies
137
- - MediaUploadService for upload operations
138
- - MediaGenerationService for AI generation
139
- - MediaValidationService for validation
140
- - MediaOptimizerService for optimization
141
- - MediaAttachment type from domain layer
142
- - MediaPosition type for media placement
@@ -1,96 +0,0 @@
1
- # Media Helper Utilities
2
-
3
- ## Purpose
4
- Core utility functions for media type detection, duration calculation, thumbnail generation, and file size operations.
5
-
6
- ## File Location
7
- `src/infrastructure/utils/mediaHelpers.ts`
8
-
9
- ## Strategy
10
- - Provide pure utility functions for common media operations
11
- - Enable media type classification from MIME types
12
- - Support file size calculations and formatting
13
- - Generate thumbnails for video files
14
- - Extract metadata from media collections
15
- - Maintain framework-agnostic approach where possible
16
-
17
- ## Forbidden
18
- - **DO NOT** add business logic to utility functions
19
- - **DO NOT** make network calls or API requests
20
- - **DO NOT** modify input parameters (pure functions)
21
- - **DO NOT** store state or cache results globally
22
- - **DO NOT** depend on React or UI frameworks
23
- - **DO NOT** throw exceptions without clear error messages
24
- - **DO NOT** use locale-specific string formatting
25
-
26
- ## Rules
27
- 1. All functions must be pure (same input = same output)
28
- 2. File size calculations must use bytes as the base unit
29
- 3. Media type detection must use MIME type patterns
30
- 4. Duration calculation must return seconds (or undefined for non-audio/video)
31
- 5. Thumbnail generation must only return URLs for video files
32
- 6. Type extraction must remove duplicates and preserve order
33
- 7. Size formatting must use appropriate units (Bytes/KB/MB/GB)
34
- 8. All functions must handle edge cases (empty arrays, null values)
35
- 9. Must support both CardMediaAttachment and MediaAttachment types
36
- 10. Must return fallback values for invalid inputs
37
-
38
- ## AI Agent Guidelines
39
-
40
- When working with media helper utilities:
41
-
42
- 1. **Type Detection**: Always use `getCardMediaType()` for consistent type classification from MIME types
43
- 2. **Size Calculations**: Use `calculateTotalSize()` for aggregating file sizes, never sum manually
44
- 3. **Duration Handling**: Check for undefined return value from `getMediaDuration()` for non-audio/video files
45
- 4. **Thumbnail Generation**: Only videos return thumbnail URLs; images return undefined
46
- 5. **Type Extraction**: Use `extractMediaTypes()` to get unique media types from collections
47
- 6. **Size Formatting**: Always use `formatFileSize()` for user-facing size displays
48
- 7. **Null Safety**: Always handle null/undefined returns appropriately
49
- 8. **Collection Operations**: Use provided utilities instead of manual array operations
50
-
51
- ### Media Type Classification
52
-
53
- - **Supported Types**: "image", "audio", "video"
54
- - **Detection Method**: MIME type pattern matching
55
- - **Default Behavior**: Unknown types default to "image"
56
- - **Common Patterns**:
57
- - Images: image/jpeg, image/png, image/gif, image/webp
58
- - Audio: audio/mp3, audio/wav, audio/mpeg, audio/aac
59
- - Video: video/mp4, video/quicktime, video/x-msvideo
60
-
61
- ### File Size Operations
62
-
63
- 1. **Aggregation**: `calculateTotalSize()` - Sum all file sizes in bytes
64
- 2. **Formatting**: `formatFileSize()` - Convert bytes to readable format
65
- 3. **Unit Selection**: Automatically chooses appropriate unit (Bytes/KB/MB/GB)
66
- 4. **Rounding**: Rounds to 2 decimal places for KB and above
67
-
68
- ### Duration and Metadata
69
-
70
- 1. **Duration**: Returns seconds for audio/video, undefined for images
71
- 2. **Thumbnails**: Only generated for video files using external service
72
- 3. **Type Extraction**: Returns unique types in order of appearance
73
- 4. **Media Support**: Works with both CardMediaAttachment and MediaAttachment
74
-
75
- ### Error Handling
76
-
77
- 1. Handle undefined returns from `getMediaDuration()` for images
78
- 2. Handle undefined returns from `generateThumbnail()` for non-videos
79
- 3. Validate MIME type strings before type detection
80
- 4. Handle empty arrays in collection operations
81
- 5. Always check for null/undefined file objects
82
-
83
- ### Usage Patterns
84
-
85
- 1. **Media Analysis**: Combine multiple utilities for comprehensive file analysis
86
- 2. **Validation**: Use type detection and size calculation for pre-upload validation
87
- 3. **Statistics**: Aggregate collection data using type extraction and size calculation
88
- 4. **Display**: Format sizes for user interfaces using formatFileSize
89
- 5. **Filtering**: Use extracted types for conditional logic and filtering
90
-
91
- ## Dependencies
92
-
93
- - Domain layer types (MediaAttachment, CardMediaAttachment)
94
- - No external libraries
95
- - No framework dependencies
96
- - Pure TypeScript/JavaScript utilities