""" Flask 应用入口文件 多客户端 qBittorrent 集中管理平台后端 """ from flask import Flask, jsonify from flask_cors import CORS from config import Config from api.clients import clients_bp from api.torrents import torrents_bp def create_app(): """创建 Flask 应用实例""" app = Flask(__name__) # 加载配置 app.config.from_object(Config) # 配置 CORS CORS(app, origins=Config.CORS_ORIGINS) # 注册蓝图 app.register_blueprint(clients_bp) app.register_blueprint(torrents_bp) # 健康检查端点 @app.route('/api/health') def health_check(): return jsonify({ 'status': 'healthy', 'message': 'qBittorrent 管理平台后端运行正常' }) # 根路径 @app.route('/') def index(): return jsonify({ 'name': 'qBittorrent 管理平台 API', 'version': '1.0.0', 'description': '多客户端 qBittorrent 集中管理平台后端 API' }) # 全局错误处理 @app.errorhandler(404) def not_found(error): return jsonify({ 'success': False, 'error': '接口不存在' }), 404 @app.errorhandler(500) def internal_error(error): return jsonify({ 'success': False, 'error': '服务器内部错误' }), 500 return app if __name__ == '__main__': app = create_app() app.run( debug=Config.DEBUG, host=Config.APP_HOST, port=Config.APP_PORT )