from flask import Flask from flask_cors import CORS from .extensions import db, migrate from .config import DevelopmentConfig, ProductionConfig, TestingConfig from .blueprints import torrent_bp, book_bp, music_bp, file_bp, video_bp, image_bp def create_app(config_name="development"): app = Flask(__name__) CORS(app) app.config.from_object(DevelopmentConfig) match config_name: case 'production': app.config.from_object(ProductionConfig) case 'testing': app.config.from_object(TestingConfig) case _: app.config.from_object(DevelopmentConfig) db.init_app(app) migrate.init_app(app, db) app.register_blueprint(torrent_bp.bp, url_prefix='/api/torrent') app.register_blueprint(book_bp.bp, url_prefix='/api/book') app.register_blueprint(music_bp.bp, url_prefix='/api/music') app.register_blueprint(file_bp.bp, url_prefix='/api/file') app.register_blueprint(video_bp.bp, url_prefix='/api/video') app.register_blueprint(image_bp.bp, url_prefix='/api/image') return app