56 lines
No EOL
1.6 KiB
Python
56 lines
No EOL
1.6 KiB
Python
"""
|
|
Flask application factory for Podcastrr.
|
|
"""
|
|
import os
|
|
from flask import Flask
|
|
from flask_migrate import Migrate
|
|
|
|
# Import blueprints
|
|
from app.web.routes.main import main_bp
|
|
from app.web.routes.podcasts import podcasts_bp
|
|
from app.web.routes.settings import settings_bp
|
|
from app.web.routes.api import api_bp
|
|
|
|
# Import database
|
|
from app.models.database import db
|
|
|
|
def create_app(config=None):
|
|
"""
|
|
Create and configure the Flask application.
|
|
|
|
Args:
|
|
config: Configuration object or path to configuration file.
|
|
|
|
Returns:
|
|
Flask application instance.
|
|
"""
|
|
app = Flask(__name__,
|
|
template_folder='../../templates',
|
|
static_folder='../../static')
|
|
|
|
# Load default configuration
|
|
app.config.from_mapping(
|
|
SECRET_KEY=os.environ.get('SECRET_KEY', 'dev'),
|
|
SQLALCHEMY_DATABASE_URI=os.environ.get('DATABASE_URI', 'sqlite:///podcastrr.db'),
|
|
SQLALCHEMY_TRACK_MODIFICATIONS=False,
|
|
DOWNLOAD_PATH=os.environ.get('DOWNLOAD_PATH', os.path.join(os.getcwd(), 'downloads')),
|
|
)
|
|
|
|
# Load additional configuration if provided
|
|
if config:
|
|
app.config.from_mapping(config)
|
|
|
|
# Initialize extensions
|
|
db.init_app(app)
|
|
Migrate(app, db)
|
|
|
|
# Register blueprints
|
|
app.register_blueprint(main_bp)
|
|
app.register_blueprint(podcasts_bp, url_prefix='/podcasts')
|
|
app.register_blueprint(settings_bp, url_prefix='/settings')
|
|
app.register_blueprint(api_bp, url_prefix='/api')
|
|
|
|
# Ensure the download directory exists
|
|
os.makedirs(app.config['DOWNLOAD_PATH'], exist_ok=True)
|
|
|
|
return app |