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

View file

@ -1,9 +1,9 @@
from flask import Blueprint, render_template, redirect, url_for
from flask import Blueprint, render_template
from flask_login import login_required, current_user
from ..models import File, Folder
import os
from ..utils.file_helpers import format_file_size
# Create blueprint with the name expected by __init__.py
# Create blueprint
bp = Blueprint('dashboard', __name__)
@bp.route('/')
@ -18,28 +18,17 @@ def index():
# Get storage usage
storage_used = sum(file.size for file in File.query.filter_by(user_id=current_user.id).all())
# Format size for display
if storage_used < 1024:
storage_used_formatted = f"{storage_used} bytes"
elif storage_used < 1024 * 1024:
storage_used_formatted = f"{storage_used / 1024:.2f} KB"
elif storage_used < 1024 * 1024 * 1024:
storage_used_formatted = f"{storage_used / (1024 * 1024):.2f} MB"
else:
storage_used_formatted = f"{storage_used / (1024 * 1024 * 1024):.2f} GB"
# Get recent files
recent_files = File.query.filter_by(user_id=current_user.id).order_by(File.created_at.desc()).limit(5).all()
# Create stats object that the template is expecting
stats = {
'file_count': file_count,
'folder_count': folder_count,
'storage_used': storage_used_formatted
}
# Add icon_class to each file
for file in recent_files:
file.icon_class = file.get_icon_class()
return render_template('dashboard/index.html',
stats=stats, # Pass as stats object
file_count=file_count,
folder_count=folder_count,
storage_used=format_file_size(storage_used),
recent_files=recent_files)
def get_file_icon(mime_type, filename):