Add folders with password sharing and email invites

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-06 22:30:00 +03:00
parent a375ad330a
commit db2cef41bb
16 changed files with 1016 additions and 4 deletions
+19 -2
View File
@@ -5,6 +5,7 @@ from datetime import datetime, timezone
from flask import (
Blueprint,
current_app,
abort,
flash,
jsonify,
redirect,
@@ -18,7 +19,8 @@ from werkzeug.utils import secure_filename
from app import db
from app.auth_utils import photo_owner_or_admin
from app.models import Photo
from app.folder_utils import can_edit_folder
from app.models import Folder, Photo
bp = Blueprint("main", __name__)
@@ -60,6 +62,13 @@ def upload():
flash("Недопустимый формат. Разрешены: PNG, JPG, GIF, WEBP, BMP", "error")
return redirect(request.referrer or url_for("main.index"))
folder_id = request.form.get("folder_id", type=int)
folder = None
if folder_id:
folder = Folder.query.get_or_404(folder_id)
if not can_edit_folder(folder):
abort(403)
ext = file.filename.rsplit(".", 1)[1].lower()
stored_name = f"{uuid.uuid4().hex}.{ext}"
safe_original = secure_filename(file.filename) or f"photo.{ext}"
@@ -75,12 +84,15 @@ def upload():
file_size=file_size,
mime_type=file.content_type or f"image/{ext}",
user_id=current_user.id,
folder_id=folder.id if folder else None,
created_at=datetime.now(timezone.utc),
)
db.session.add(photo)
db.session.commit()
flash("Фото успешно загружено", "success")
if folder:
return redirect(url_for("folders.view_folder", folder_id=folder.id))
return redirect(url_for("cabinet.index"))
@@ -129,15 +141,20 @@ cabinet_bp = Blueprint("cabinet", __name__, url_prefix="/cabinet")
@cabinet_bp.route("/")
@login_required
def index():
from app.folder_utils import process_pending_invites
process_pending_invites(current_user)
photos = (
Photo.query.filter_by(user_id=current_user.id)
Photo.query.filter_by(user_id=current_user.id, folder_id=None)
.order_by(Photo.created_at.desc())
.all()
)
folders = Folder.query.filter_by(owner_id=current_user.id).order_by(Folder.created_at.desc()).limit(6).all()
total_size = sum(p.file_size for p in photos)
return render_template(
"cabinet/index.html",
photos=photos,
folders=folders,
total_photos=len(photos),
total_size=total_size,
max_upload_mb=current_app.config["MAX_CONTENT_LENGTH"] // (1024 * 1024),