@umituz/react-native-design-system 2.8.7 → 2.8.9
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.
- package/package.json +10 -6
- package/src/device/infrastructure/repositories/LegacyDeviceIdRepository.ts +1 -1
- package/src/device/infrastructure/services/DeviceFeatureService.ts +1 -1
- package/src/exception/infrastructure/services/ExceptionLogger.ts +1 -1
- package/src/exception/infrastructure/storage/ExceptionStore.ts +1 -1
- package/src/exports/filesystem.ts +1 -0
- package/src/exports/media.ts +1 -0
- package/src/exports/storage.ts +1 -0
- package/src/filesystem/domain/constants/FileConstants.ts +20 -0
- package/src/filesystem/domain/entities/File.ts +20 -0
- package/src/filesystem/domain/types/FileTypes.ts +43 -0
- package/src/filesystem/domain/utils/FileUtils.ts +86 -0
- package/src/filesystem/index.ts +23 -0
- package/src/filesystem/infrastructure/services/FileSystemService.ts +45 -0
- package/src/filesystem/infrastructure/services/cache.service.ts +48 -0
- package/src/filesystem/infrastructure/services/directory.service.ts +66 -0
- package/src/filesystem/infrastructure/services/download.constants.ts +6 -0
- package/src/filesystem/infrastructure/services/download.service.ts +74 -0
- package/src/filesystem/infrastructure/services/download.types.ts +7 -0
- package/src/filesystem/infrastructure/services/encoding.service.ts +25 -0
- package/src/filesystem/infrastructure/services/file-info.service.ts +52 -0
- package/src/filesystem/infrastructure/services/file-manager.service.ts +81 -0
- package/src/filesystem/infrastructure/services/file-path.service.ts +22 -0
- package/src/filesystem/infrastructure/services/file-reader.service.ts +52 -0
- package/src/filesystem/infrastructure/services/file-writer.service.ts +32 -0
- package/src/filesystem/infrastructure/utils/blob.utils.ts +20 -0
- package/src/image/infrastructure/services/ImageStorageService.ts +1 -1
- package/src/index.ts +14 -0
- package/src/media/domain/entities/CardMultimedia.types.README.md +129 -0
- package/src/media/domain/entities/CardMultimedia.types.ts +105 -0
- package/src/media/domain/entities/Media.README.md +80 -0
- package/src/media/domain/entities/Media.ts +139 -0
- package/src/media/domain/entities/MultimediaFlashcardTypes.README.md +144 -0
- package/src/media/domain/entities/MultimediaFlashcardTypes.ts +105 -0
- package/src/media/domain/utils/MediaUtils.README.md +178 -0
- package/src/media/domain/utils/MediaUtils.ts +82 -0
- package/src/media/index.ts +70 -0
- package/src/media/index.ts.README.md +191 -0
- package/src/media/infrastructure/services/CardMediaGenerationService.README.md +99 -0
- package/src/media/infrastructure/services/CardMediaGenerationService.ts +101 -0
- package/src/media/infrastructure/services/CardMediaOptimizerService.README.md +167 -0
- package/src/media/infrastructure/services/CardMediaOptimizerService.ts +36 -0
- package/src/media/infrastructure/services/CardMediaUploadService.README.md +123 -0
- package/src/media/infrastructure/services/CardMediaUploadService.ts +67 -0
- package/src/media/infrastructure/services/CardMediaValidationService.README.md +134 -0
- package/src/media/infrastructure/services/CardMediaValidationService.ts +81 -0
- package/src/media/infrastructure/services/CardMultimediaService.README.md +176 -0
- package/src/media/infrastructure/services/CardMultimediaService.ts +97 -0
- package/src/media/infrastructure/services/MediaGenerationService.README.md +142 -0
- package/src/media/infrastructure/services/MediaGenerationService.ts +80 -0
- package/src/media/infrastructure/services/MediaOptimizerService.README.md +145 -0
- package/src/media/infrastructure/services/MediaOptimizerService.ts +32 -0
- package/src/media/infrastructure/services/MediaPickerService.README.md +106 -0
- package/src/media/infrastructure/services/MediaPickerService.ts +173 -0
- package/src/media/infrastructure/services/MediaSaveService.README.md +120 -0
- package/src/media/infrastructure/services/MediaSaveService.ts +154 -0
- package/src/media/infrastructure/services/MediaUploadService.README.md +135 -0
- package/src/media/infrastructure/services/MediaUploadService.ts +62 -0
- package/src/media/infrastructure/services/MediaValidationService.README.md +135 -0
- package/src/media/infrastructure/services/MediaValidationService.ts +61 -0
- package/src/media/infrastructure/services/MultimediaFlashcardService.README.md +142 -0
- package/src/media/infrastructure/services/MultimediaFlashcardService.ts +95 -0
- package/src/media/infrastructure/utils/mediaHelpers.README.md +96 -0
- package/src/media/infrastructure/utils/mediaHelpers.ts +82 -0
- package/src/media/infrastructure/utils/mediaPickerMappers.README.md +129 -0
- package/src/media/infrastructure/utils/mediaPickerMappers.ts +76 -0
- package/src/media/presentation/hooks/card-multimedia.types.README.md +177 -0
- package/src/media/presentation/hooks/card-multimedia.types.ts +51 -0
- package/src/media/presentation/hooks/multimedia.types.README.md +201 -0
- package/src/media/presentation/hooks/multimedia.types.ts +51 -0
- package/src/media/presentation/hooks/useCardMediaGeneration.README.md +164 -0
- package/src/media/presentation/hooks/useCardMediaGeneration.ts +124 -0
- package/src/media/presentation/hooks/useCardMediaUpload.README.md +153 -0
- package/src/media/presentation/hooks/useCardMediaUpload.ts +86 -0
- package/src/media/presentation/hooks/useCardMediaValidation.README.md +176 -0
- package/src/media/presentation/hooks/useCardMediaValidation.ts +101 -0
- package/src/media/presentation/hooks/useCardMultimediaFlashcard.README.md +158 -0
- package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +104 -0
- package/src/media/presentation/hooks/useMedia.README.md +94 -0
- package/src/media/presentation/hooks/useMedia.ts +186 -0
- package/src/media/presentation/hooks/useMediaGeneration.README.md +118 -0
- package/src/media/presentation/hooks/useMediaGeneration.ts +101 -0
- package/src/media/presentation/hooks/useMediaUpload.README.md +108 -0
- package/src/media/presentation/hooks/useMediaUpload.ts +86 -0
- package/src/media/presentation/hooks/useMediaValidation.README.md +134 -0
- package/src/media/presentation/hooks/useMediaValidation.ts +93 -0
- package/src/media/presentation/hooks/useMultimediaFlashcard.README.md +141 -0
- package/src/media/presentation/hooks/useMultimediaFlashcard.ts +103 -0
- package/src/molecules/alerts/AlertStore.ts +1 -1
- package/src/molecules/calendar/infrastructure/storage/EventActions.ts +1 -1
- package/src/molecules/calendar/infrastructure/stores/storageAdapter.ts +1 -1
- package/src/offline/infrastructure/storage/OfflineStore.ts +1 -1
- package/src/onboarding/infrastructure/storage/OnboardingStore.ts +2 -2
- package/src/onboarding/infrastructure/storage/__tests__/OnboardingStore.test.ts +1 -1
- package/src/onboarding/infrastructure/storage/actions/answerActions.ts +1 -1
- package/src/onboarding/infrastructure/storage/actions/storageHelpers.ts +1 -1
- package/src/storage/README.md +185 -0
- package/src/storage/__tests__/integration.test.ts +391 -0
- package/src/storage/__tests__/mocks/asyncStorage.mock.ts +52 -0
- package/src/storage/__tests__/performance.test.tsx +352 -0
- package/src/storage/__tests__/setup.ts +63 -0
- package/src/storage/application/README.md +158 -0
- package/src/storage/application/ports/IStorageRepository.ts +61 -0
- package/src/storage/application/ports/README.md +127 -0
- package/src/storage/cache/README.md +154 -0
- package/src/storage/cache/__tests__/PerformanceAndMemory.test.ts +387 -0
- package/src/storage/cache/__tests__/setup.ts +19 -0
- package/src/storage/cache/domain/Cache.ts +146 -0
- package/src/storage/cache/domain/CacheManager.md +83 -0
- package/src/storage/cache/domain/CacheManager.ts +48 -0
- package/src/storage/cache/domain/CacheStatsTracker.md +169 -0
- package/src/storage/cache/domain/CacheStatsTracker.ts +49 -0
- package/src/storage/cache/domain/CachedValue.md +97 -0
- package/src/storage/cache/domain/ErrorHandler.md +99 -0
- package/src/storage/cache/domain/ErrorHandler.ts +42 -0
- package/src/storage/cache/domain/PatternMatcher.md +122 -0
- package/src/storage/cache/domain/PatternMatcher.ts +30 -0
- package/src/storage/cache/domain/README.md +118 -0
- package/src/storage/cache/domain/__tests__/Cache.test.ts +293 -0
- package/src/storage/cache/domain/__tests__/CacheManager.test.ts +276 -0
- package/src/storage/cache/domain/__tests__/ErrorHandler.test.ts +303 -0
- package/src/storage/cache/domain/__tests__/PatternMatcher.test.ts +261 -0
- package/src/storage/cache/domain/strategies/EvictionStrategy.ts +9 -0
- package/src/storage/cache/domain/strategies/FIFOStrategy.ts +12 -0
- package/src/storage/cache/domain/strategies/LFUStrategy.ts +22 -0
- package/src/storage/cache/domain/strategies/LRUStrategy.ts +22 -0
- package/src/storage/cache/domain/strategies/README.md +117 -0
- package/src/storage/cache/domain/strategies/TTLStrategy.ts +23 -0
- package/src/storage/cache/domain/strategies/__tests__/EvictionStrategies.test.ts +293 -0
- package/src/storage/cache/domain/types/Cache.ts +28 -0
- package/src/storage/cache/domain/types/README.md +107 -0
- package/src/storage/cache/index.ts +28 -0
- package/src/storage/cache/infrastructure/README.md +126 -0
- package/src/storage/cache/infrastructure/TTLCache.ts +103 -0
- package/src/storage/cache/infrastructure/__tests__/TTLCache.test.ts +303 -0
- package/src/storage/cache/presentation/README.md +123 -0
- package/src/storage/cache/presentation/__tests__/ReactHooks.test.ts +514 -0
- package/src/storage/cache/presentation/useCache.ts +76 -0
- package/src/storage/cache/presentation/useCachedValue.ts +88 -0
- package/src/storage/cache/types.d.ts +3 -0
- package/src/storage/domain/README.md +128 -0
- package/src/storage/domain/constants/CacheDefaults.ts +64 -0
- package/src/storage/domain/constants/README.md +105 -0
- package/src/storage/domain/entities/CachedValue.ts +86 -0
- package/src/storage/domain/entities/README.md +109 -0
- package/src/storage/domain/entities/StorageResult.ts +75 -0
- package/src/storage/domain/entities/__tests__/CachedValue.test.ts +149 -0
- package/src/storage/domain/entities/__tests__/StorageResult.test.ts +122 -0
- package/src/storage/domain/errors/README.md +126 -0
- package/src/storage/domain/errors/StorageError.ts +81 -0
- package/src/storage/domain/errors/__tests__/StorageError.test.ts +127 -0
- package/src/storage/domain/factories/README.md +138 -0
- package/src/storage/domain/factories/StoreFactory.ts +59 -0
- package/src/storage/domain/types/README.md +522 -0
- package/src/storage/domain/types/Store.ts +44 -0
- package/src/storage/domain/utils/CacheKeyGenerator.ts +66 -0
- package/src/storage/domain/utils/README.md +127 -0
- package/src/storage/domain/utils/__tests__/devUtils.test.ts +97 -0
- package/src/storage/domain/utils/devUtils.ts +37 -0
- package/src/storage/domain/value-objects/README.md +120 -0
- package/src/storage/domain/value-objects/StorageKey.ts +60 -0
- package/src/storage/index.ts +175 -0
- package/src/storage/infrastructure/README.md +165 -0
- package/src/storage/infrastructure/adapters/README.md +175 -0
- package/src/storage/infrastructure/adapters/StorageService.md +103 -0
- package/src/storage/infrastructure/adapters/StorageService.ts +49 -0
- package/src/storage/infrastructure/repositories/AsyncStorageRepository.ts +98 -0
- package/src/storage/infrastructure/repositories/BaseStorageOperations.ts +100 -0
- package/src/storage/infrastructure/repositories/BatchStorageOperations.ts +42 -0
- package/src/storage/infrastructure/repositories/README.md +121 -0
- package/src/storage/infrastructure/repositories/StringStorageOperations.ts +44 -0
- package/src/storage/infrastructure/repositories/__tests__/AsyncStorageRepository.test.ts +170 -0
- package/src/storage/infrastructure/repositories/__tests__/BaseStorageOperations.test.ts +201 -0
- package/src/storage/presentation/README.md +181 -0
- package/src/storage/presentation/hooks/CacheStorageOperations.ts +94 -0
- package/src/storage/presentation/hooks/README.md +128 -0
- package/src/storage/presentation/hooks/__tests__/usePersistentCache.test.ts +405 -0
- package/src/storage/presentation/hooks/__tests__/useStorage.test.ts +247 -0
- package/src/storage/presentation/hooks/__tests__/useStorageState.test.ts +293 -0
- package/src/storage/presentation/hooks/useCacheState.ts +53 -0
- package/src/storage/presentation/hooks/usePersistentCache.ts +154 -0
- package/src/storage/presentation/hooks/useStorage.ts +102 -0
- package/src/storage/presentation/hooks/useStorageState.ts +71 -0
- package/src/storage/presentation/hooks/useStore.ts +15 -0
- package/src/storage/types/README.md +103 -0
- package/src/theme/infrastructure/globalThemeStore.ts +1 -1
- package/src/theme/infrastructure/storage/ThemeStorage.ts +1 -1
- package/src/theme/infrastructure/stores/themeStore.ts +1 -1
- package/src/utilities/sharing/infrastructure/services/SharingService.ts +1 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# @umituz/react-native-media - Main Export
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Main entry point for the library. Exports all services, hooks, types, and utilities for media management in React Native applications.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`src/index.ts`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Provide a single import point for all library functionality
|
|
11
|
+
- Organize exports by category (services, hooks, types, utils)
|
|
12
|
+
- Enable tree-shaking by using named exports
|
|
13
|
+
- Maintain clear separation between general media and card-specific features
|
|
14
|
+
- Support both individual imports and bulk imports
|
|
15
|
+
|
|
16
|
+
## Forbidden
|
|
17
|
+
- **DO NOT** add default exports - only named exports
|
|
18
|
+
- **DO NOT** re-export external dependencies directly
|
|
19
|
+
- **DO NOT** create circular import dependencies
|
|
20
|
+
- **DO NOT** mix categories in export groups
|
|
21
|
+
- **DO NOT** export internal implementation details
|
|
22
|
+
- **DO NOT** use wildcard exports from sub-modules
|
|
23
|
+
- **DO NOT** change export names once published
|
|
24
|
+
|
|
25
|
+
## Rules
|
|
26
|
+
1. All public exports must be re-exported from this file
|
|
27
|
+
2. Exports must be organized by category (services, hooks, types, utils)
|
|
28
|
+
3. Each category must be clearly commented
|
|
29
|
+
4. General media features must be separate from card-specific features
|
|
30
|
+
5. Type exports must use `export type` for tree-shaking
|
|
31
|
+
6. Service exports must be singleton instances or static classes
|
|
32
|
+
7. Hook exports must be named with `use` prefix
|
|
33
|
+
8. All exports must have TypeScript types
|
|
34
|
+
9. Breaking changes require major version bump
|
|
35
|
+
10. All exports must be documented in their respective README files
|
|
36
|
+
|
|
37
|
+
## AI Agent Guidelines
|
|
38
|
+
|
|
39
|
+
### Import Strategy
|
|
40
|
+
|
|
41
|
+
When working with this library:
|
|
42
|
+
|
|
43
|
+
1. **Single Entry Point**: All imports should come from `@umituz/react-native-media`
|
|
44
|
+
2. **Specific Imports**: Import only what you need for better tree-shaking
|
|
45
|
+
3. **Type Imports**: Use `import type` for type-only imports
|
|
46
|
+
4. **Category Awareness**: Understand the difference between general and card-specific features
|
|
47
|
+
|
|
48
|
+
### Export Categories
|
|
49
|
+
|
|
50
|
+
#### Services (Infrastructure Layer)
|
|
51
|
+
All services follow singleton pattern:
|
|
52
|
+
- `MediaPickerService` - Image/video selection from camera and gallery
|
|
53
|
+
- `MediaSaveService` - Saving media to device gallery
|
|
54
|
+
- `MediaUploadService` - Upload/download media and URL management
|
|
55
|
+
- `MediaGenerationService` - AI-powered text-to-image and text-to-audio
|
|
56
|
+
- `MediaValidationService` - File validation before upload
|
|
57
|
+
- `MediaOptimizerService` - Compression and optimization
|
|
58
|
+
- `CardMultimediaService` - Card-specific media operations
|
|
59
|
+
- `CardMediaGenerationService` - Card AI generation with image search
|
|
60
|
+
- `CardMediaUploadService` - Card upload with position support
|
|
61
|
+
- `CardMediaValidationService` - Card validation with stricter rules
|
|
62
|
+
- `CardMediaOptimizerService` - Card optimization
|
|
63
|
+
- `MultimediaFlashcardService` - Main flashcard service
|
|
64
|
+
- `CardMultimediaFlashcardService` - Main card flashcard service
|
|
65
|
+
|
|
66
|
+
#### Hooks (Presentation Layer)
|
|
67
|
+
All hooks are named with `use` prefix:
|
|
68
|
+
|
|
69
|
+
**General Media Hooks:**
|
|
70
|
+
- `useMedia` - Core media selection and camera
|
|
71
|
+
- `useMediaUpload` - Upload with progress tracking
|
|
72
|
+
- `useMediaGeneration` - AI generation
|
|
73
|
+
- `useMediaValidation` - Pre-upload validation
|
|
74
|
+
- `useMultimediaFlashcard` - Flashcard creation
|
|
75
|
+
|
|
76
|
+
**Card-Specific Hooks:**
|
|
77
|
+
- `useCardMultimediaFlashcard` - Card flashcard management
|
|
78
|
+
- `useCardMediaGeneration` - Card AI generation
|
|
79
|
+
- `useCardMediaUpload` - Card upload with position
|
|
80
|
+
- `useCardMediaValidation` - Card validation
|
|
81
|
+
|
|
82
|
+
#### Types (Domain Layer)
|
|
83
|
+
Organized by functionality:
|
|
84
|
+
|
|
85
|
+
**Basic Types:**
|
|
86
|
+
- `MediaType` - Media type enum (IMAGE, VIDEO, ALL)
|
|
87
|
+
- `ImageFormat` - Format enum (JPEG, PNG, WEBP)
|
|
88
|
+
- `MediaQuality` - Quality enum (LOW, MEDIUM, HIGH)
|
|
89
|
+
- `MediaLibraryPermission` - Permission states
|
|
90
|
+
- `MediaAsset` - Media file properties
|
|
91
|
+
- `MediaPickerResult` - Picker return type
|
|
92
|
+
- `MediaPickerOptions` - Picker configuration
|
|
93
|
+
- `CameraOptions` - Camera configuration
|
|
94
|
+
|
|
95
|
+
**Card Types:**
|
|
96
|
+
- `CardMediaType` - Card media types
|
|
97
|
+
- `CardMediaPosition` - Position (FRONT, BACK, BOTH)
|
|
98
|
+
- `CardMediaAttachment` - Card media with position
|
|
99
|
+
- `CardMultimediaFlashcard` - Card entity
|
|
100
|
+
- `CardMediaGenerationRequest` - Generation request
|
|
101
|
+
- `CardMediaGenerationResult` - Generation result
|
|
102
|
+
- `CardMediaUploadProgress` - Upload progress
|
|
103
|
+
- `CardMediaCompressionOptions` - Compression options
|
|
104
|
+
- `CardMediaValidation` - Validation result
|
|
105
|
+
|
|
106
|
+
**Flashcard Types:**
|
|
107
|
+
- `MediaAttachment` - General media attachment
|
|
108
|
+
- `MultimediaFlashcard` - Flashcard entity
|
|
109
|
+
- `MediaGenerationRequest` - Generation request
|
|
110
|
+
- `MediaGenerationResult` - Generation result
|
|
111
|
+
|
|
112
|
+
#### Utils (Domain & Infrastructure)
|
|
113
|
+
Utility functions and helpers:
|
|
114
|
+
|
|
115
|
+
**Domain Utils:**
|
|
116
|
+
- `MediaUtils` - Core media utilities
|
|
117
|
+
|
|
118
|
+
**Infrastructure Utils:**
|
|
119
|
+
- Helper functions for media operations
|
|
120
|
+
- Mapper functions for type conversions
|
|
121
|
+
|
|
122
|
+
### Module Selection Guidelines
|
|
123
|
+
|
|
124
|
+
#### Use General Media Features When:
|
|
125
|
+
- Working with standard media operations
|
|
126
|
+
- No card/flashcard requirements
|
|
127
|
+
- Need basic upload/download/validation
|
|
128
|
+
- Building general-purpose media features
|
|
129
|
+
|
|
130
|
+
#### Use Card-Specific Features When:
|
|
131
|
+
- Building flashcard applications
|
|
132
|
+
- Need position-based media (front/back)
|
|
133
|
+
- Working with card entities
|
|
134
|
+
- Need card-specific validation rules
|
|
135
|
+
- Using card generation or upload services
|
|
136
|
+
|
|
137
|
+
### Dependency Rules
|
|
138
|
+
|
|
139
|
+
1. **Services** can be used independently or through hooks
|
|
140
|
+
2. **Hooks** wrap services and provide React state management
|
|
141
|
+
3. **Types** are used by both services and hooks
|
|
142
|
+
4. **Utils** provide helper functions used across layers
|
|
143
|
+
|
|
144
|
+
### Common Import Patterns
|
|
145
|
+
|
|
146
|
+
**Service-only usage:**
|
|
147
|
+
- Import service classes directly
|
|
148
|
+
- Use for non-React code or direct service access
|
|
149
|
+
- Services follow singleton pattern
|
|
150
|
+
|
|
151
|
+
**Hook usage (recommended for React components):**
|
|
152
|
+
- Import hooks for React components
|
|
153
|
+
- Hooks provide state management
|
|
154
|
+
- Hooks wrap services with React integration
|
|
155
|
+
|
|
156
|
+
**Type imports:**
|
|
157
|
+
- Use `import type` for type-only imports
|
|
158
|
+
- Enables tree-shaking
|
|
159
|
+
- Better IDE support
|
|
160
|
+
|
|
161
|
+
**Combined imports:**
|
|
162
|
+
- Mix services, hooks, and types as needed
|
|
163
|
+
- All imports from single entry point
|
|
164
|
+
- Named exports only
|
|
165
|
+
|
|
166
|
+
## File Structure Reference
|
|
167
|
+
|
|
168
|
+
The library follows Clean Architecture with three main layers:
|
|
169
|
+
|
|
170
|
+
**Domain Layer** (`src/domain/`)
|
|
171
|
+
- `entities/` - Core type definitions and interfaces
|
|
172
|
+
- `utils/` - Domain utility functions
|
|
173
|
+
|
|
174
|
+
**Infrastructure Layer** (`src/infrastructure/`)
|
|
175
|
+
- `services/` - Service implementations with external integrations
|
|
176
|
+
- `utils/` - Helper functions and mappers
|
|
177
|
+
|
|
178
|
+
**Presentation Layer** (`src/presentation/`)
|
|
179
|
+
- `hooks/` - React hooks for UI integration
|
|
180
|
+
|
|
181
|
+
**Main Export** (`src/index.ts`)
|
|
182
|
+
- Single entry point for all exports
|
|
183
|
+
- Organized by category
|
|
184
|
+
- This file
|
|
185
|
+
|
|
186
|
+
## Dependencies
|
|
187
|
+
|
|
188
|
+
- Exports all domain entities and types
|
|
189
|
+
- Exports all infrastructure services
|
|
190
|
+
- Exports all presentation hooks
|
|
191
|
+
- Re-exports utilities from domain and infrastructure layers
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# CardMediaGenerationService
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Service that performs AI-based media generation operations for flashcards, including text-to-image, text-to-audio, and image-search capabilities.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/CardMediaGenerationService`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Generate media content using AI APIs for card applications
|
|
11
|
+
- Support multiple generation types (text-to-image, text-to-audio, image-search)
|
|
12
|
+
- Track processing time and credit/balance usage
|
|
13
|
+
- Return card-compatible media attachments with position support
|
|
14
|
+
- Provide detailed result information including success status and error messages
|
|
15
|
+
- Enable batch generation with multiple results
|
|
16
|
+
- Maintain unique request IDs for tracking and debugging
|
|
17
|
+
|
|
18
|
+
## Forbidden
|
|
19
|
+
- **DO NOT** generate media without checking available credits/balance
|
|
20
|
+
- **DO NOT** use empty or null prompts for generation
|
|
21
|
+
- **DO NOT** assume all generation requests will succeed
|
|
22
|
+
- **DO NOT** ignore generation timeout limits
|
|
23
|
+
- **DO NOT** generate inappropriate or copyrighted content
|
|
24
|
+
- **DO NOT** proceed without error handling for API failures
|
|
25
|
+
- **DO NOT** mix generation types in single requests
|
|
26
|
+
- **DO NOT** bypass request ID tracking
|
|
27
|
+
|
|
28
|
+
## Rules
|
|
29
|
+
1. All generation operations must include a valid prompt
|
|
30
|
+
2. Text-to-image generation requires prompt and optional style/maxResults
|
|
31
|
+
3. Text-to-audio generation requires prompt, language, and optional voice/speed
|
|
32
|
+
4. Image search requires keyword prompt and optional maxResults
|
|
33
|
+
5. Credit costs vary by type: text-to-image (5), text-to-audio (3), image-search (2)
|
|
34
|
+
6. All generated media must have position attribute set to 'both' by default
|
|
35
|
+
7. Processing time must be tracked and returned in milliseconds
|
|
36
|
+
8. Unique request IDs must be generated for each operation
|
|
37
|
+
9. Generation failures must return clear error messages
|
|
38
|
+
10. Audio files must be assigned a 10-second duration by default
|
|
39
|
+
11. maxResults defaults to 1 for text-to-image, 5 for image-search
|
|
40
|
+
|
|
41
|
+
## AI Agent Guidelines
|
|
42
|
+
|
|
43
|
+
When working with CardMediaGenerationService:
|
|
44
|
+
|
|
45
|
+
1. **Pre-generation Checks**: Always verify credit/balance before generation requests
|
|
46
|
+
2. **Prompt Quality**: Use clear, descriptive prompts for better results
|
|
47
|
+
3. **Type Selection**: Choose appropriate generation type for use case
|
|
48
|
+
4. **Result Validation**: Always check success flag before using results
|
|
49
|
+
5. **Error Handling**: Handle API failures, timeouts, and insufficient credits
|
|
50
|
+
6. **Position Assignment**: Set correct position (front/back/both) for card use
|
|
51
|
+
7. **Request Tracking**: Store request IDs for debugging and support
|
|
52
|
+
|
|
53
|
+
### Generation Type Guidelines
|
|
54
|
+
|
|
55
|
+
- **Text-to-Image**: Use for visual content on cards (front typically)
|
|
56
|
+
- Specify style (realistic, artistic) for better results
|
|
57
|
+
- Set maxResults to 1 unless multiple options needed
|
|
58
|
+
- Images receive position='both' by default
|
|
59
|
+
|
|
60
|
+
- **Text-to-Audio**: Use for pronunciation or audio explanations
|
|
61
|
+
- Specify language code (tr-TR, en-US, etc.)
|
|
62
|
+
- Set voice type (male, female) if applicable
|
|
63
|
+
- Adjust speed (0.5-2.0) for playback preferences
|
|
64
|
+
- Audio receives 10-second duration by default
|
|
65
|
+
|
|
66
|
+
- **Image Search**: Use for finding relevant visuals
|
|
67
|
+
- Use specific keywords for better results
|
|
68
|
+
- Set maxResults for multiple options
|
|
69
|
+
- Credits are cheaper than text-to-image
|
|
70
|
+
|
|
71
|
+
### Credit Management
|
|
72
|
+
|
|
73
|
+
- Calculate total credits before batch operations
|
|
74
|
+
- Text-to-image: 5 credits per request
|
|
75
|
+
- Text-to-audio: 3 credits per request
|
|
76
|
+
- Image search: 2 credits per request
|
|
77
|
+
- Handle insufficient credit errors gracefully
|
|
78
|
+
- Track credits used from generation results
|
|
79
|
+
|
|
80
|
+
### Error Handling Patterns
|
|
81
|
+
|
|
82
|
+
- Check success flag before accessing attachments
|
|
83
|
+
- Parse error messages for specific failure types:
|
|
84
|
+
- "insufficient credits" - balance too low
|
|
85
|
+
- "timeout" - operation took too long
|
|
86
|
+
- "invalid prompt" - prompt validation failed
|
|
87
|
+
- "api error" - underlying API failure
|
|
88
|
+
|
|
89
|
+
### Performance Considerations
|
|
90
|
+
|
|
91
|
+
- Generation operations are simulated (3 seconds delay)
|
|
92
|
+
- Batch multiple results in single request when possible
|
|
93
|
+
- Track processing time for performance monitoring
|
|
94
|
+
- Use request IDs for debugging slow operations
|
|
95
|
+
|
|
96
|
+
## Dependencies
|
|
97
|
+
- CardMediaAttachment type from domain layer
|
|
98
|
+
- AI generation APIs (simulated in development)
|
|
99
|
+
- Credit/balance management system
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card Media Generation Service
|
|
3
|
+
* Handles AI media generation (text-to-image, text-to-audio, image-search)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
CardMediaAttachment,
|
|
8
|
+
CardMediaGenerationRequest,
|
|
9
|
+
CardMediaGenerationResult,
|
|
10
|
+
CardMediaType,
|
|
11
|
+
CardMediaPosition,
|
|
12
|
+
} from "../../domain/entities/CardMultimedia.types";
|
|
13
|
+
|
|
14
|
+
export class CardMediaGenerationService {
|
|
15
|
+
/**
|
|
16
|
+
* Generate media from AI (text-to-image, text-to-audio, etc.)
|
|
17
|
+
*/
|
|
18
|
+
async generateMedia(
|
|
19
|
+
request: CardMediaGenerationRequest,
|
|
20
|
+
): Promise<CardMediaGenerationResult> {
|
|
21
|
+
try {
|
|
22
|
+
const startTime = Date.now();
|
|
23
|
+
|
|
24
|
+
// Simulate AI generation
|
|
25
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
26
|
+
|
|
27
|
+
const attachments: CardMediaAttachment[] = [];
|
|
28
|
+
|
|
29
|
+
switch (request.type) {
|
|
30
|
+
case "text_to_image":
|
|
31
|
+
for (let i = 0; i < (request.options.maxResults || 1); i++) {
|
|
32
|
+
attachments.push({
|
|
33
|
+
id: `ai_img_${Date.now()}_${i}`,
|
|
34
|
+
type: "image" as CardMediaType,
|
|
35
|
+
position: "both" as CardMediaPosition,
|
|
36
|
+
url: `https://picsum.photos/400/300?random=${Date.now() + i}`,
|
|
37
|
+
filename: `ai_generated_${i}.jpg`,
|
|
38
|
+
fileSize: 150000, // 150KB
|
|
39
|
+
mimeType: "image/jpeg",
|
|
40
|
+
isDownloaded: false,
|
|
41
|
+
createdAt: new Date().toISOString(),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
|
|
46
|
+
case "text_to_audio":
|
|
47
|
+
attachments.push({
|
|
48
|
+
id: `ai_audio_${Date.now()}`,
|
|
49
|
+
type: "audio" as CardMediaType,
|
|
50
|
+
position: "back" as CardMediaPosition,
|
|
51
|
+
url: `https://example.com/audio_${Date.now()}.mp3`,
|
|
52
|
+
filename: `ai_generated_${Date.now()}.mp3`,
|
|
53
|
+
fileSize: 80000, // 80KB
|
|
54
|
+
mimeType: "audio/mp3",
|
|
55
|
+
duration: 10, // 10 seconds
|
|
56
|
+
isDownloaded: false,
|
|
57
|
+
createdAt: new Date().toISOString(),
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
|
|
61
|
+
case "image_search":
|
|
62
|
+
for (let i = 0; i < (request.options.maxResults || 5); i++) {
|
|
63
|
+
attachments.push({
|
|
64
|
+
id: `search_img_${Date.now()}_${i}`,
|
|
65
|
+
type: "image" as CardMediaType,
|
|
66
|
+
position: "both" as CardMediaPosition,
|
|
67
|
+
url: `https://picsum.photos/400/300?random=${Date.now() + i}`,
|
|
68
|
+
filename: `search_result_${i}.jpg`,
|
|
69
|
+
fileSize: 120000, // 120KB
|
|
70
|
+
mimeType: "image/jpeg",
|
|
71
|
+
isDownloaded: false,
|
|
72
|
+
createdAt: new Date().toISOString(),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
success: true,
|
|
80
|
+
attachments,
|
|
81
|
+
creditsUsed:
|
|
82
|
+
request.type === "text_to_image"
|
|
83
|
+
? 5
|
|
84
|
+
: request.type === "text_to_audio"
|
|
85
|
+
? 3
|
|
86
|
+
: 2,
|
|
87
|
+
processingTime: Date.now() - startTime,
|
|
88
|
+
requestId: `req_${Date.now()}`,
|
|
89
|
+
};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
attachments: [],
|
|
94
|
+
creditsUsed: 0,
|
|
95
|
+
processingTime: 0,
|
|
96
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
97
|
+
requestId: "",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# CardMediaOptimizerService
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Service that optimizes and compresses flashcard media files to reduce size while maintaining acceptable quality, and manages media deletion operations.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/CardMediaOptimizerService`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Optimize media files by reducing file size with quality settings
|
|
11
|
+
- Support dimension resizing (maxWidth, maxHeight)
|
|
12
|
+
- Provide multiple quality levels for different use cases
|
|
13
|
+
- Generate new optimized versions while preserving originals
|
|
14
|
+
- Delete media from server and local storage
|
|
15
|
+
- Return optimized media with updated file size and URL
|
|
16
|
+
- Maintain card media position through optimization
|
|
17
|
+
- Calculate size reduction percentages
|
|
18
|
+
|
|
19
|
+
## Forbidden
|
|
20
|
+
- **DO NOT** optimize below usable quality (quality < 0.3)
|
|
21
|
+
- **DO NOT** modify original media files
|
|
22
|
+
- **DO NOT** delete media without verifying ownership
|
|
23
|
+
- **DO NOT** assume optimization will always succeed
|
|
24
|
+
- **DO NOT** use negative or invalid quality values
|
|
25
|
+
- **DO NOT** set dimensions to zero or negative values
|
|
26
|
+
- **DO NOT** delete media without user confirmation
|
|
27
|
+
- **DO NOT** bypass optimization error handling
|
|
28
|
+
|
|
29
|
+
## Rules
|
|
30
|
+
1. Quality value must be between 0-1 (0 = worst, 1 = best)
|
|
31
|
+
2. Max dimensions must be positive integers if specified
|
|
32
|
+
3. Original media is always preserved, never modified
|
|
33
|
+
4. Optimized media receives new URL with ?optimized=true parameter
|
|
34
|
+
5. File size is approximately calculated as: original * quality
|
|
35
|
+
6. Position attribute is preserved through optimization
|
|
36
|
+
7. All other attachment properties remain unchanged
|
|
37
|
+
8. Optimization must maintain aspect ratio when resizing
|
|
38
|
+
9. Delete operation is permanent and irreversible
|
|
39
|
+
10. Optimized size calculation is simulated (not actual compression)
|
|
40
|
+
11. Quality levels: high (0.9-1.0), medium (0.7-0.8), low (0.5-0.6)
|
|
41
|
+
|
|
42
|
+
## AI Agent Guidelines
|
|
43
|
+
|
|
44
|
+
When working with CardMediaOptimizerService:
|
|
45
|
+
|
|
46
|
+
1. **Quality Selection**: Choose appropriate quality for use case
|
|
47
|
+
2. **Size Calculation**: Estimate size reduction before optimization
|
|
48
|
+
3. **Original Preservation**: Always keep original media intact
|
|
49
|
+
4. **Error Handling**: Handle optimization failures gracefully
|
|
50
|
+
5. **Position Maintenance**: Preserve position through all operations
|
|
51
|
+
6. **Delete Confirmation**: Always verify before deletion
|
|
52
|
+
7. **Batch Operations**: Consider batch optimization for multiple files
|
|
53
|
+
|
|
54
|
+
### Quality Level Guidelines
|
|
55
|
+
|
|
56
|
+
- **High Quality (0.9-1.0)**:
|
|
57
|
+
- Use for: Card front images, important visuals
|
|
58
|
+
- Size reduction: 10-20%
|
|
59
|
+
- When to use: High quality requirements, focal content
|
|
60
|
+
|
|
61
|
+
- **Medium Quality (0.7-0.8)** - RECOMMENDED:
|
|
62
|
+
- Use for: General card media, back images
|
|
63
|
+
- Size reduction: 30-50%
|
|
64
|
+
- When to use: Balance of quality and size, most cases
|
|
65
|
+
|
|
66
|
+
- **Low Quality (0.5-0.6)**:
|
|
67
|
+
- Use for: Thumbnails, previews, non-critical content
|
|
68
|
+
- Size reduction: 50-70%
|
|
69
|
+
- When to use: Previews, placeholders, bandwidth-constrained
|
|
70
|
+
|
|
71
|
+
- **Very Low Quality (0.3-0.4)**:
|
|
72
|
+
- Use for: Low-quality previews only
|
|
73
|
+
- Size reduction: 70-80%
|
|
74
|
+
- When to use: Extreme bandwidth constraints
|
|
75
|
+
|
|
76
|
+
### Dimension Guidelines
|
|
77
|
+
|
|
78
|
+
- **Full Resolution**: No max dimensions specified
|
|
79
|
+
- Use when: Quality is critical, storage is abundant
|
|
80
|
+
|
|
81
|
+
- **1920x1080** - RECOMMENDED:
|
|
82
|
+
- Use for: General card media, good balance
|
|
83
|
+
- Suitable for: Most modern displays
|
|
84
|
+
|
|
85
|
+
- **1280x720**:
|
|
86
|
+
- Use for: Smaller cards, bandwidth optimization
|
|
87
|
+
- Suitable for: Mobile devices, previews
|
|
88
|
+
|
|
89
|
+
- **Lower than 1280x720**:
|
|
90
|
+
- Use for: Thumbnails, very small cards
|
|
91
|
+
- Consider: May appear pixelated on large screens
|
|
92
|
+
|
|
93
|
+
### Card-Specific Optimization
|
|
94
|
+
|
|
95
|
+
- **Front Side Media**:
|
|
96
|
+
- Use higher quality (0.8-0.9)
|
|
97
|
+
- Full or near-full resolution
|
|
98
|
+
- This is the focal point of the card
|
|
99
|
+
|
|
100
|
+
- **Back Side Media**:
|
|
101
|
+
- Use medium quality (0.7)
|
|
102
|
+
- Moderate resolution (1280x720 or 1920x1080)
|
|
103
|
+
- Secondary content can be more compressed
|
|
104
|
+
|
|
105
|
+
- **Audio Files**:
|
|
106
|
+
- This service is designed for image optimization only
|
|
107
|
+
- Audio optimization requires different approach (bitrate)
|
|
108
|
+
|
|
109
|
+
### Deletion Guidelines
|
|
110
|
+
|
|
111
|
+
- **Before Delete**:
|
|
112
|
+
- Verify media ownership
|
|
113
|
+
- Check card associations
|
|
114
|
+
- Confirm with user if applicable
|
|
115
|
+
- Consider soft delete option
|
|
116
|
+
|
|
117
|
+
- **During Delete**:
|
|
118
|
+
- Remove from server storage
|
|
119
|
+
- Remove from local storage
|
|
120
|
+
- Update card references
|
|
121
|
+
- Handle missing files gracefully
|
|
122
|
+
|
|
123
|
+
- **After Delete**:
|
|
124
|
+
- Update database references
|
|
125
|
+
- Clean up orphaned files
|
|
126
|
+
- Cannot be undone (permanent)
|
|
127
|
+
|
|
128
|
+
### Optimization Workflow
|
|
129
|
+
|
|
130
|
+
1. Start with original media attachment
|
|
131
|
+
2. Determine target quality and dimensions
|
|
132
|
+
3. Calculate expected size reduction
|
|
133
|
+
4. Run optimization operation
|
|
134
|
+
5. Receive optimized attachment with new URL
|
|
135
|
+
6. Replace or keep both versions
|
|
136
|
+
7. Update card media references
|
|
137
|
+
|
|
138
|
+
### Error Handling
|
|
139
|
+
|
|
140
|
+
- **Optimization Failures**:
|
|
141
|
+
- Return original media unchanged
|
|
142
|
+
- Log error for debugging
|
|
143
|
+
- Continue with original if appropriate
|
|
144
|
+
|
|
145
|
+
- **Invalid Parameters**:
|
|
146
|
+
- Quality outside 0-1 range
|
|
147
|
+
- Negative or zero dimensions
|
|
148
|
+
- Must reject with clear error
|
|
149
|
+
|
|
150
|
+
- **Delete Failures**:
|
|
151
|
+
- Media not found
|
|
152
|
+
- Permission denied
|
|
153
|
+
- Handle gracefully, log error
|
|
154
|
+
|
|
155
|
+
### Performance Considerations
|
|
156
|
+
|
|
157
|
+
- Optimization is simulated (size * quality calculation)
|
|
158
|
+
- In production, integrate actual optimization API
|
|
159
|
+
- Consider lazy optimization (optimize on demand)
|
|
160
|
+
- Batch optimization for multiple files
|
|
161
|
+
- Cache optimized versions when possible
|
|
162
|
+
|
|
163
|
+
## Dependencies
|
|
164
|
+
- CardMediaAttachment type from domain layer
|
|
165
|
+
- CardMediaCompressionOptions type for optimization settings
|
|
166
|
+
- Optimization API endpoints (simulated in development)
|
|
167
|
+
- Storage access for deletion operations
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card Media Optimizer Service
|
|
3
|
+
* Handles media optimization and deletion
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
declare var __DEV__: boolean;
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
CardMediaAttachment,
|
|
10
|
+
CardMediaCompressionOptions,
|
|
11
|
+
} from "../../domain/entities/CardMultimedia.types";
|
|
12
|
+
|
|
13
|
+
export class CardMediaOptimizerService {
|
|
14
|
+
/**
|
|
15
|
+
* Optimize media file
|
|
16
|
+
*/
|
|
17
|
+
async optimizeMedia(
|
|
18
|
+
attachment: CardMediaAttachment,
|
|
19
|
+
options: CardMediaCompressionOptions,
|
|
20
|
+
): Promise<CardMediaAttachment> {
|
|
21
|
+
return {
|
|
22
|
+
...attachment,
|
|
23
|
+
fileSize: Math.floor(attachment.fileSize * options.quality),
|
|
24
|
+
url: `${attachment.url}?optimized=true`,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Delete media attachment
|
|
30
|
+
*/
|
|
31
|
+
async deleteMedia(attachmentId: string): Promise<void> {
|
|
32
|
+
if (__DEV__) {
|
|
33
|
+
console.log(`[CardMediaOptimizerService] Deleting media: ${attachmentId}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|