""" Flask API module for Clean-Tracks. """ from flask import Flask, render_template from flask_cors import CORS from flask_socketio import SocketIO import os # Create Flask app factory def create_app(config=None): """Create and configure the Flask application.""" # Set template and static folder paths template_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'templates')) static_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'static')) app = Flask(__name__, template_folder=template_dir, static_folder=static_dir) # Default configuration app.config.update({ 'SECRET_KEY': 'dev-secret-key-change-in-production', 'MAX_CONTENT_LENGTH': 500 * 1024 * 1024, # 500MB max file size 'UPLOAD_FOLDER': '/tmp/clean-tracks-uploads', 'DATABASE_URL': None, # Will use default SQLite 'CORS_ORIGINS': '*', }) # Override with custom config if config: app.config.update(config) # Initialize CORS CORS(app, origins=app.config['CORS_ORIGINS']) # Initialize SocketIO socketio = SocketIO(app, cors_allowed_origins="*") # Add main route @app.route('/') def index(): """Serve the main application page.""" return render_template('index.html') @app.route('/privacy') def privacy(): """Serve the privacy policy page.""" return render_template('privacy.html') @app.route('/terms') def terms(): """Serve the terms of service page.""" return render_template('terms.html') # Register blueprints from .routes import api_bp from .websocket import register_socketio_handlers app.register_blueprint(api_bp, url_prefix='/api') register_socketio_handlers(socketio) # Store socketio instance on app app.socketio = socketio return app, socketio