more commits..

This commit is contained in:
pika 2025-03-23 03:53:45 +01:00
parent 6dda02141e
commit 7823be6481
20 changed files with 1835 additions and 631 deletions

100
app/utils/file_helpers.py Normal file
View file

@ -0,0 +1,100 @@
def format_file_size(size_bytes):
"""Format file size in bytes to human-readable format"""
if size_bytes < 1024:
return f"{size_bytes} bytes"
elif size_bytes < 1024 * 1024:
return f"{size_bytes / 1024:.2f} KB"
elif size_bytes < 1024 * 1024 * 1024:
return f"{size_bytes / (1024 * 1024):.2f} MB"
else:
return f"{size_bytes / (1024 * 1024 * 1024):.2f} GB"
def get_file_icon(mime_type, filename):
"""Get Font Awesome icon class based on file type"""
# Extract extension from filename
extension = filename.split('.')[-1].lower() if '.' in filename else ''
# Define icon mapping
icon_map = {
# Documents
'pdf': 'fa-file-pdf',
'doc': 'fa-file-word',
'docx': 'fa-file-word',
'txt': 'fa-file-alt',
'rtf': 'fa-file-alt',
'odt': 'fa-file-alt',
# Spreadsheets
'xls': 'fa-file-excel',
'xlsx': 'fa-file-excel',
'csv': 'fa-file-csv',
# Presentations
'ppt': 'fa-file-powerpoint',
'pptx': 'fa-file-powerpoint',
# Images
'jpg': 'fa-file-image',
'jpeg': 'fa-file-image',
'png': 'fa-file-image',
'gif': 'fa-file-image',
'svg': 'fa-file-image',
'webp': 'fa-file-image',
# Audio
'mp3': 'fa-file-audio',
'wav': 'fa-file-audio',
'ogg': 'fa-file-audio',
# Video
'mp4': 'fa-file-video',
'avi': 'fa-file-video',
'mov': 'fa-file-video',
'wmv': 'fa-file-video',
# Archives
'zip': 'fa-file-archive',
'rar': 'fa-file-archive',
'7z': 'fa-file-archive',
'tar': 'fa-file-archive',
'gz': 'fa-file-archive',
# Code
'html': 'fa-file-code',
'css': 'fa-file-code',
'js': 'fa-file-code',
'py': 'fa-file-code',
'java': 'fa-file-code',
'php': 'fa-file-code',
'c': 'fa-file-code',
'cpp': 'fa-file-code',
'h': 'fa-file-code',
}
# Check if we have an icon for this extension
if extension in icon_map:
return icon_map[extension]
# If not, try to determine from mime type
if mime_type:
if mime_type.startswith('image/'):
return 'fa-file-image'
elif mime_type.startswith('audio/'):
return 'fa-file-audio'
elif mime_type.startswith('video/'):
return 'fa-file-video'
elif mime_type.startswith('text/'):
return 'fa-file-alt'
elif 'pdf' in mime_type:
return 'fa-file-pdf'
elif 'msword' in mime_type or 'document' in mime_type:
return 'fa-file-word'
elif 'excel' in mime_type or 'spreadsheet' in mime_type:
return 'fa-file-excel'
elif 'powerpoint' in mime_type or 'presentation' in mime_type:
return 'fa-file-powerpoint'
elif 'zip' in mime_type or 'compressed' in mime_type or 'archive' in mime_type:
return 'fa-file-archive'
# Default icon
return 'fa-file'