UNPKG

@mvp-factory/holy-upload

Version:

File upload processing system extracted from Holy Habit project with security validation and image optimization

184 lines 5.53 kB
/** * Upload Types * * Type definitions for file upload system * Extracted from Holy Habit upload system */ export interface UploadConfig { /** Upload directory path */ uploadDir: string; /** Maximum file size in bytes (default: 10MB) */ maxSize?: number; /** Maximum image width (default: 1920) */ maxWidth?: number; /** Maximum image height (default: 1080) */ maxHeight?: number; /** Allowed MIME types */ allowedMimeTypes?: string[]; /** Allowed file extensions */ allowedExtensions?: string[]; /** Enable image optimization (default: true) */ enableOptimization?: boolean; /** JPEG quality for optimization (default: 85) */ jpegQuality?: number; /** PNG compression level (default: 8) */ pngCompression?: number; /** WebP quality for optimization (default: 85) */ webpQuality?: number; } export interface UploadResult { success: boolean; file?: UploadedFile; url?: string; error?: string; } export interface MultipleUploadResult { success: boolean; files: UploadedFile[]; errors: string[]; successCount: number; errorCount: number; } export interface UploadedFile { /** Generated filename */ filename: string; /** Original filename */ originalName: string; /** MIME type */ mimeType: string; /** File size in bytes */ size: number; /** File extension */ extension: string; /** Upload timestamp */ uploadedAt: Date; /** User ID who uploaded the file */ userId?: string; /** Full file path */ path: string; /** Public URL */ url: string; } export interface ImageOptimizationOptions { /** Maximum width */ maxWidth?: number; /** Maximum height */ maxHeight?: number; /** JPEG quality (1-100) */ jpegQuality?: number; /** PNG compression level (0-9) */ pngCompression?: number; /** WebP quality (1-100) */ webpQuality?: number; /** Maintain aspect ratio */ maintainAspectRatio?: boolean; } export interface ValidationOptions { /** Maximum file size in bytes */ maxSize?: number; /** Allowed MIME types */ allowedMimeTypes?: string[]; /** Allowed file extensions */ allowedExtensions?: string[]; /** Check for malicious files */ checkMalicious?: boolean; } export interface ValidationResult { isValid: boolean; mimeType?: string; extension?: string; size?: number; errors: string[]; } export interface StorageInfo { /** Total storage used in bytes */ totalUsed: number; /** Total storage used (formatted) */ totalUsedFormatted: string; /** Number of files */ fileCount: number; /** Storage limit in bytes */ storageLimit: number; /** Usage percentage */ usagePercentage: number; } export interface FileCleanupOptions { /** User ID to clean up files for */ userId?: string; /** Delete files older than X days */ olderThanDays?: number; /** Only delete unused files */ unusedOnly?: boolean; /** Dry run - don't actually delete */ dryRun?: boolean; } export interface CleanupResult { success: boolean; deletedCount: number; freedSpace: number; freedSpaceFormatted: string; errors: string[]; } export interface UploadMiddlewareOptions { /** Field name for single file upload */ fieldName?: string; /** Maximum number of files for multiple upload */ maxFiles?: number; /** Upload configuration */ config?: Partial<UploadConfig>; /** Custom validation function */ customValidator?: (file: Express.Multer.File) => Promise<ValidationResult>; } export interface SecureUploadOptions { /** Enable virus scanning */ enableVirusScanning?: boolean; /** Quarantine directory for suspicious files */ quarantineDir?: string; /** Maximum files per user per hour */ rateLimitPerHour?: number; /** Whitelist of safe file signatures */ allowedSignatures?: string[]; } export interface UploadSession { /** Session ID */ sessionId: string; /** User ID */ userId: string; /** Upload started at */ startedAt: Date; /** Files uploaded in this session */ files: UploadedFile[]; /** Session metadata */ metadata?: Record<string, any>; } export declare class UploadError extends Error { code: string; statusCode: number; constructor(message: string, code: string, statusCode?: number); } export declare class ValidationError extends UploadError { constructor(message: string); } export declare class FileSizeError extends UploadError { constructor(message: string); } export declare class FileTypeError extends UploadError { constructor(message: string); } export declare class StorageError extends UploadError { constructor(message: string); } export declare const DEFAULT_CONFIG: Required<UploadConfig>; export declare const UPLOAD_ERRORS: { readonly NO_FILE: "No file uploaded"; readonly FILE_TOO_LARGE: "File size exceeds limit"; readonly INVALID_TYPE: "Invalid file type"; readonly INVALID_EXTENSION: "Invalid file extension"; readonly UPLOAD_FAILED: "Failed to upload file"; readonly OPTIMIZATION_FAILED: "Failed to optimize image"; readonly DIRECTORY_ERROR: "Failed to create upload directory"; readonly PERMISSION_DENIED: "Permission denied"; readonly MALICIOUS_FILE: "File appears to be malicious"; readonly RATE_LIMITED: "Upload rate limit exceeded"; }; //# sourceMappingURL=Upload.d.ts.map