@mvp-factory/holy-upload
Version:
File upload processing system extracted from Holy Habit project with security validation and image optimization
159 lines • 4.82 kB
TypeScript
/**
* File Utilities
*
* File operations and utilities for upload system
* Extracted from Holy Habit file handling logic
*/
import * as fs from 'fs';
import { StorageInfo, FileCleanupOptions, CleanupResult } from '../types/Upload';
export declare class FileUtils {
/**
* Generate secure filename
*
* @param originalName - Original filename
* @param userId - User ID (optional)
* @param prefix - Filename prefix (optional)
* @returns Generated filename
*/
static generateSecureFilename(originalName: string, userId?: string, prefix?: string): string;
/**
* Generate UUID-based filename
*
* @param originalName - Original filename
* @param preserveExtension - Whether to preserve original extension
* @returns UUID-based filename
*/
static generateUUIDFilename(originalName: string, preserveExtension?: boolean): string;
/**
* Sanitize filename
*
* @param filename - Original filename
* @returns Sanitized filename
*/
static sanitizeFilename(filename: string): string;
/**
* Ensure directory exists
*
* @param dirPath - Directory path
* @param mode - Directory permissions (default: 0o755)
*/
static ensureDirectory(dirPath: string, mode?: number): Promise<void>;
/**
* Get directory size
*
* @param dirPath - Directory path
* @returns Directory size in bytes
*/
static getDirectorySize(dirPath: string): Promise<number>;
/**
* Count files in directory
*
* @param dirPath - Directory path
* @param recursive - Count files recursively
* @returns Number of files
*/
static countFiles(dirPath: string, recursive?: boolean): Promise<number>;
/**
* Get storage information
*
* @param uploadDir - Upload directory
* @param storageLimit - Storage limit in bytes
* @returns Storage information
*/
static getStorageInfo(uploadDir: string, storageLimit?: number): Promise<StorageInfo>;
/**
* Clean up old files
*
* @param uploadDir - Upload directory
* @param options - Cleanup options
* @returns Cleanup result
*/
static cleanupOldFiles(uploadDir: string, options?: FileCleanupOptions): Promise<CleanupResult>;
/**
* Get files recursively
*
* @param dirPath - Directory path
* @returns Array of file paths
*/
private static getFilesRecursively;
/**
* Clean up empty directories
*
* @param dirPath - Directory path
*/
private static cleanupEmptyDirectories;
/**
* Move file
*
* @param sourcePath - Source file path
* @param destinationPath - Destination file path
*/
static moveFile(sourcePath: string, destinationPath: string): Promise<void>;
/**
* Copy file
*
* @param sourcePath - Source file path
* @param destinationPath - Destination file path
*/
static copyFile(sourcePath: string, destinationPath: string): Promise<void>;
/**
* Delete file safely
*
* @param filePath - File path
* @returns True if deleted successfully
*/
static deleteFile(filePath: string): Promise<boolean>;
/**
* Check if file exists
*
* @param filePath - File path
* @returns True if file exists
*/
static fileExists(filePath: string): Promise<boolean>;
/**
* Get file stats
*
* @param filePath - File path
* @returns File stats or null if not found
*/
static getFileStats(filePath: string): Promise<fs.Stats | null>;
/**
* Format bytes to human readable string
*
* @param bytes - Number of bytes
* @param decimals - Number of decimal places
* @returns Formatted string
*/
static formatBytes(bytes: number, decimals?: number): string;
/**
* Get MIME type from file extension
*
* @param filename - Filename
* @returns MIME type
*/
static getMimeTypeFromExtension(filename: string): string;
/**
* Generate hash for file
*
* @param filePath - File path
* @param algorithm - Hash algorithm (default: sha256)
* @returns File hash
*/
static generateFileHash(filePath: string, algorithm?: string): Promise<string>;
/**
* Get duplicate files
*
* @param dirPath - Directory path
* @returns Map of file hashes to file paths
*/
static findDuplicateFiles(dirPath: string): Promise<Map<string, string[]>>;
/**
* Create file backup
*
* @param filePath - Original file path
* @param backupDir - Backup directory
* @returns Backup file path
*/
static createBackup(filePath: string, backupDir: string): Promise<string>;
}
//# sourceMappingURL=FileUtils.d.ts.map