Implement organized media folder structure for community posts

- Add media_folder field to Post model for organized file storage
- Create MediaConfig class for centralized media management settings
- Update community routes to use post-specific media folders
- Add thumbnail generation for uploaded images
- Implement structured folder layout: app/static/media/posts/{post_folder}/
- Add utility functions for image and GPX file handling
- Create media management script for migration and maintenance
- Add proper file validation and MIME type checking
- Include routes for serving images, thumbnails, and GPX files
- Maintain backward compatibility with existing uploads
- Add comprehensive documentation and migration tools

Each post now gets its own media folder with subfolders for:
- images/ (with thumbnails/ subfolder)
- gpx/

Post content remains in database for optimal query performance while
media files are organized in dedicated folders for better management.
This commit is contained in:
ske087
2025-07-23 18:03:03 +03:00
parent 6a0548b880
commit 540eb17e89
8 changed files with 808 additions and 26 deletions

View File

@@ -8,10 +8,19 @@ class Config:
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or 'sqlite:///moto_adventure.db'
SQLALCHEMY_TRACK_MODIFICATIONS = False
# File Upload Configuration
# Media Configuration - Updated for new media system
MEDIA_FOLDER = os.environ.get('MEDIA_FOLDER') or 'app/static/media/posts'
MAX_CONTENT_LENGTH = int(os.environ.get('MAX_CONTENT_LENGTH') or 16 * 1024 * 1024) # 16MB
# Image Processing
IMAGE_MAX_WIDTH = int(os.environ.get('IMAGE_MAX_WIDTH') or 1920)
IMAGE_MAX_HEIGHT = int(os.environ.get('IMAGE_MAX_HEIGHT') or 1080)
IMAGE_QUALITY = int(os.environ.get('IMAGE_QUALITY') or 85)
THUMBNAIL_SIZE = int(os.environ.get('THUMBNAIL_SIZE') or 300)
# Legacy - keeping for backward compatibility
UPLOAD_FOLDER = os.environ.get('UPLOAD_FOLDER') or 'app/static/uploads'
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16MB max file size
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'gpx'}
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'webp', 'gpx'}
# Email Configuration
MAIL_SERVER = os.environ.get('MAIL_SERVER') or 'smtp.gmail.com'