/** * Storage Service * Unified service for secure file operations, user uploads, and internal data storage * Provides path sanitization, validation, and consistent file handling */ declare const BASE_DIRS: { readonly attachments: string; readonly data: string; readonly templates: string; readonly uploads: string; readonly logs: string; readonly config: string; }; export type BaseDirectory = keyof typeof BASE_DIRS; export interface FileInfo { name: string; size: number; path: string; mimeType?: string; hash?: string; created?: Date; modified?: Date; } export interface SaveOptions { overwrite?: boolean; createBackup?: boolean; validateContent?: boolean; } export interface ReadOptions { encoding?: BufferEncoding; maxSize?: number; } export interface FileUploadOptions { maxSize?: number; allowedTypes?: string[]; destination?: string; generateUniqueName?: boolean; preserveExtension?: boolean; } export interface UploadedFile { originalName: string; filename: string; path: string; size: number; mimetype?: string; extension: string; hash?: string; } export declare class StorageService { private initialized; private readonly maxFileSize; initialize(): Promise; /** * Sanitize a filename to prevent path traversal attacks */ sanitizeFilename(filename: string): string; /** * Validate that a path is within the allowed base directory */ isPathSafe(filePath: string, baseDir: string): boolean; /** * Get the full safe path for a file */ getSafePath(filename: string, category?: BaseDirectory): string; /** * Save a file securely */ saveFile(content: string | Buffer, filename: string, category?: BaseDirectory, options?: SaveOptions): Promise; /** * Read a file securely */ readFile(filename: string, category?: BaseDirectory, options?: ReadOptions): Promise; /** * Delete a file securely */ deleteFile(filename: string, category?: BaseDirectory): Promise; /** * List files in a category */ listFiles(category?: BaseDirectory, pattern?: RegExp): Promise; /** * Get file info */ getFileInfo(filename: string, category?: BaseDirectory): Promise; /** * Move file between categories */ moveFile(filename: string, fromCategory: BaseDirectory, toCategory: BaseDirectory): Promise; /** * Get available base directories */ getBaseDirectories(): Record; /** * Save a user upload with security checks * @param file - File buffer or stream * @param originalName - Original filename from user * @param options - Upload options * @returns Information about the uploaded file */ saveUserUpload(file: Buffer | NodeJS.ReadableStream, originalName: string, options?: FileUploadOptions): Promise; /** * Clean temporary files older than a given age. Falls back to ./temp to * preserve the previous middleware behaviour. */ cleanTempFiles(maxAgeMs?: number, tempDir?: string): Promise; /** * Save internal application data * @param data - Data to save * @param filename - Filename for the data * @param category - Category/directory for the data * @param options - Save options */ saveInternalData(data: string | Buffer | object, filename: string, category?: BaseDirectory, options?: SaveOptions): Promise; } export declare function getStorageService(): StorageService; export declare function getSecureFileHandler(): StorageService; export { StorageService as SecureFileHandler }; export default StorageService; //# sourceMappingURL=storageService.d.ts.map