Files
baiyue-logistics-chat/logistics_chat/__init__.py
T
ouyangxq 805675f8db 重构物流客服模块并完善会话接待工作台
- 拆分应用工厂、业务服务与路由,保留原有 HTTP/SSE 和存储入口
- 分离页面资源,重排客服工作台并完善响应式导航、草稿和附件交互
- 整理维护脚本、请求示例和贡献指南,移除启动脚本中的密钥配置
- 上传文件改为仅本地保留,补充隔离的后端与前端回归验证

验证:46 项 Python 测试通过,含 14 个已有子测试;12 个 Node 前端场景通过。
2026-10-29 10:59:29 +08:00

46 lines
1.8 KiB
Python

"""Application factory; package imports do not initialize storage or networking."""
def create_app(config=None):
from collections import defaultdict
import logging
from pathlib import Path
from flask import Flask
from .config import ROOT_DIR, default_config
from . import db, file_service, hooks
from .routes import register_routes
app = Flask(__name__, template_folder=str(ROOT_DIR/'templates'),
static_folder=str(ROOT_DIR/'static'))
app.config.update(default_config())
if config:
app.config.update(config)
app.extensions['human_typing'] = {}
app.extensions['rate_hits'] = defaultdict(list)
app.before_request(hooks.rate_limit)
app.after_request(hooks.no_cache_html)
app.teardown_appcontext(db.close_connections)
register_routes(app)
if app.config['INITIALIZE_RUNTIME']:
if not app.testing:
from flask.logging import default_handler
log_directory = Path(app.config['LOG_DIR'])
log_directory.mkdir(parents=True, exist_ok=True)
log_path = str((log_directory/'app.log').resolve())
app.logger = logging.getLogger('logistics_chat.' + log_path)
app.logger.setLevel(logging.INFO)
if default_handler not in app.logger.handlers:
app.logger.addHandler(default_handler)
if not any(getattr(handler, 'baseFilename', None) == log_path for handler in app.logger.handlers):
handler = logging.FileHandler(log_path, encoding='utf-8')
handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)s] %(message)s'))
app.logger.addHandler(handler)
with app.app_context():
db.init_db()
db.backup_db()
file_service.cleanup_uploads()
return app