@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,123 @@
|
|
|
1
|
+
# CardMediaUploadService
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Service that handles media file upload, download, and URL management for flashcard applications, with support for compression and automatic thumbnail generation.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/CardMediaUploadService`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Upload media files to server storage with unique identifiers
|
|
11
|
+
- Support compression options during upload (quality, dimensions, format)
|
|
12
|
+
- Generate thumbnails automatically for uploaded media
|
|
13
|
+
- Download media from server to local storage
|
|
14
|
+
- Retrieve and manage media URLs
|
|
15
|
+
- Calculate duration for audio/video files
|
|
16
|
+
- Return card-compatible media attachments with position support
|
|
17
|
+
- Handle all media types (image, video, audio) with automatic type detection
|
|
18
|
+
|
|
19
|
+
## Forbidden
|
|
20
|
+
- **DO NOT** upload files without validation
|
|
21
|
+
- **DO NOT** bypass file size limits
|
|
22
|
+
- **DO NOT** upload unsupported file types
|
|
23
|
+
- **DO NOT** ignore upload failures
|
|
24
|
+
- **DO NOT** assume all uploads will succeed
|
|
25
|
+
- **DO NOT** overwrite existing media without verification
|
|
26
|
+
- **DO NOT** proceed without error handling for network issues
|
|
27
|
+
- **DO NOT** download media without checking URL validity
|
|
28
|
+
|
|
29
|
+
## Rules
|
|
30
|
+
1. All uploads must include valid file metadata (name, type, size, uri)
|
|
31
|
+
2. Compression options are optional but recommended for large files
|
|
32
|
+
3. Quality must be between 0-1 when specified
|
|
33
|
+
4. Max dimensions must be positive integers when specified
|
|
34
|
+
5. Supported formats are jpeg and png for compression
|
|
35
|
+
6. All attachments receive unique IDs automatically
|
|
36
|
+
7. Position defaults to 'both' for uploaded media
|
|
37
|
+
8. isDownloaded defaults to true for uploads
|
|
38
|
+
9. Thumbnails are generated automatically for visual content
|
|
39
|
+
10. Audio/video duration is calculated automatically
|
|
40
|
+
11. File type is determined automatically from MIME type
|
|
41
|
+
12. Upload operations must handle network failures gracefully
|
|
42
|
+
13. Download operations must validate URL before processing
|
|
43
|
+
|
|
44
|
+
## AI Agent Guidelines
|
|
45
|
+
|
|
46
|
+
When working with CardMediaUploadService:
|
|
47
|
+
|
|
48
|
+
1. **Pre-upload Validation**: Always validate files before upload attempts
|
|
49
|
+
2. **Compression Strategy**: Apply compression for files larger than 5MB
|
|
50
|
+
3. **Type Detection**: Rely on automatic type detection from MIME type
|
|
51
|
+
4. **Error Handling**: Handle network timeouts and connection failures
|
|
52
|
+
5. **Position Assignment**: Set correct position (front/back/both) for card use
|
|
53
|
+
6. **Thumbnail Usage**: Use thumbnails for previews to save bandwidth
|
|
54
|
+
7. **Duration Handling**: Use calculated duration for audio/video scheduling
|
|
55
|
+
|
|
56
|
+
### Upload Guidelines
|
|
57
|
+
|
|
58
|
+
- **Before Upload**:
|
|
59
|
+
- Validate file size and type
|
|
60
|
+
- Consider compression for large files
|
|
61
|
+
- Check network connectivity
|
|
62
|
+
- Prepare error handling
|
|
63
|
+
|
|
64
|
+
- **During Upload**:
|
|
65
|
+
- Monitor for failures
|
|
66
|
+
- Handle network errors
|
|
67
|
+
- Store attachment information
|
|
68
|
+
- Track upload progress
|
|
69
|
+
|
|
70
|
+
- **After Upload**:
|
|
71
|
+
- Verify upload success
|
|
72
|
+
- Store attachment ID and URL
|
|
73
|
+
- Set position for card use
|
|
74
|
+
- Consider optimization if needed
|
|
75
|
+
|
|
76
|
+
### Compression Options
|
|
77
|
+
|
|
78
|
+
- **Quality**: 0.9 (high), 0.7 (medium/recommended), 0.5 (low)
|
|
79
|
+
- **Max Dimensions**: 1920x1080 (recommended), 1280x720 (smaller)
|
|
80
|
+
- **Format**: jpeg (smaller size), png (better quality)
|
|
81
|
+
- Apply compression when file size > 5MB for images
|
|
82
|
+
- Use quality 0.7 for balance of size and quality
|
|
83
|
+
|
|
84
|
+
### Media Type Detection
|
|
85
|
+
|
|
86
|
+
- **Image**: MIME types starting with 'image/'
|
|
87
|
+
- Supported: image/jpeg, image/png, image/webp
|
|
88
|
+
- **Audio**: MIME types starting with 'audio/'
|
|
89
|
+
- Supported: audio/mp3, audio/wav, audio/m4a
|
|
90
|
+
- **Video**: MIME types starting with 'video/'
|
|
91
|
+
- Supported: video/mp4, video/mov
|
|
92
|
+
|
|
93
|
+
### Download Guidelines
|
|
94
|
+
|
|
95
|
+
- Validate media URL before download
|
|
96
|
+
- Handle missing files gracefully
|
|
97
|
+
- Use local path for offline access
|
|
98
|
+
- Check isDownloaded status before re-downloading
|
|
99
|
+
- Manage local storage space
|
|
100
|
+
|
|
101
|
+
### Error Handling Patterns
|
|
102
|
+
|
|
103
|
+
- Handle network errors: timeout, connection refused
|
|
104
|
+
- Handle file errors: invalid format, corrupted file
|
|
105
|
+
- Handle server errors: 500, 503, insufficient storage
|
|
106
|
+
- Handle validation errors: size exceeded, unsupported type
|
|
107
|
+
- Always provide fallback behavior for failed uploads
|
|
108
|
+
|
|
109
|
+
### Performance Considerations
|
|
110
|
+
|
|
111
|
+
- Upload operations are simulated (2 seconds delay)
|
|
112
|
+
- Compress before upload to reduce transfer time
|
|
113
|
+
- Use thumbnails for previews instead of full media
|
|
114
|
+
- Batch uploads when possible for multiple files
|
|
115
|
+
- Consider lazy loading for card media
|
|
116
|
+
|
|
117
|
+
## Dependencies
|
|
118
|
+
- CardMediaAttachment type from domain layer
|
|
119
|
+
- CardMediaCompressionOptions type for compression settings
|
|
120
|
+
- getCardMediaType helper for type detection
|
|
121
|
+
- getMediaDuration helper for duration calculation
|
|
122
|
+
- generateThumbnail helper for thumbnail creation
|
|
123
|
+
- Upload API endpoints (simulated in development)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card Media Upload Service
|
|
3
|
+
* Handles media upload, download, and URL operations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
declare var __DEV__: boolean;
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
CardMediaAttachment,
|
|
10
|
+
CardMediaCompressionOptions,
|
|
11
|
+
} from "../../domain/entities/CardMultimedia.types";
|
|
12
|
+
import {
|
|
13
|
+
generateThumbnail,
|
|
14
|
+
getCardMediaType,
|
|
15
|
+
getMediaDuration,
|
|
16
|
+
} from "../utils/mediaHelpers";
|
|
17
|
+
|
|
18
|
+
export class CardMediaUploadService {
|
|
19
|
+
/**
|
|
20
|
+
* Upload media file with optional compression
|
|
21
|
+
*/
|
|
22
|
+
async uploadMedia(
|
|
23
|
+
file: any,
|
|
24
|
+
_options?: CardMediaCompressionOptions,
|
|
25
|
+
): Promise<CardMediaAttachment> {
|
|
26
|
+
try {
|
|
27
|
+
// Simulate upload process
|
|
28
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
29
|
+
|
|
30
|
+
const attachment: CardMediaAttachment = {
|
|
31
|
+
id: `card_media_${Date.now()}`,
|
|
32
|
+
type: getCardMediaType(file.type),
|
|
33
|
+
position: "both",
|
|
34
|
+
url: `https://storage.example.com/media/${Date.now()}_${file.name}`,
|
|
35
|
+
filename: file.name,
|
|
36
|
+
fileSize: file.size || 100000,
|
|
37
|
+
mimeType: file.type,
|
|
38
|
+
duration: await getMediaDuration(file),
|
|
39
|
+
thumbnailUrl: generateThumbnail(file),
|
|
40
|
+
caption: "",
|
|
41
|
+
isDownloaded: true,
|
|
42
|
+
createdAt: new Date().toISOString(),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return attachment;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error(`Failed to upload media: ${error}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get media URL
|
|
53
|
+
*/
|
|
54
|
+
async getMediaUrl(attachmentId: string): Promise<string> {
|
|
55
|
+
return `https://storage.example.com/media/${attachmentId}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Download media to local storage
|
|
60
|
+
*/
|
|
61
|
+
async downloadMedia(attachmentId: string): Promise<string> {
|
|
62
|
+
if (__DEV__) {
|
|
63
|
+
console.log(`[CardMediaUploadService] Downloading media: ${attachmentId}`);
|
|
64
|
+
}
|
|
65
|
+
return `/local/storage/${attachmentId}`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# CardMediaValidationService
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Service that validates flashcard media files before upload, checking file size, type, and media-specific properties with detailed error, warning, and recommendation reporting.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/CardMediaValidationService`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Validate media files before upload operations
|
|
11
|
+
- Check file size against maximum limits (50 MB hard limit)
|
|
12
|
+
- Validate file type compatibility (image, audio, video)
|
|
13
|
+
- Provide media-specific warnings (large images, long videos)
|
|
14
|
+
- Generate actionable recommendations for optimization
|
|
15
|
+
- Return structured validation results with errors, warnings, and recommendations
|
|
16
|
+
- Support asynchronous validation operations
|
|
17
|
+
- Format file sizes in human-readable format
|
|
18
|
+
|
|
19
|
+
## Forbidden
|
|
20
|
+
- **DO NOT** upload files with validation errors
|
|
21
|
+
- **DO NOT** ignore validation warnings about performance impact
|
|
22
|
+
- **DO NOT** bypass validation for any media upload
|
|
23
|
+
- **DO NOT** allow unsupported file types
|
|
24
|
+
- **DO NOT** proceed when file size exceeds maximum
|
|
25
|
+
- **DO NOT** suppress error messages
|
|
26
|
+
- **DO NOT** assume all validations will pass
|
|
27
|
+
- **DO NOT** skip validation for "trusted" sources
|
|
28
|
+
|
|
29
|
+
## Rules
|
|
30
|
+
1. Maximum file size is 50 MB (hard error)
|
|
31
|
+
2. Large file warning is triggered at 10 MB+
|
|
32
|
+
3. Very large image warning is triggered at 5 MB+
|
|
33
|
+
4. Long audio/video warning is triggered at 5 minutes (300 seconds)
|
|
34
|
+
5. Supported image types: image/jpeg, image/png, image/webp
|
|
35
|
+
6. Supported audio types: audio/mp3, audio/wav, audio/m4a
|
|
36
|
+
7. Supported video types: video/mp4, video/mov
|
|
37
|
+
8. Unsupported file types must return error
|
|
38
|
+
9. Validation must be asynchronous operation
|
|
39
|
+
10. Warnings must not block upload but inform user
|
|
40
|
+
11. Recommendations must provide actionable improvement steps
|
|
41
|
+
12. File size must be checked in bytes
|
|
42
|
+
13. Validation result must include isValid boolean flag
|
|
43
|
+
|
|
44
|
+
## AI Agent Guidelines
|
|
45
|
+
|
|
46
|
+
When working with CardMediaValidationService:
|
|
47
|
+
|
|
48
|
+
1. **Always Validate**: Never upload without validation first
|
|
49
|
+
2. **Check isValid**: Block upload if isValid is false
|
|
50
|
+
3. **Handle Errors**: Show error messages to user and prevent upload
|
|
51
|
+
4. **Show Warnings**: Display warnings but allow user to proceed
|
|
52
|
+
5. **Provide Recommendations**: Show optimization suggestions
|
|
53
|
+
6. **Media-Specific Checks**: Apply different rules for each media type
|
|
54
|
+
7. **User Communication**: Present validation results clearly
|
|
55
|
+
|
|
56
|
+
### Validation Workflow
|
|
57
|
+
|
|
58
|
+
- **Step 1 - Validate**: Run validation before any upload
|
|
59
|
+
- **Step 2 - Check Errors**: If errors exist, show and stop
|
|
60
|
+
- **Step 3 - Show Warnings**: Display warnings, ask user to confirm
|
|
61
|
+
- **Step 4 - Show Recommendations**: Present optimization suggestions
|
|
62
|
+
- **Step 5 - Proceed or Stop**: Allow upload if valid, stop if invalid
|
|
63
|
+
|
|
64
|
+
### Error Handling
|
|
65
|
+
|
|
66
|
+
- **File Size Errors**:
|
|
67
|
+
- "File size (X MB) exceeds maximum allowed size (50 MB)"
|
|
68
|
+
- Must prevent upload operation
|
|
69
|
+
- User must reduce file size
|
|
70
|
+
|
|
71
|
+
- **File Type Errors**:
|
|
72
|
+
- "Unsupported file type: [type]"
|
|
73
|
+
- Must prevent upload operation
|
|
74
|
+
- User must convert to supported format
|
|
75
|
+
|
|
76
|
+
### Warning Handling
|
|
77
|
+
|
|
78
|
+
- **Large File Warning** (10+ MB):
|
|
79
|
+
- "Large file size may impact performance"
|
|
80
|
+
- Allow upload with user confirmation
|
|
81
|
+
- Recommend compression
|
|
82
|
+
|
|
83
|
+
- **Large Image Warning** (5+ MB):
|
|
84
|
+
- "Very large image may cause performance issues"
|
|
85
|
+
- Allow upload with user confirmation
|
|
86
|
+
- Recommend resizing to under 5 MB
|
|
87
|
+
|
|
88
|
+
- **Long Content Warning** (5+ minutes):
|
|
89
|
+
- "Long audio/video files may impact app performance"
|
|
90
|
+
- Allow upload with user confirmation
|
|
91
|
+
- Recommend trimming to under 5 minutes
|
|
92
|
+
|
|
93
|
+
### Recommendation Patterns
|
|
94
|
+
|
|
95
|
+
- **For Large Files**: "Consider compressing file"
|
|
96
|
+
- **For Large Images**: "Consider resizing image to under 5MB"
|
|
97
|
+
- **For Long Content**: "Consider trimming to under 5 minutes"
|
|
98
|
+
- **For Format**: Recommend MP3 for audio, MP4 for video
|
|
99
|
+
- **For Resolution**: Recommend 1920x1080 or smaller
|
|
100
|
+
|
|
101
|
+
### Media-Specific Validation
|
|
102
|
+
|
|
103
|
+
- **Images**:
|
|
104
|
+
- Check MIME type against supported formats
|
|
105
|
+
- Warn if size > 5 MB
|
|
106
|
+
- Recommend JPEG for better compression
|
|
107
|
+
- Consider resolution checks (optional)
|
|
108
|
+
|
|
109
|
+
- **Audio**:
|
|
110
|
+
- Check MIME type against supported formats
|
|
111
|
+
- Warn if duration > 5 minutes
|
|
112
|
+
- Recommend MP3 format
|
|
113
|
+
- Consider bitrate checks (optional)
|
|
114
|
+
|
|
115
|
+
- **Video**:
|
|
116
|
+
- Check MIME type against supported formats
|
|
117
|
+
- Warn if duration > 5 minutes
|
|
118
|
+
- Recommend MP4 format
|
|
119
|
+
- Consider resolution checks (optional)
|
|
120
|
+
|
|
121
|
+
### User Communication
|
|
122
|
+
|
|
123
|
+
- Display errors prominently (block upload)
|
|
124
|
+
- Show warnings with clear impact explanation
|
|
125
|
+
- Present recommendations as actionable steps
|
|
126
|
+
- Allow user to decide on warnings
|
|
127
|
+
- Format file sizes in MB/KB for readability
|
|
128
|
+
- Group messages by severity (errors, warnings, recommendations)
|
|
129
|
+
|
|
130
|
+
## Dependencies
|
|
131
|
+
- CardMediaValidation type for validation results
|
|
132
|
+
- File size constants for limits
|
|
133
|
+
- MIME type validation utilities
|
|
134
|
+
- Media type detection helpers
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card Media Validation Service
|
|
3
|
+
* Handles media file validation before upload
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { formatFileSize } from "../utils/mediaHelpers";
|
|
7
|
+
import type { CardMediaValidation } from "../../domain/entities/CardMultimedia.types";
|
|
8
|
+
import { getMediaDuration } from "../utils/mediaHelpers";
|
|
9
|
+
|
|
10
|
+
export class CardMediaValidationService {
|
|
11
|
+
/**
|
|
12
|
+
* Validate media file before upload
|
|
13
|
+
*/
|
|
14
|
+
async validateMedia(file: any): Promise<CardMediaValidation> {
|
|
15
|
+
try {
|
|
16
|
+
const errors: string[] = [];
|
|
17
|
+
const warnings: string[] = [];
|
|
18
|
+
const recommendations: string[] = [];
|
|
19
|
+
|
|
20
|
+
// File size validation
|
|
21
|
+
const maxSize = 50 * 1024 * 1024; // 50MB
|
|
22
|
+
if (file.size > maxSize) {
|
|
23
|
+
errors.push(
|
|
24
|
+
`File size (${formatFileSize(file.size)}) exceeds maximum allowed size (${formatFileSize(maxSize)})`,
|
|
25
|
+
);
|
|
26
|
+
} else if (file.size > 10 * 1024 * 1024) {
|
|
27
|
+
// 10MB
|
|
28
|
+
warnings.push(`Large file size may impact performance`);
|
|
29
|
+
recommendations.push("Consider compressing file");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// File type validation
|
|
33
|
+
const supportedTypes = [
|
|
34
|
+
"image/jpeg",
|
|
35
|
+
"image/png",
|
|
36
|
+
"image/webp",
|
|
37
|
+
"audio/mp3",
|
|
38
|
+
"audio/wav",
|
|
39
|
+
"audio/m4a",
|
|
40
|
+
"video/mp4",
|
|
41
|
+
"video/mov",
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
if (!supportedTypes.includes(file.type)) {
|
|
45
|
+
errors.push(`Unsupported file type: ${file.type}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Media-specific validations
|
|
49
|
+
if (file.type.startsWith("image/")) {
|
|
50
|
+
if (file.size > 5 * 1024 * 1024) {
|
|
51
|
+
// 5MB for images
|
|
52
|
+
warnings.push("Very large image may cause performance issues");
|
|
53
|
+
recommendations.push("Consider resizing image to under 5MB");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (file.type.startsWith("audio/") || file.type.startsWith("video/")) {
|
|
58
|
+
const duration = await getMediaDuration(file);
|
|
59
|
+
if (duration && duration > 300) {
|
|
60
|
+
// 5 minutes
|
|
61
|
+
warnings.push("Long audio/video files may impact app performance");
|
|
62
|
+
recommendations.push("Consider trimming to under 5 minutes");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
isValid: errors.length === 0,
|
|
68
|
+
errors,
|
|
69
|
+
warnings,
|
|
70
|
+
recommendations,
|
|
71
|
+
};
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return {
|
|
74
|
+
isValid: false,
|
|
75
|
+
errors: [error instanceof Error ? error.message : "Validation failed"],
|
|
76
|
+
warnings: [],
|
|
77
|
+
recommendations: [],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# CardMultimediaService
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Central service for managing all media operations in card-based applications, combining upload, generation, validation, and optimization capabilities through a singleton instance with card-specific media support.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`/Users/umituz/Desktop/github/umituz/apps/artificial_intelligence/npm-packages/react-native-media/src/infrastructure/services/CardMultimediaService`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Provide unified interface for all card media operations
|
|
11
|
+
- Coordinate upload, generation, validation, and optimization services
|
|
12
|
+
- Maintain singleton pattern for resource efficiency
|
|
13
|
+
- Support card-specific media requirements (front/back/both positions)
|
|
14
|
+
- Simplify media management for card applications
|
|
15
|
+
- Enable batch operations for card sets
|
|
16
|
+
- Provide consistent API across all media operations
|
|
17
|
+
- Handle card-specific metadata and associations
|
|
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 card media with non-card media types
|
|
27
|
+
- **DO NOT** assume all operations will succeed
|
|
28
|
+
- **DO NOT** ignore card-specific position requirements
|
|
29
|
+
|
|
30
|
+
## Rules
|
|
31
|
+
1. MUST use getInstance() to retrieve service instance
|
|
32
|
+
2. MUST NOT create new instances with constructor
|
|
33
|
+
3. MUST maintain single instance across application lifecycle
|
|
34
|
+
4. MUST validate media before upload operations
|
|
35
|
+
5. MUST support CardMediaAttachment and CardMediaPosition types
|
|
36
|
+
6. MUST handle position attribute (front/back/both) correctly
|
|
37
|
+
7. MUST handle all operation failures gracefully
|
|
38
|
+
8. MUST provide consistent interface through all methods
|
|
39
|
+
9. MUST initialize all sub-services on first use
|
|
40
|
+
10. MUST coordinate between sub-services for complex operations
|
|
41
|
+
11. MUST handle asynchronous operations properly
|
|
42
|
+
12. MUST return appropriate error messages for failures
|
|
43
|
+
13. MUST support card-specific media constraints
|
|
44
|
+
|
|
45
|
+
## AI Agent Guidelines
|
|
46
|
+
|
|
47
|
+
When working with CardMultimediaService:
|
|
48
|
+
|
|
49
|
+
1. **Singleton Pattern**: Always use getInstance(), never constructor
|
|
50
|
+
2. **Validation First**: Validate before upload or generation
|
|
51
|
+
3. **Position Awareness**: Always consider card position (front/back/both)
|
|
52
|
+
4. **Operation Flow**: Follow validate -> upload/generate -> optimize -> store
|
|
53
|
+
5. **Error Handling**: Handle errors at each step appropriately
|
|
54
|
+
6. **Resource Management**: Rely on singleton for efficient resource use
|
|
55
|
+
7. **Type Safety**: Use CardMediaAttachment and CardMediaPosition types
|
|
56
|
+
8. **Card Context**: Maintain card-specific context throughout operations
|
|
57
|
+
|
|
58
|
+
### Card Creation Workflow
|
|
59
|
+
|
|
60
|
+
- **Step 1 - Get Instance**: `CardMultimediaService.getInstance()`
|
|
61
|
+
- **Step 2 - Select File**: Pick file from device or camera
|
|
62
|
+
- **Step 3 - Validate**: Run validation, check results
|
|
63
|
+
- **Step 4 - Upload**: Upload if validation passes
|
|
64
|
+
- **Step 5 - Set Position**: Assign position (front/back/both)
|
|
65
|
+
- **Step 6 - Optimize** (Optional): Optimize if file is large
|
|
66
|
+
- **Step 7 - Store**: Save attachment with card data
|
|
67
|
+
- **Step 8 - Handle Errors**: Provide feedback at each step
|
|
68
|
+
|
|
69
|
+
### Media Upload with Position
|
|
70
|
+
|
|
71
|
+
- Use for user-selected media on card sides
|
|
72
|
+
- Always validate before uploading
|
|
73
|
+
- Set position based on card side (front/back/both)
|
|
74
|
+
- Consider compression for large files
|
|
75
|
+
- Store returned attachment with card
|
|
76
|
+
- Handle upload failures with user feedback
|
|
77
|
+
|
|
78
|
+
### AI Content Generation for Cards
|
|
79
|
+
|
|
80
|
+
- Use for text-to-image or text-to-audio generation
|
|
81
|
+
- Validate prompts before generation
|
|
82
|
+
- Check credit/balance availability
|
|
83
|
+
- Set position based on use case (front for questions, back for answers)
|
|
84
|
+
- Handle generation failures gracefully
|
|
85
|
+
- Store successful attachments with card
|
|
86
|
+
|
|
87
|
+
### Position Management
|
|
88
|
+
|
|
89
|
+
- **Front**: Media displayed on card front side
|
|
90
|
+
- Typically contains questions or prompts
|
|
91
|
+
- Often uses text-to-image generation
|
|
92
|
+
- May require higher quality
|
|
93
|
+
|
|
94
|
+
- **Back**: Media displayed on card back side
|
|
95
|
+
- Typically contains answers or explanations
|
|
96
|
+
- Often uses text-to-audio generation
|
|
97
|
+
- Can be more compressed
|
|
98
|
+
|
|
99
|
+
- **Both**: Media used on both sides
|
|
100
|
+
- Shared content between sides
|
|
101
|
+
- Less common but supported
|
|
102
|
+
- Maintain consistency across sides
|
|
103
|
+
|
|
104
|
+
### Media Optimization for Cards
|
|
105
|
+
|
|
106
|
+
- Use when file size impacts performance
|
|
107
|
+
- Choose quality level based on position (front = higher, back = lower)
|
|
108
|
+
- Consider card importance and frequency of use
|
|
109
|
+
- Calculate expected size reduction
|
|
110
|
+
- Preserve position through optimization
|
|
111
|
+
- Update card with optimized media
|
|
112
|
+
|
|
113
|
+
### Media Deletion for Cards
|
|
114
|
+
|
|
115
|
+
- Verify media ownership before deletion
|
|
116
|
+
- Check card associations and dependencies
|
|
117
|
+
- Confirm deletion with user if needed
|
|
118
|
+
- Delete from all storage locations
|
|
119
|
+
- Update card references
|
|
120
|
+
- Handle missing files gracefully
|
|
121
|
+
|
|
122
|
+
### Batch Operations for Card Sets
|
|
123
|
+
|
|
124
|
+
- For multiple cards, use same service instance
|
|
125
|
+
- Process uploads/generations in sequence
|
|
126
|
+
- Collect results before saving
|
|
127
|
+
- Handle partial failures appropriately
|
|
128
|
+
- Consider parallel operations for independent media
|
|
129
|
+
- Track progress for user feedback
|
|
130
|
+
- Maintain position consistency across cards
|
|
131
|
+
|
|
132
|
+
### Error Handling Patterns
|
|
133
|
+
|
|
134
|
+
- **Validation Errors**: Show to user, block upload
|
|
135
|
+
- **Upload Errors**: Retry or allow alternative file
|
|
136
|
+
- **Generation Errors**: Check credits, try different prompt
|
|
137
|
+
- **Optimization Errors**: Continue with original media
|
|
138
|
+
- **Deletion Errors**: Log error, notify user
|
|
139
|
+
- **Position Errors**: Validate position before operations
|
|
140
|
+
- **Network Errors**: Show connection message, allow retry
|
|
141
|
+
|
|
142
|
+
### Card-Specific Considerations
|
|
143
|
+
|
|
144
|
+
- **Front Media**: Often focal point, prioritize quality
|
|
145
|
+
- **Back Media**: Secondary content, can be more compressed
|
|
146
|
+
- **Both Position**: Ensure quality works for both sides
|
|
147
|
+
- **Multiple Media**: Support multiple attachments per card
|
|
148
|
+
- **Position Validation**: Validate media type compatibility with position
|
|
149
|
+
- **Card Associations**: Maintain references between media and cards
|
|
150
|
+
|
|
151
|
+
### Service Coordination
|
|
152
|
+
|
|
153
|
+
The service automatically coordinates:
|
|
154
|
+
- CardMediaUploadService handles file uploads
|
|
155
|
+
- CardMediaGenerationService handles AI generation
|
|
156
|
+
- CardMediaValidationService checks file validity
|
|
157
|
+
- CardMediaOptimizerService handles compression
|
|
158
|
+
- All services work together with card-specific requirements
|
|
159
|
+
|
|
160
|
+
### Performance Considerations
|
|
161
|
+
|
|
162
|
+
- Singleton reduces memory footprint
|
|
163
|
+
- Single instance maintains state efficiently
|
|
164
|
+
- Sub-services initialized once
|
|
165
|
+
- All operations are asynchronous
|
|
166
|
+
- Consider lazy loading for large card sets
|
|
167
|
+
- Cache media URLs when possible
|
|
168
|
+
- Optimize media based on card usage patterns
|
|
169
|
+
|
|
170
|
+
## Dependencies
|
|
171
|
+
- CardMediaUploadService for upload operations
|
|
172
|
+
- CardMediaGenerationService for AI generation (including image-search)
|
|
173
|
+
- CardMediaValidationService for validation
|
|
174
|
+
- CardMediaOptimizerService for optimization
|
|
175
|
+
- CardMediaAttachment type from domain layer
|
|
176
|
+
- CardMediaPosition type for card-side placement
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card Multimedia Flashcard Service
|
|
3
|
+
* Media attachments for flashcards - Main entry point
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
CardMediaAttachment,
|
|
8
|
+
CardMediaGenerationRequest,
|
|
9
|
+
CardMediaGenerationResult,
|
|
10
|
+
CardMediaCompressionOptions,
|
|
11
|
+
CardMediaValidation,
|
|
12
|
+
CardMultimediaFlashcardService as ICardMultimediaFlashcardService,
|
|
13
|
+
} from "../../domain/entities/CardMultimedia.types";
|
|
14
|
+
import { CardMediaUploadService } from "./CardMediaUploadService";
|
|
15
|
+
import { CardMediaGenerationService } from "./CardMediaGenerationService";
|
|
16
|
+
import { CardMediaValidationService } from "./CardMediaValidationService";
|
|
17
|
+
import { CardMediaOptimizerService } from "./CardMediaOptimizerService";
|
|
18
|
+
|
|
19
|
+
export class CardMultimediaFlashcardService implements ICardMultimediaFlashcardService {
|
|
20
|
+
private static instance: CardMultimediaFlashcardService;
|
|
21
|
+
private uploadService: CardMediaUploadService;
|
|
22
|
+
private generationService: CardMediaGenerationService;
|
|
23
|
+
private validationService: CardMediaValidationService;
|
|
24
|
+
private optimizerService: CardMediaOptimizerService;
|
|
25
|
+
|
|
26
|
+
private constructor() {
|
|
27
|
+
this.uploadService = new CardMediaUploadService();
|
|
28
|
+
this.generationService = new CardMediaGenerationService();
|
|
29
|
+
this.validationService = new CardMediaValidationService();
|
|
30
|
+
this.optimizerService = new CardMediaOptimizerService();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static getInstance(): CardMultimediaFlashcardService {
|
|
34
|
+
if (!CardMultimediaFlashcardService.instance) {
|
|
35
|
+
CardMultimediaFlashcardService.instance =
|
|
36
|
+
new CardMultimediaFlashcardService();
|
|
37
|
+
}
|
|
38
|
+
return CardMultimediaFlashcardService.instance;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Upload media file with optional compression
|
|
43
|
+
*/
|
|
44
|
+
async uploadMedia(
|
|
45
|
+
file: any,
|
|
46
|
+
options?: CardMediaCompressionOptions,
|
|
47
|
+
): Promise<CardMediaAttachment> {
|
|
48
|
+
return this.uploadService.uploadMedia(file, options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Generate media from AI (text-to-image, text-to-audio, etc.)
|
|
53
|
+
*/
|
|
54
|
+
async generateMedia(
|
|
55
|
+
request: CardMediaGenerationRequest,
|
|
56
|
+
): Promise<CardMediaGenerationResult> {
|
|
57
|
+
return this.generationService.generateMedia(request);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Validate media file before upload
|
|
62
|
+
*/
|
|
63
|
+
async validateMedia(file: any): Promise<CardMediaValidation> {
|
|
64
|
+
return this.validationService.validateMedia(file);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Optimize media file
|
|
69
|
+
*/
|
|
70
|
+
async optimizeMedia(
|
|
71
|
+
attachment: CardMediaAttachment,
|
|
72
|
+
options: CardMediaCompressionOptions,
|
|
73
|
+
): Promise<CardMediaAttachment> {
|
|
74
|
+
return this.optimizerService.optimizeMedia(attachment, options);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Delete media attachment
|
|
79
|
+
*/
|
|
80
|
+
async deleteMedia(attachmentId: string): Promise<void> {
|
|
81
|
+
return this.optimizerService.deleteMedia(attachmentId);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get media URL
|
|
86
|
+
*/
|
|
87
|
+
async getMediaUrl(attachmentId: string): Promise<string> {
|
|
88
|
+
return this.uploadService.getMediaUrl(attachmentId);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Download media to local storage
|
|
93
|
+
*/
|
|
94
|
+
async downloadMedia(attachmentId: string): Promise<string> {
|
|
95
|
+
return this.uploadService.downloadMedia(attachmentId);
|
|
96
|
+
}
|
|
97
|
+
}
|