@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.
- package/package.json +1 -1
- package/src/atoms/AtomicInput.tsx +0 -2
- package/src/media/domain/entities/{MultimediaFlashcardTypes.ts → MediaAttachments.ts} +13 -32
- package/src/media/index.ts +24 -23
- package/src/media/infrastructure/services/MediaGenerationService.ts +1 -1
- package/src/media/infrastructure/services/MediaOptimizerService.ts +1 -1
- package/src/media/infrastructure/services/MediaUploadService.ts +1 -1
- package/src/media/infrastructure/services/MediaValidationService.ts +1 -1
- package/src/media/infrastructure/services/MultimediaFlashcardService.ts +1 -1
- package/src/media/infrastructure/utils/PermissionManager.ts +1 -1
- package/src/media/infrastructure/utils/media-collection-utils.ts +4 -2
- package/src/media/infrastructure/utils/mediaPickerMappers.ts +1 -1
- package/src/media/presentation/hooks/multimedia.types.ts +1 -1
- package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +4 -4
- package/src/media/presentation/hooks/useMedia.ts +2 -2
- package/src/media/presentation/hooks/useMediaGeneration.ts +1 -1
- package/src/media/presentation/hooks/useMediaUpload.ts +1 -1
- package/src/media/presentation/hooks/useMediaValidation.ts +1 -1
- package/src/media/presentation/hooks/useMultimediaFlashcard.ts +1 -1
- package/src/molecules/navigation/utils/AppNavigation.ts +3 -3
- package/src/storage/infrastructure/adapters/StorageService.ts +3 -3
- package/src/storage/infrastructure/repositories/BaseStorageOperations.ts +5 -5
- package/src/storage/presentation/hooks/CacheStorageOperations.ts +3 -3
- package/src/storage/presentation/hooks/useStore.ts +0 -1
- package/src/media/domain/entities/CardMultimedia.types.README.md +0 -129
- package/src/media/domain/entities/Media.README.md +0 -80
- package/src/media/domain/entities/MultimediaFlashcardTypes.README.md +0 -144
- package/src/media/domain/utils/MediaUtils.README.md +0 -178
- package/src/media/index.ts.README.md +0 -191
- package/src/media/infrastructure/services/CardMultimediaService.README.md +0 -176
- package/src/media/infrastructure/services/CardMultimediaService.ts +0 -98
- package/src/media/infrastructure/services/MediaGenerationService.README.md +0 -142
- package/src/media/infrastructure/services/MediaOptimizerService.README.md +0 -145
- package/src/media/infrastructure/services/MediaPickerService.README.md +0 -106
- package/src/media/infrastructure/services/MediaSaveService.README.md +0 -120
- package/src/media/infrastructure/services/MediaUploadService.README.md +0 -135
- package/src/media/infrastructure/services/MediaValidationService.README.md +0 -135
- package/src/media/infrastructure/services/MultimediaFlashcardService.README.md +0 -142
- package/src/media/infrastructure/utils/mediaHelpers.README.md +0 -96
- package/src/media/infrastructure/utils/mediaPickerMappers.README.md +0 -129
- package/src/media/presentation/hooks/card-multimedia.types.README.md +0 -177
- package/src/media/presentation/hooks/card-multimedia.types.ts +0 -53
- package/src/media/presentation/hooks/multimedia.types.README.md +0 -201
- package/src/media/presentation/hooks/useCardMediaGeneration.ts +0 -20
- package/src/media/presentation/hooks/useCardMediaUpload.ts +0 -84
- package/src/media/presentation/hooks/useCardMediaValidation.ts +0 -104
- package/src/media/presentation/hooks/useCardMultimediaFlashcard.README.md +0 -158
- package/src/media/presentation/hooks/useMedia.README.md +0 -94
- package/src/media/presentation/hooks/useMediaGeneration.README.md +0 -118
- package/src/media/presentation/hooks/useMediaUpload.README.md +0 -108
- package/src/media/presentation/hooks/useMediaValidation.README.md +0 -134
- package/src/media/presentation/hooks/useMultimediaFlashcard.README.md +0 -141
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Card Media Validation Hook
|
|
3
|
-
* Hook for validating card media files
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useState, useCallback } from "react";
|
|
7
|
-
import { formatFileSize } from "../../infrastructure/utils/media-collection-utils";
|
|
8
|
-
import type { UseCardMediaValidationResult } from "./card-multimedia.types";
|
|
9
|
-
import type {
|
|
10
|
-
MediaValidation as CardMediaValidation,
|
|
11
|
-
MediaFile as CardMediaFile,
|
|
12
|
-
} from "../../domain/entities/MultimediaFlashcardTypes";
|
|
13
|
-
|
|
14
|
-
export const useCardMediaValidation = (): UseCardMediaValidationResult => {
|
|
15
|
-
const [isValidating, setIsValidating] = useState(false);
|
|
16
|
-
const [validation, setValidation] =
|
|
17
|
-
useState<CardMediaValidation | null>(null);
|
|
18
|
-
const [error, setError] = useState<string | null>(null);
|
|
19
|
-
|
|
20
|
-
const validateMedia = useCallback(
|
|
21
|
-
async (file: CardMediaFile): Promise<CardMediaValidation> => {
|
|
22
|
-
try {
|
|
23
|
-
setIsValidating(true);
|
|
24
|
-
setError(null);
|
|
25
|
-
|
|
26
|
-
// Simulate validation
|
|
27
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
28
|
-
|
|
29
|
-
const errors: string[] = [];
|
|
30
|
-
const warnings: string[] = [];
|
|
31
|
-
const recommendations: string[] = [];
|
|
32
|
-
|
|
33
|
-
// File size validation
|
|
34
|
-
const maxSize = 50 * 1024 * 1024; // 50MB
|
|
35
|
-
if (file.size > maxSize) {
|
|
36
|
-
errors.push(
|
|
37
|
-
`File size (${formatFileSize(file.size)}) exceeds maximum allowed size (${formatFileSize(maxSize)})`,
|
|
38
|
-
);
|
|
39
|
-
} else if (file.size > 10 * 1024 * 1024) {
|
|
40
|
-
// 10MB
|
|
41
|
-
warnings.push(`Large file size may impact performance`);
|
|
42
|
-
recommendations.push("Consider compressing file");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// File type validation
|
|
46
|
-
const supportedTypes = [
|
|
47
|
-
"image/jpeg",
|
|
48
|
-
"image/png",
|
|
49
|
-
"image/webp",
|
|
50
|
-
"audio/mp3",
|
|
51
|
-
"audio/wav",
|
|
52
|
-
"audio/m4a",
|
|
53
|
-
"video/mp4",
|
|
54
|
-
"video/mov",
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
if (!supportedTypes.includes(file.type)) {
|
|
58
|
-
errors.push(`Unsupported file type: ${file.type}`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Media-specific validations
|
|
62
|
-
if (file.type.startsWith("image/")) {
|
|
63
|
-
if (file.size > 5 * 1024 * 1024) {
|
|
64
|
-
// 5MB for images
|
|
65
|
-
warnings.push("Very large image may cause performance issues");
|
|
66
|
-
recommendations.push("Consider resizing image to under 5MB");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const result: CardMediaValidation = {
|
|
71
|
-
isValid: errors.length === 0,
|
|
72
|
-
errors,
|
|
73
|
-
warnings,
|
|
74
|
-
recommendations,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
setValidation(result);
|
|
78
|
-
return result;
|
|
79
|
-
} catch (err) {
|
|
80
|
-
const errorMessage =
|
|
81
|
-
err instanceof Error ? err.message : "Validation failed";
|
|
82
|
-
setError(errorMessage);
|
|
83
|
-
setIsValidating(false);
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
isValid: false,
|
|
87
|
-
errors: [errorMessage],
|
|
88
|
-
warnings: [],
|
|
89
|
-
recommendations: [],
|
|
90
|
-
};
|
|
91
|
-
} finally {
|
|
92
|
-
setIsValidating(false);
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
[],
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
validateMedia,
|
|
100
|
-
isValidating,
|
|
101
|
-
validation,
|
|
102
|
-
error,
|
|
103
|
-
};
|
|
104
|
-
};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# useCardMultimediaFlashcard
|
|
2
|
-
|
|
3
|
-
## Purpose
|
|
4
|
-
Card-specific hook for creating and managing flashcards with media attachments using CardMediaAttachment types.
|
|
5
|
-
|
|
6
|
-
## File Location
|
|
7
|
-
`src/presentation/hooks/useCardMultimediaFlashcard.ts`
|
|
8
|
-
|
|
9
|
-
## Strategy
|
|
10
|
-
- Provide card-specific interface for flashcard creation with media
|
|
11
|
-
- Support CardMediaAttachment with position-aware media management
|
|
12
|
-
- Enable card-specific media operations (create, update, delete)
|
|
13
|
-
- Automatically analyze card media composition
|
|
14
|
-
- Calculate storage requirements for card media
|
|
15
|
-
- Track download status for offline card access
|
|
16
|
-
- Maintain card-specific ID prefixes and naming conventions
|
|
17
|
-
|
|
18
|
-
## Forbidden
|
|
19
|
-
- **DO NOT** create cards without required front/back content
|
|
20
|
-
- **DO NOT** add media without position assignment (front, back, both)
|
|
21
|
-
- **DO NOT** mix MediaAttachment with CardMediaAttachment types
|
|
22
|
-
- **DO NOT** use mock implementations in production
|
|
23
|
-
- **DO NOT** assume card media is downloaded without checking
|
|
24
|
-
- **DO NOT** modify card structure directly after creation
|
|
25
|
-
- **DO NOT** exceed practical media limits per card
|
|
26
|
-
- **DO NOT** bypass media size estimation
|
|
27
|
-
- **DO NOT** use incorrect ID prefixes (must use card_multimedia_)
|
|
28
|
-
|
|
29
|
-
## Rules
|
|
30
|
-
1. Always use CardMediaAttachment type (not MediaAttachment)
|
|
31
|
-
2. Always assign position (front, back, both) to each media
|
|
32
|
-
3. Use card_multimedia_ prefix for card IDs
|
|
33
|
-
4. Calculate estimatedSize from all card media
|
|
34
|
-
5. Populate mediaType array with unique types
|
|
35
|
-
6. Set hasMedia based on media array length
|
|
36
|
-
7. Check isDownloaded from all media attachments
|
|
37
|
-
8. Support empty media array for text-only cards
|
|
38
|
-
9. Return complete CardMultimediaFlashcard object
|
|
39
|
-
10. Clear processing state on completion
|
|
40
|
-
|
|
41
|
-
## AI Agent Guidelines
|
|
42
|
-
|
|
43
|
-
When working with useCardMultimediaFlashcard hook:
|
|
44
|
-
|
|
45
|
-
1. **Type Correctness**: Always use CardMediaAttachment (not MediaAttachment)
|
|
46
|
-
2. **Position Assignment**: Every media must have position (front, back, both)
|
|
47
|
-
3. **Media Upload**: Use useCardMediaUpload for proper type handling
|
|
48
|
-
4. **Card Analysis**: Leverage auto-generated hasMedia, mediaType, isDownloaded
|
|
49
|
-
5. **ID Prefixes**: Ensure card IDs use card_multimedia_ prefix
|
|
50
|
-
|
|
51
|
-
### Card Creation Workflow
|
|
52
|
-
|
|
53
|
-
1. Prepare card content (front, back, difficulty, tags)
|
|
54
|
-
2. Upload media using useCardMediaUpload (gets CardMediaAttachment)
|
|
55
|
-
3. Assign position to each media attachment
|
|
56
|
-
4. Call createCardMultimedia with data
|
|
57
|
-
5. Receive CardMultimediaFlashcard object
|
|
58
|
-
6. Store or display the completed card
|
|
59
|
-
|
|
60
|
-
### CardMultimediaFlashcard Structure
|
|
61
|
-
|
|
62
|
-
CardMultimediaFlashcard includes:
|
|
63
|
-
- id: Unique card ID (card_multimedia_ prefix)
|
|
64
|
-
- front: Front side content
|
|
65
|
-
- back: Back side content
|
|
66
|
-
- difficulty: easy/medium/hard
|
|
67
|
-
- tags: Topic tags array
|
|
68
|
-
- media: Array of CardMediaAttachment
|
|
69
|
-
- hasMedia: Boolean flag
|
|
70
|
-
- mediaType: Array of media types (image, audio, video)
|
|
71
|
-
- isDownloaded: Boolean (all media downloaded)
|
|
72
|
-
- estimatedSize: Total size in bytes
|
|
73
|
-
- createdAt: ISO timestamp
|
|
74
|
-
|
|
75
|
-
### CardMediaAttachment vs MediaAttachment
|
|
76
|
-
|
|
77
|
-
Key differences:
|
|
78
|
-
- CardMediaAttachment has position property (front, back, both)
|
|
79
|
-
- CardMediaAttachment IDs use card_media_ prefix
|
|
80
|
-
- CardMediaAttachment uses CardMediaPosition enum
|
|
81
|
-
- CardMediaAttachment uses CardMediaType enum
|
|
82
|
-
|
|
83
|
-
### Media Positioning Strategy
|
|
84
|
-
|
|
85
|
-
**front**: Media for front side of card
|
|
86
|
-
- Question images
|
|
87
|
-
- Prompt audio
|
|
88
|
-
- Instructional videos
|
|
89
|
-
|
|
90
|
-
**back**: Media for back side of card
|
|
91
|
-
- Answer images
|
|
92
|
-
- Explanation audio
|
|
93
|
-
- Solution videos
|
|
94
|
-
|
|
95
|
-
**both**: Media for both sides
|
|
96
|
-
- Background music
|
|
97
|
-
- Contextual images
|
|
98
|
-
- Reference materials
|
|
99
|
-
|
|
100
|
-
### Card Management Functions
|
|
101
|
-
|
|
102
|
-
**createCardMultimedia**: Create new card
|
|
103
|
-
- Requires front and back content
|
|
104
|
-
- Accepts CardMediaAttachment array
|
|
105
|
-
- Assigns unique card_multimedia_ ID
|
|
106
|
-
- Analyzes media composition
|
|
107
|
-
- Calculates storage requirements
|
|
108
|
-
|
|
109
|
-
**updateCardMedia**: Replace media on card
|
|
110
|
-
- Takes cardId and new media array
|
|
111
|
-
- Preserves card metadata
|
|
112
|
-
- Re-analyzes composition
|
|
113
|
-
- Updates size calculation
|
|
114
|
-
|
|
115
|
-
**deleteCardMedia**: Remove specific media
|
|
116
|
-
- Takes attachmentId (card_media_ prefix)
|
|
117
|
-
- Updates media array
|
|
118
|
-
- Recalculates size
|
|
119
|
-
- Updates analysis
|
|
120
|
-
|
|
121
|
-
### Integration with Card Hooks
|
|
122
|
-
|
|
123
|
-
Use with card-specific hooks:
|
|
124
|
-
- useCardMediaUpload: Upload with CardMediaAttachment type
|
|
125
|
-
- useCardMediaValidation: Validate with card-specific rules
|
|
126
|
-
- useCardMediaGeneration: Generate AI media for cards
|
|
127
|
-
|
|
128
|
-
### Card Media Analysis
|
|
129
|
-
|
|
130
|
-
**hasMedia**: True if media array length > 0
|
|
131
|
-
**mediaType**: Unique array ['image', 'audio', 'video'] based on media
|
|
132
|
-
**isDownloaded**: True if all media.isDownloaded are true
|
|
133
|
-
**estimatedSize**: Sum of all media.fileSize values
|
|
134
|
-
|
|
135
|
-
### Performance Guidelines
|
|
136
|
-
|
|
137
|
-
- Limit to 5-10 media items per card
|
|
138
|
-
- Warn if estimatedSize exceeds 25 MB
|
|
139
|
-
- Use position to organize media effectively
|
|
140
|
-
- Consider download status for offline usage
|
|
141
|
-
- Balance media types across card sides
|
|
142
|
-
|
|
143
|
-
### Best Practices
|
|
144
|
-
|
|
145
|
-
1. Always assign meaningful positions to media
|
|
146
|
-
2. Use tags for card organization and filtering
|
|
147
|
-
3. Set appropriate difficulty levels
|
|
148
|
-
4. Balance media between front and back
|
|
149
|
-
5. Consider offline usage patterns
|
|
150
|
-
6. Validate media before adding to cards
|
|
151
|
-
|
|
152
|
-
## Dependencies
|
|
153
|
-
|
|
154
|
-
- CardMultimediaFlashcardService (infrastructure layer)
|
|
155
|
-
- Domain types: CardMultimediaFlashcard, CardMediaAttachment
|
|
156
|
-
- useCardMediaUpload (for card-specific upload)
|
|
157
|
-
- useCardMediaValidation (for card-specific validation)
|
|
158
|
-
- useCardMediaGeneration (for card AI media)
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# useMedia
|
|
2
|
-
|
|
3
|
-
## Purpose
|
|
4
|
-
Core React hook for media selection operations (image/video picking, camera access) in React Native applications.
|
|
5
|
-
|
|
6
|
-
## File Location
|
|
7
|
-
`src/presentation/hooks/useMedia.ts`
|
|
8
|
-
|
|
9
|
-
## Strategy
|
|
10
|
-
- Provide unified interface for media picker and camera operations
|
|
11
|
-
- Abstract expo-image-picker complexity from components
|
|
12
|
-
- Centralize permission management logic
|
|
13
|
-
- Maintain consistent state management across media operations
|
|
14
|
-
- Enable type-safe media operations with proper TypeScript interfaces
|
|
15
|
-
- Support single and multiple media selection workflows
|
|
16
|
-
- Handle loading states and error propagation
|
|
17
|
-
|
|
18
|
-
## Forbidden
|
|
19
|
-
- **DO NOT** expose expo-image-picker implementation details to consumers
|
|
20
|
-
- **DO NOT** automatically request permissions without explicit user action
|
|
21
|
-
- **DO NOT** mix camera and library picker logic in single operations
|
|
22
|
-
- **DO NOT** assume permission states - always check before operations
|
|
23
|
-
- **DO NOT** bypass error handling or loading states
|
|
24
|
-
- **DO NOT** use mock implementations in production without clear warnings
|
|
25
|
-
- **DO NOT** allow operations while previous operation is in progress
|
|
26
|
-
- **DO NOT** modify media assets after selection
|
|
27
|
-
- **DO NOT** store selected media permanently in hook state
|
|
28
|
-
|
|
29
|
-
## Rules
|
|
30
|
-
1. Always check permission status before camera/library operations
|
|
31
|
-
2. All picker operations must return MediaPickerResult with canceled flag
|
|
32
|
-
3. Loading state must be true during async operations
|
|
33
|
-
4. Error state must be cleared on new operation attempts
|
|
34
|
-
5. Permission requests must be explicit, not automatic
|
|
35
|
-
6. Selected media must be validated against type definitions
|
|
36
|
-
7. Quality parameters must be in 0-1 range
|
|
37
|
-
8. Aspect ratio must be [width, height] tuple
|
|
38
|
-
9. File size must be included when available from picker
|
|
39
|
-
10. Support both single and multiple selection based on function used
|
|
40
|
-
|
|
41
|
-
## AI Agent Guidelines
|
|
42
|
-
|
|
43
|
-
When working with useMedia hook:
|
|
44
|
-
|
|
45
|
-
1. **Permission First**: Always request/check permissions before calling picker or camera functions
|
|
46
|
-
2. **State Management**: Use isLoading to prevent duplicate operations during active calls
|
|
47
|
-
3. **Error Handling**: Always check error state and handle user cancellation (canceled: true)
|
|
48
|
-
4. **Type Safety**: Use MediaPickerOptions and CameraOptions interfaces for configuration
|
|
49
|
-
5. **Validation**: Validate returned assets before processing (check if assets array exists)
|
|
50
|
-
|
|
51
|
-
### Key Functions
|
|
52
|
-
|
|
53
|
-
- **pickImage**: Single image selection from library with optional editing
|
|
54
|
-
- **pickMultipleImages**: Multiple image selection with selection limit
|
|
55
|
-
- **pickVideo**: Video selection from library
|
|
56
|
-
- **launchCamera**: Photo capture via device camera
|
|
57
|
-
- **launchCameraForVideo**: Video recording via device camera
|
|
58
|
-
- **requestCameraPermission**: Request camera access permission
|
|
59
|
-
- **requestMediaLibraryPermission**: Request photo library access permission
|
|
60
|
-
- **getCameraPermissionStatus**: Check current camera permission state
|
|
61
|
-
- **getMediaLibraryPermissionStatus**: Check current library permission state
|
|
62
|
-
|
|
63
|
-
### Media Selection Workflow
|
|
64
|
-
|
|
65
|
-
1. Check permission status before operation
|
|
66
|
-
2. Request permission if not granted
|
|
67
|
-
3. Call appropriate picker/camera function with options
|
|
68
|
-
4. Check canceled flag before processing assets
|
|
69
|
-
5. Validate assets array exists and has items
|
|
70
|
-
6. Process first asset (or all for multiple selection)
|
|
71
|
-
|
|
72
|
-
### Quality Guidelines
|
|
73
|
-
|
|
74
|
-
- HIGH (1.0): Original quality, largest file size
|
|
75
|
-
- MEDIUM (0.7): Balanced quality and size (recommended)
|
|
76
|
-
- LOW (0.3): Smallest file size, reduced quality
|
|
77
|
-
|
|
78
|
-
### Platform Requirements
|
|
79
|
-
|
|
80
|
-
- **iOS**: Add NSCameraUsageDescription and NSPhotoLibraryUsageDescription to Info.plist
|
|
81
|
-
- **Android**: Add CAMERA and READ_EXTERNAL_STORAGE permissions to AndroidManifest.xml
|
|
82
|
-
|
|
83
|
-
### State Management
|
|
84
|
-
|
|
85
|
-
- **isLoading**: True during any async picker/camera operation
|
|
86
|
-
- **error**: String error message or null, cleared on new operations
|
|
87
|
-
- **MediaPickerResult.canceled**: True when user cancels operation
|
|
88
|
-
- **MediaPickerResult.assets**: Array of selected media or undefined
|
|
89
|
-
|
|
90
|
-
## Dependencies
|
|
91
|
-
|
|
92
|
-
- MediaPickerService (infrastructure layer)
|
|
93
|
-
- Domain types: MediaAsset, MediaPickerResult, MediaPickerOptions, CameraOptions
|
|
94
|
-
- expo-image-picker (via service layer)
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# useMediaGeneration
|
|
2
|
-
|
|
3
|
-
## Purpose
|
|
4
|
-
React hook for AI-powered media generation (text-to-image, text-to-audio) with result tracking.
|
|
5
|
-
|
|
6
|
-
## File Location
|
|
7
|
-
`src/presentation/hooks/useMediaGeneration.ts`
|
|
8
|
-
|
|
9
|
-
## Strategy
|
|
10
|
-
- Provide unified interface for AI media generation operations
|
|
11
|
-
- Support multiple generation types (text-to-image, text-to-audio)
|
|
12
|
-
- Track generation status and progress
|
|
13
|
-
- Manage credit usage and balance tracking
|
|
14
|
-
- Handle generation errors gracefully
|
|
15
|
-
- Return structured results with metadata
|
|
16
|
-
- Support customizable generation options
|
|
17
|
-
|
|
18
|
-
## Forbidden
|
|
19
|
-
- **DO NOT** start new generation while previous is in progress
|
|
20
|
-
- **DO NOT** ignore credit costs before generation
|
|
21
|
-
- **DO NOT** mock generation process in production without API integration
|
|
22
|
-
- **DO NOT** assume generation will succeed - always check result.success
|
|
23
|
-
- **DO NOT** expose API keys or AI service implementation details
|
|
24
|
-
- **DO NOT** allow unlimited concurrent generations
|
|
25
|
-
- **DO NOT** bypass generation timeout handling
|
|
26
|
-
- **DO NOT** store large generation results permanently in hook state
|
|
27
|
-
- **DO NOT** use empty or invalid prompts for generation
|
|
28
|
-
|
|
29
|
-
## Rules
|
|
30
|
-
1. Always validate prompt text before generation
|
|
31
|
-
2. Check credit availability before generation operations
|
|
32
|
-
3. Track processing time for each generation request
|
|
33
|
-
4. Return unique requestId for each generation
|
|
34
|
-
5. Support maxResults parameter for multiple outputs
|
|
35
|
-
6. Generation state must be cleared on new operations
|
|
36
|
-
7. Include creditsUsed in result metadata
|
|
37
|
-
8. Handle both success and failure in result object
|
|
38
|
-
9. Support language and voice options for audio generation
|
|
39
|
-
10. Support style options for image generation
|
|
40
|
-
|
|
41
|
-
## AI Agent Guidelines
|
|
42
|
-
|
|
43
|
-
When working with useMediaGeneration hook:
|
|
44
|
-
|
|
45
|
-
1. **Prompt Quality**: Use descriptive, specific prompts for better results
|
|
46
|
-
2. **Credit Management**: Track credit costs and balance before operations
|
|
47
|
-
3. **Error Handling**: Always check result.success field
|
|
48
|
-
4. **Result Processing**: Validate attachments array before use
|
|
49
|
-
5. **Options**: Use appropriate options for generation type
|
|
50
|
-
|
|
51
|
-
### Generation Types
|
|
52
|
-
|
|
53
|
-
**Text-to-Image** (type: 'text_to_image')
|
|
54
|
-
- Generates images from text descriptions
|
|
55
|
-
- Credit cost: 5 per generation
|
|
56
|
-
- Default maxResults: 1
|
|
57
|
-
- Supports style customization
|
|
58
|
-
|
|
59
|
-
**Text-to-Audio** (type: 'text_to_audio')
|
|
60
|
-
- Generates audio from text (text-to-speech)
|
|
61
|
-
- Credit cost: 3 per generation
|
|
62
|
-
- Default duration: 10 seconds
|
|
63
|
-
- Supports voice, language, speed options
|
|
64
|
-
|
|
65
|
-
### Generation Workflow
|
|
66
|
-
|
|
67
|
-
1. Validate prompt text quality and length
|
|
68
|
-
2. Check available credits
|
|
69
|
-
3. Configure generation options
|
|
70
|
-
4. Call generateMedia with request
|
|
71
|
-
5. Monitor isGenerating state
|
|
72
|
-
6. Process generationResult on completion
|
|
73
|
-
7. Handle errors with user feedback
|
|
74
|
-
|
|
75
|
-
### Result Structure
|
|
76
|
-
|
|
77
|
-
GenerationResult includes:
|
|
78
|
-
- success: Boolean indicating success/failure
|
|
79
|
-
- attachments: Array of generated MediaAttachment
|
|
80
|
-
- creditsUsed: Number of credits consumed
|
|
81
|
-
- processingTime: Duration in milliseconds
|
|
82
|
-
- requestId: Unique request identifier
|
|
83
|
-
- error: Error message if failed
|
|
84
|
-
|
|
85
|
-
### Generation Options
|
|
86
|
-
|
|
87
|
-
**Image Options:**
|
|
88
|
-
- maxResults: Number of images to generate (default: 1)
|
|
89
|
-
- style: Image style preset
|
|
90
|
-
|
|
91
|
-
**Audio Options:**
|
|
92
|
-
- voice: Voice type (male/female)
|
|
93
|
-
- language: Language code (e.g., 'tr-TR', 'en-US')
|
|
94
|
-
- speed: Playback speed (default: 1.0)
|
|
95
|
-
|
|
96
|
-
### Integration Requirements
|
|
97
|
-
|
|
98
|
-
- Configure AI API endpoints
|
|
99
|
-
- Implement authentication for AI services
|
|
100
|
-
- Handle rate limiting and quotas
|
|
101
|
-
- Implement retry logic for failed generations
|
|
102
|
-
- Cache generation results when appropriate
|
|
103
|
-
- Monitor credit balance and usage
|
|
104
|
-
|
|
105
|
-
### Error Scenarios
|
|
106
|
-
|
|
107
|
-
- Insufficient credits: Check balance before generation
|
|
108
|
-
- Invalid prompt: Validate text quality and length
|
|
109
|
-
- API timeout: Implement retry with exponential backoff
|
|
110
|
-
- Content policy violations: Filter and validate prompts
|
|
111
|
-
- Service unavailable: Graceful degradation with error message
|
|
112
|
-
|
|
113
|
-
## Dependencies
|
|
114
|
-
|
|
115
|
-
- MediaGenerationService (infrastructure layer)
|
|
116
|
-
- Domain types: MediaGenerationRequest, MediaGenerationResult, MediaAttachment
|
|
117
|
-
- Credit/balance tracking system
|
|
118
|
-
- AI service APIs (text-to-image, text-to-speech)
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# useMediaUpload
|
|
2
|
-
|
|
3
|
-
## Purpose
|
|
4
|
-
React hook for uploading media files to server with progress tracking and compression support.
|
|
5
|
-
|
|
6
|
-
## File Location
|
|
7
|
-
`src/presentation/hooks/useMediaUpload.ts`
|
|
8
|
-
|
|
9
|
-
## Strategy
|
|
10
|
-
- Provide unified media upload interface with progress tracking
|
|
11
|
-
- Support compression options to optimize file sizes before upload
|
|
12
|
-
- Track upload progress with percentage and status updates
|
|
13
|
-
- Handle upload errors gracefully with proper error propagation
|
|
14
|
-
- Maintain loading state to prevent duplicate uploads
|
|
15
|
-
- Support various media types (image, video, audio)
|
|
16
|
-
- Generate automatic thumbnails for media files
|
|
17
|
-
|
|
18
|
-
## Forbidden
|
|
19
|
-
- **DO NOT** start new upload while previous upload is in progress
|
|
20
|
-
- **DO NOT** ignore compression options - always apply before upload
|
|
21
|
-
- **DO NOT** upload files without validation (use useMediaValidation first)
|
|
22
|
-
- **DO NOT** mock upload process in production without integration
|
|
23
|
-
- **DO NOT** modify file during upload (compression happens before)
|
|
24
|
-
- **DO NOT** assume upload will succeed - always handle errors
|
|
25
|
-
- **DO NOT** use hardcoded API endpoints - must be configurable
|
|
26
|
-
- **DO NOT** bypass progress tracking for async uploads
|
|
27
|
-
- **DO NOT** store upload results permanently in hook state
|
|
28
|
-
|
|
29
|
-
## Rules
|
|
30
|
-
1. Always validate files before uploading (use useMediaValidation hook)
|
|
31
|
-
2. Compression quality must be in 0-1 range
|
|
32
|
-
3. Dimensions must be in pixels (maxWidth, maxHeight)
|
|
33
|
-
4. Progress updates must be emitted every 10% or on status change
|
|
34
|
-
5. Upload state must be cleared on error or completion
|
|
35
|
-
6. Return complete MediaAttachment object on success
|
|
36
|
-
7. Generate thumbnail URL automatically for visual media
|
|
37
|
-
8. Calculate duration for audio/video files
|
|
38
|
-
9. Update progress status: uploading -> completed or error
|
|
39
|
-
10. Include unique fileId in progress tracking
|
|
40
|
-
|
|
41
|
-
## AI Agent Guidelines
|
|
42
|
-
|
|
43
|
-
When working with useMediaUpload hook:
|
|
44
|
-
|
|
45
|
-
1. **Pre-upload Validation**: Always use useMediaValidation before calling uploadMedia
|
|
46
|
-
2. **Progress Tracking**: Monitor uploadProgress state for real-time updates
|
|
47
|
-
3. **Compression**: Apply appropriate compression based on use case
|
|
48
|
-
4. **Error Recovery**: Handle upload errors and allow retry logic
|
|
49
|
-
5. **File Size**: Consider file size when choosing compression settings
|
|
50
|
-
|
|
51
|
-
### Upload Workflow
|
|
52
|
-
|
|
53
|
-
1. Validate file with useMediaValidation hook
|
|
54
|
-
2. Select compression options based on file type and size
|
|
55
|
-
3. Call uploadMedia with file and options
|
|
56
|
-
4. Monitor uploadProgress for status updates
|
|
57
|
-
5. Handle completion (success or error)
|
|
58
|
-
6. Process returned MediaAttachment object
|
|
59
|
-
|
|
60
|
-
### Compression Guidelines
|
|
61
|
-
|
|
62
|
-
**High Quality** (quality: 0.9, maxWidth: 4096)
|
|
63
|
-
- Use for professional photos, detailed graphics
|
|
64
|
-
- Larger file size, best quality
|
|
65
|
-
|
|
66
|
-
**Medium Quality** (quality: 0.7, maxWidth: 1920) - RECOMMENDED
|
|
67
|
-
- Balanced quality and size
|
|
68
|
-
- Good for most use cases
|
|
69
|
-
|
|
70
|
-
**Low Quality** (quality: 0.5, maxWidth: 1280)
|
|
71
|
-
- Use for thumbnails, previews
|
|
72
|
-
- Smallest file size, reduced quality
|
|
73
|
-
|
|
74
|
-
### Upload Progress States
|
|
75
|
-
|
|
76
|
-
- **uploading**: Upload in progress, progress 0-99%
|
|
77
|
-
- **completed**: Upload finished successfully, progress 100%
|
|
78
|
-
- **error**: Upload failed, error message available
|
|
79
|
-
|
|
80
|
-
### MediaAttachment Structure
|
|
81
|
-
|
|
82
|
-
Returned object includes:
|
|
83
|
-
- id: Unique identifier
|
|
84
|
-
- url: Uploaded file URL
|
|
85
|
-
- type: MediaType (IMAGE, VIDEO, AUDIO)
|
|
86
|
-
- position: MediaPosition (front, back, both)
|
|
87
|
-
- filename: Original filename
|
|
88
|
-
- fileSize: Size in bytes
|
|
89
|
-
- mimeType: MIME type string
|
|
90
|
-
- duration: Audio/video duration in seconds
|
|
91
|
-
- thumbnailUrl: Thumbnail URL for visual media
|
|
92
|
-
- caption: Optional caption text
|
|
93
|
-
- isDownloaded: Download status flag
|
|
94
|
-
- createdAt: ISO timestamp
|
|
95
|
-
|
|
96
|
-
### Integration Requirements
|
|
97
|
-
|
|
98
|
-
- Configure API endpoint for upload service
|
|
99
|
-
- Implement actual upload logic in MediaUploadService
|
|
100
|
-
- Handle authentication tokens for uploads
|
|
101
|
-
- Support retry logic for failed uploads
|
|
102
|
-
- Implement timeout handling for large files
|
|
103
|
-
|
|
104
|
-
## Dependencies
|
|
105
|
-
|
|
106
|
-
- MediaUploadService (infrastructure layer)
|
|
107
|
-
- Domain types: MediaAttachment, MediaCompressionOptions, MediaUploadProgress
|
|
108
|
-
- useMediaValidation (for pre-upload validation)
|