@bts-soft/core 2.3.3 → 2.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +28 -23
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -410,45 +410,50 @@ await notificationService.send(ChannelType.MESSENGER, {
410
410
 
411
411
  ## Deep Dive: `@bts-soft/upload`
412
412
 
413
- The upload module is a production-hardened media orchestration service. It is designed to handle the complexities of multi-part streams, file validation, and cloud storage management.
413
+ The upload module is a production-hardened media orchestration service designed to handle the complexities of multi-part streams, file validation, and cross-provider storage management.
414
414
 
415
- ### Architecture Patterns
415
+ ### Multi-Provider Architecture
416
416
 
417
- The service is built on three pillars of software engineering:
417
+ The service leverages the **Strategy Pattern** to support multiple storage backends without changing the application logic:
418
418
 
419
- 1. **Strategy Pattern**:
420
- The `IUploadStrategy` interface allows you to define how files are stored. The default implementation is `CloudinaryUploadStrategy`, but you can easily plug in Amazon S3 or Google Cloud Storage.
421
-
422
- 2. **Command Pattern**:
423
- Each upload type (Image, Video, Audio, Raw File) is encapsulated in a command. This allows the system to apply specific optimizations (like chunked video upload) without cluttering the main service.
419
+ 1. **Cloudinary Strategy**: Default for production, providing on-the-fly optimization, transcoding, and CDN delivery.
420
+ 2. **Local Disk Strategy**: Ideal for development or high-security environments where files must remain on the internal network.
424
421
 
425
- 3. **Observer Pattern**:
426
- Successful and failed uploads trigger events that `IUploadObserver` instances can listen to. This is used for global logging, analytics, and cleanup tasks.
422
+ Switching providers is handled via the `UPLOAD_PROVIDER` environment variable.
427
423
 
428
- ---
424
+ ### Design Patterns
429
425
 
430
- ### Media Type Specifications
426
+ The module is built on three pillars of software engineering:
431
427
 
432
- | Media Type | File Extensions | Size Limit | Processing Logic |
433
- | :--- | :--- | :--- | :--- |
434
- | **Images** | `jpg`, `png`, `webp`, `gif` | 5 MB | Format optimization, fetch_format: auto |
435
- | **Videos** | `mp4`, `webm`, `avi`, `mov` | 100 MB | Chunked upload (6MB chunks), Duration extraction |
436
- | **Audio** | `mp3`, `wav`, `ogg`, `m4a` | 50 MB | Treated as a "video" resource for waveform generation |
437
- | **Raw Files** | `pdf`, `doc`, `zip`, `txt` | 10 MB | Stored as 'raw' resources with original headers |
428
+ - **Strategy Pattern**: The `IUploadStrategy` and `IDeleteStrategy` interfaces decouple the service from the underlying storage technology.
429
+ - **Command Pattern**: Each operation (Upload, Delete) is encapsulated in a command object, ensuring consistent execution and error handling.
430
+ - **Observer Pattern**: Triggers events on success or failure, enabling centralized logging and auditing via `IUploadObserver`.
438
431
 
439
- ---
432
+ ### Media Specifications & Validation
440
433
 
441
- ### Provider Integration (Cloudinary)
434
+ The system enforces strict validation for file extensions and sizes. Limits can be customized via environment variables.
442
435
 
443
- To initialize the upload system, ensure your environment is configured:
436
+ | Media Type | File Extensions | Default Limit | Storage Logic |
437
+ | :--- | :--- | :--- | :--- |
438
+ | **Images** | `jpg`, `png`, `webp`, `gif` | 5 MB | Auto-optimization and non-destructive resizing. |
439
+ | **Videos** | `mp4`, `webm`, `avi`, `mov` | 100 MB | Chunked upload support with duration extraction. |
440
+ | **Audio** | `mp3`, `wav`, `ogg`, `m4a` | 50 MB | Optimized for playback and metadata extraction. |
441
+ | **Raw Files** | `pdf`, `doc`, `zip`, `txt` | 10 MB | Stored as 'raw' binary with original headers. |
442
+
443
+ ### Configuration Reference
444
444
 
445
445
  ```env
446
+ # Provider Selection
447
+ UPLOAD_PROVIDER=cloudinary # or 'local'
448
+
449
+ # Cloudinary Credentials (if provider=cloudinary)
446
450
  CLOUDINARY_CLOUD_NAME=your_name
447
451
  CLOUDINARY_API_KEY=your_key
448
452
  CLOUDINARY_API_SECRET=your_secret
449
- ```
450
453
 
451
- The system automatically handles the creation of a Cloudinary client instance and injects it into the default strategies.
454
+ # Local Settings (if provider=local)
455
+ UPLOAD_LOCAL_PATH=./uploads
456
+ ```
452
457
 
453
458
  ---
454
459
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bts-soft/core",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "author": "Omar Sabry",
5
5
  "description": "All bts-soft packages - meta-package bundling common, cache, validation, upload, and notifications for NestJS.",
6
6
  "main": "dist/index.js",
@@ -17,8 +17,8 @@
17
17
  "@bts-soft/notifications": "1.4.5",
18
18
  "@bts-soft/common": "1.2.8",
19
19
  "@bts-soft/cache": "1.0.9",
20
- "@bts-soft/validation": "1.1.1",
21
- "@bts-soft/upload": "1.4.0"
20
+ "@bts-soft/validation": "1.1.3",
21
+ "@bts-soft/upload": "1.4.1"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@nestjs/common": ">=11.0.0",