@bernierllc/media-manager
v1.0.6
Published
Media asset management service with upload, processing, optimization, and CDN integration.
Readme
@bernierllc/media-manager
Media asset management service with upload, processing, optimization, and CDN integration.
Overview
The @bernierllc/media-manager package provides a comprehensive service for managing media assets including images, videos, and documents. It handles upload, processing, optimization, metadata extraction, and CDN distribution with caching and event emission.
Features
- File Upload: Multipart file uploads with validation and size limits
- Image Processing: Automatic image optimization and format conversion
- Metadata Extraction: Extract dimensions, format, and EXIF data from images
- Storage Integration: Works with Supabase Storage and other backends via
@bernierllc/file-handler - Caching: Built-in caching for improved performance
- Event Emission: Emit events for upload, delete, and other operations
- Search: Search assets by filename, content type, date range, and user
Installation
npm install @bernierllc/media-managerUsage
import { MediaManager } from '@bernierllc/media-manager';
// Initialize media manager
const mediaManager = new MediaManager({
supabaseUrl: process.env.SUPABASE_URL,
supabaseAnonKey: process.env.SUPABASE_ANON_KEY,
maxFileSize: 10 * 1024 * 1024, // 10MB
allowedTypes: ['image/*', 'video/*'],
enableOptimization: true,
cacheEnabled: true
});
// Initialize (required)
await mediaManager.initialize();
// Upload a file
const uploadResult = await mediaManager.upload({
file: fileBuffer,
filename: 'photo.jpg',
contentType: 'image/jpeg',
userId: 'user-123',
optimize: true
});
if (uploadResult.success) {
console.log('Uploaded:', uploadResult.data?.url);
}
// Get an asset
const assetResult = await mediaManager.getAsset('asset-id');
if (assetResult.success) {
console.log('Asset:', assetResult.data);
}
// Search assets
const searchResult = await mediaManager.searchAssets({
contentType: 'image/jpeg',
uploadedAfter: new Date('2025-01-01'),
limit: 10
});
// Delete an asset
const deleteResult = await mediaManager.delete('asset-id');API
MediaManager
Constructor
new MediaManager(config: MediaConfig)Methods
initialize(): Promise<void>- Initialize the media manager (required before use)upload(request: UploadRequest): Promise<MediaResult<MediaAsset>>- Upload a media filegetAsset(assetId: string): Promise<MediaResult<MediaAsset>>- Get an asset by IDdelete(assetId: string): Promise<MediaResult<void>>- Delete an assetsearchAssets(query: MediaQuery): Promise<MediaResult<MediaAsset[]>>- Search for assetsprocess(assetId: string, operations: ImageOperation[]): Promise<MediaResult<MediaAsset>>- Process an asset (not yet implemented)getEventEmitter(): EventEmitter- Get the event emitter for subscribing to events
Integration Status
- Logger: ✅ Integrated - Uses
@bernierllc/loggerfor all logging operations - Docs-Suite: ✅ Ready - Full TypeDoc API documentation available
- NeverHub: ⚠️ Optional - Can emit media events to NeverHub event bus for distributed observability
Dependencies
@bernierllc/logger- Logging@bernierllc/image-processor- Image processing and optimization@bernierllc/supabase-client- Database operations@bernierllc/cache-manager- Caching@bernierllc/event-emitter- Event emission@bernierllc/file-uploader- File upload handling@bernierllc/file-handler- File storage abstraction
Testing
Run tests with:
npm test
npm run test:coverageTarget coverage: 85%+ (service package standard)
License
Copyright (c) 2025 Bernier LLC
This file is licensed to the client under a limited-use license. The client may use and modify this code only within the scope of the project it was delivered for. Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
