2026-06-30 21:00:20 +08:00
|
|
|
from flask import Flask, jsonify
|
|
|
|
|
from flask_cors import CORS
|
2026-07-02 18:51:23 +08:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
2026-06-30 21:00:20 +08:00
|
|
|
|
|
|
|
|
def create_app():
|
|
|
|
|
app = Flask(__name__)
|
2026-07-02 18:51:23 +08:00
|
|
|
|
|
|
|
|
# Session 配置
|
|
|
|
|
app.secret_key = os.getenv('FLASK_SECRET_KEY', 'military-tech-voice-secret-2026')
|
|
|
|
|
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
|
|
|
|
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
|
|
|
|
|
app.config['PERMANENT_SESSION_LIFETIME'] = 86400 * 7 # 7天免重登
|
|
|
|
|
|
|
|
|
|
CORS(app, resources={r"/api/*": {"origins": "*"}}, supports_credentials=True)
|
|
|
|
|
|
|
|
|
|
# 初始化数据库
|
|
|
|
|
from app.db import init_db
|
|
|
|
|
init_db()
|
|
|
|
|
|
|
|
|
|
# 注册蓝图
|
2026-06-30 21:00:20 +08:00
|
|
|
from app.routes.tts_synthesize import bp as synthesize_bp
|
2026-07-02 18:51:23 +08:00
|
|
|
from app.routes.auth import bp as auth_bp
|
|
|
|
|
from app.routes.admin import bp as admin_bp
|
2026-06-30 21:00:20 +08:00
|
|
|
app.register_blueprint(synthesize_bp)
|
2026-07-02 18:51:23 +08:00
|
|
|
app.register_blueprint(auth_bp)
|
|
|
|
|
app.register_blueprint(admin_bp)
|
|
|
|
|
|
2026-06-30 21:00:20 +08:00
|
|
|
@app.route('/api/health')
|
2026-07-02 18:51:23 +08:00
|
|
|
def health():
|
|
|
|
|
return jsonify({'status': 'ok', 'service': '军事科技AI配音系统'})
|
|
|
|
|
|
2026-06-30 21:00:20 +08:00
|
|
|
return app
|
|
|
|
|
|
2026-07-02 18:51:23 +08:00
|
|
|
|
2026-06-30 21:00:20 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
create_app().run(host='0.0.0.0', port=5000, debug=True)
|