""" Utility Functions Module Common helper functions used across the application. """ from pathlib import Path from datetime import datetime def format_size(size: int) -> str: """Format bytes to human readable string""" for unit in ['B', 'KB', 'MB', 'GB', 'TB']: if size < 1024: return f"{size:.1f} {unit}" size /= 1024 return f"{size:.1f} PB" def get_file_icon(name: str, is_dir: bool = False) -> str: """Get emoji icon for file type""" if is_dir: return "📁" ext = Path(name).suffix.lower() icons = { '.txt': '📄', '.md': '📝', '.pdf': '📕', '.doc': '📘', '.csv': '📊', '.py': '🐍', '.js': '📜', '.json': '📋', '.html': '🌐', '.css': '🎨', '.jpg': '🖼️', '.jpeg': '🖼️', '.png': '🖼️', '.gif': '🖼️', '.svg': '🖼️', '.mp3': '🎵', '.wav': '🎵', '.mp4': '🎬', '.avi': '🎬', '.zip': '📦', '.tar': '📦', '.gz': '📦', '.pt': '🧠', '.pth': '🧠', '.safetensors': '🧠', '.ckpt': '🧠', '.bin': '🧠', '.env': '🔐', '.log': '📜', '.sh': '🖥️', } return icons.get(ext, '📄') def get_mime_type(name: str) -> str: """Get mime type category for file""" ext = Path(name).suffix.lower() if ext in ['.jpg', '.jpeg', '.png', '.gif', '.svg', '.webp']: return 'image' if ext in ['.txt', '.md', '.py', '.js', '.json', '.html', '.css', '.yaml', '.yml', '.sh', '.log', '.csv']: return 'text' return 'binary' def format_timestamp(ts: float) -> str: """Format unix timestamp to string""" return datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M")